[nimsuggest] fix def call on identifier 2 times on the line (#20228)
- apparently TLineInfo's implementation of `==` ignores the column. After I fixed the code to use exact TLineInfo comparison I fixed several other issues hidden by that issue. - Replaced `tuple[sym, info]` with `SymInfoPair`
This commit is contained in:
parent
04e4a5ec0e
commit
d4c0d35b32
5 changed files with 76 additions and 48 deletions
|
|
@ -711,17 +711,16 @@ proc recompilePartially(graph: ModuleGraph, projectFileIdx = InvalidFileIdx) =
|
|||
except Exception as e:
|
||||
myLog fmt "Failed clean recompilation:\n {e.msg} \n\n {e.getStackTrace()}"
|
||||
|
||||
proc fileSymbols(graph: ModuleGraph, fileIdx: FileIndex): seq[tuple[sym: PSym, info: TLineInfo]] =
|
||||
result = graph.suggestSymbols.getOrDefault(fileIdx, @[]).deduplicate
|
||||
|
||||
proc findSymData(graph: ModuleGraph, file: AbsoluteFile; line, col: int):
|
||||
tuple[sym: PSym, info: TLineInfo] =
|
||||
ref SymInfoPair =
|
||||
let
|
||||
fileIdx = fileInfoIdx(graph.config, file)
|
||||
trackPos = newLineInfo(fileIdx, line, col)
|
||||
for (sym, info) in graph.fileSymbols(fileIdx):
|
||||
if isTracked(info, trackPos, sym.name.s.len):
|
||||
return (sym, info)
|
||||
for s in graph.fileSymbols(fileIdx):
|
||||
if isTracked(s.info, trackPos, s.sym.name.s.len):
|
||||
new(result)
|
||||
result[] = s
|
||||
break
|
||||
|
||||
proc markDirtyIfNeeded(graph: ModuleGraph, file: string, originalFileIdx: FileIndex) =
|
||||
let sha = $sha1.secureHashFile(file)
|
||||
|
|
@ -735,7 +734,7 @@ proc markDirtyIfNeeded(graph: ModuleGraph, file: string, originalFileIdx: FileIn
|
|||
proc suggestResult(graph: ModuleGraph, sym: PSym, info: TLineInfo, defaultSection = ideNone) =
|
||||
let section = if defaultSection != ideNone:
|
||||
defaultSection
|
||||
elif sym.info == info:
|
||||
elif sym.info.exactEquals(info):
|
||||
ideDef
|
||||
else:
|
||||
ideUse
|
||||
|
|
@ -800,31 +799,31 @@ proc executeNoHooksV3(cmd: IdeCmd, file: AbsoluteFile, dirtyfile: AbsoluteFile,
|
|||
|
||||
case cmd
|
||||
of ideDef:
|
||||
let (sym, info) = graph.findSymData(file, line, col)
|
||||
if sym != nil:
|
||||
graph.suggestResult(sym, sym.info)
|
||||
let s = graph.findSymData(file, line, col)
|
||||
if not s.isNil:
|
||||
graph.suggestResult(s.sym, s.sym.info)
|
||||
of ideType:
|
||||
let (sym, _) = graph.findSymData(file, line, col)
|
||||
if sym != nil:
|
||||
let typeSym = sym.typ.sym
|
||||
let s = graph.findSymData(file, line, col)
|
||||
if not s.isNil:
|
||||
let typeSym = s.sym.typ.sym
|
||||
if typeSym != nil:
|
||||
graph.suggestResult(typeSym, typeSym.info, ideType)
|
||||
elif sym.typ.len != 0:
|
||||
let genericType = sym.typ[0].sym
|
||||
elif s.sym.typ.len != 0:
|
||||
let genericType = s.sym.typ[0].sym
|
||||
graph.suggestResult(genericType, genericType.info, ideType)
|
||||
of ideUse, ideDus:
|
||||
let symbol = graph.findSymData(file, line, col).sym
|
||||
if symbol != nil:
|
||||
for (sym, info) in graph.suggestSymbolsIter:
|
||||
if sym == symbol:
|
||||
graph.suggestResult(sym, info)
|
||||
let symbol = graph.findSymData(file, line, col)
|
||||
if not symbol.isNil:
|
||||
for s in graph.suggestSymbolsIter:
|
||||
if s.sym == symbol.sym:
|
||||
graph.suggestResult(s.sym, s.info)
|
||||
of ideHighlight:
|
||||
let sym = graph.findSymData(file, line, col).sym
|
||||
if sym != nil:
|
||||
let usages = graph.fileSymbols(fileIndex).filterIt(it.sym == sym)
|
||||
let sym = graph.findSymData(file, line, col)
|
||||
if not sym.isNil:
|
||||
let usages = graph.fileSymbols(fileIndex).filterIt(it.sym == sym.sym)
|
||||
myLog fmt "Found {usages.len} usages in {file.string}"
|
||||
for (sym, info) in usages:
|
||||
graph.suggestResult(sym, info)
|
||||
for s in usages:
|
||||
graph.suggestResult(s.sym, s.info)
|
||||
of ideRecompile:
|
||||
graph.recompileFullProject()
|
||||
of ideChanged:
|
||||
|
|
@ -837,14 +836,12 @@ proc executeNoHooksV3(cmd: IdeCmd, file: AbsoluteFile, dirtyfile: AbsoluteFile,
|
|||
let
|
||||
module = graph.getModule fileIndex
|
||||
symbols = graph.fileSymbols(fileIndex)
|
||||
.filterIt(it.sym.info == it.info and
|
||||
.filterIt(it.sym.info.exactEquals(it.info) and
|
||||
(it.sym.owner == module or
|
||||
it.sym.kind in searchableSymKinds))
|
||||
for (sym, _) in symbols:
|
||||
suggestResult(
|
||||
conf,
|
||||
symToSuggest(graph, sym, false,
|
||||
ideOutline, sym.info, 100, PrefixMatch.None, false, 0))
|
||||
|
||||
for s in symbols:
|
||||
graph.suggestResult(s.sym, s.info, ideOutline)
|
||||
of ideChk:
|
||||
myLog fmt "Reporting errors for {graph.suggestErrors.len} file(s)"
|
||||
for sug in graph.suggestErrorsIter:
|
||||
|
|
@ -856,13 +853,12 @@ proc executeNoHooksV3(cmd: IdeCmd, file: AbsoluteFile, dirtyfile: AbsoluteFile,
|
|||
suggestResult(graph.config, error)
|
||||
of ideGlobalSymbols:
|
||||
var counter = 0
|
||||
for (sym, info) in graph.suggestSymbolsIter:
|
||||
if sfGlobal in sym.flags or sym.kind in searchableSymKinds:
|
||||
if contains(sym.name.s, file.string):
|
||||
for s in graph.suggestSymbolsIter:
|
||||
if (sfGlobal in s.sym.flags or s.sym.kind in searchableSymKinds) and
|
||||
s.sym.info == s.info:
|
||||
if contains(s.sym.name.s, file.string):
|
||||
inc counter
|
||||
suggestResult(conf,
|
||||
symToSuggest(graph, sym, isLocal=false,
|
||||
ideDef, info, 100, PrefixMatch.None, false, 0))
|
||||
graph.suggestResult(s.sym, s.info)
|
||||
# stop after first 100 results
|
||||
if counter > 100:
|
||||
break
|
||||
|
|
|
|||
|
|
@ -7,6 +7,8 @@ type
|
|||
proc test(f: Foo) =
|
||||
echo f.ba#[!]#r
|
||||
|
||||
#[!]#
|
||||
|
||||
discard """
|
||||
$nimsuggest --v3 --tester $file
|
||||
>use $1
|
||||
|
|
@ -22,4 +24,8 @@ outline skProc tv3.test proc (f: Foo){.gcsafe, locks: 0.} $file 7 5 "" 100
|
|||
sug skField bar string $file 5 4 "" 100 Prefix
|
||||
>globalSymbols test
|
||||
def skProc tv3.test proc (f: Foo){.gcsafe, locks: 0.} $file 7 5 "" 100
|
||||
>globalSymbols Foo
|
||||
def skType tv3.Foo Foo $file 4 2 "" 100
|
||||
>def $2
|
||||
>use $2
|
||||
"""
|
||||
|
|
|
|||
9
nimsuggest/tests/tv3_definition.nim
Normal file
9
nimsuggest/tests/tv3_definition.nim
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
|
||||
let foo = 30
|
||||
let bar = foo + fo#[!]#o + foo
|
||||
|
||||
discard """
|
||||
$nimsuggest --v3 --tester $file
|
||||
>def $1
|
||||
def skLet tv3_definition.foo int $file 2 4 "" 100
|
||||
"""
|
||||
Loading…
Add table
Add a link
Reference in a new issue