diff options
author | Ivan Yonchovski <yyoncho@users.noreply.github.com> | 2022-08-30 22:02:15 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-08-30 21:02:15 +0200 |
commit | d4c0d35b32e51eae06e65e78c253cdaf8bb42446 (patch) | |
tree | 9a333bb358bd535411ca25dbcd7f74a9e676567a /compiler | |
parent | 04e4a5ec0e35fc7e1c346c2d002e8487b4b48cb5 (diff) | |
download | Nim-d4c0d35b32e51eae06e65e78c253cdaf8bb42446.tar.gz |
[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`
Diffstat (limited to 'compiler')
-rw-r--r-- | compiler/modulegraphs.nim | 22 | ||||
-rw-r--r-- | compiler/suggest.nim | 15 |
2 files changed, 27 insertions, 10 deletions
diff --git a/compiler/modulegraphs.nim b/compiler/modulegraphs.nim index 932f5a0b0..0df72c43b 100644 --- a/compiler/modulegraphs.nim +++ b/compiler/modulegraphs.nim @@ -53,6 +53,10 @@ type concreteTypes*: seq[FullId] inst*: PInstantiation + SymInfoPair* = object + sym*: PSym + info*: TLineInfo + ModuleGraph* {.acyclic.} = ref object ifaces*: seq[Iface] ## indexed by int32 fileIdx packed*: PackedModuleGraph @@ -83,7 +87,7 @@ type doStopCompile*: proc(): bool {.closure.} usageSym*: PSym # for nimsuggest owners*: seq[PSym] - suggestSymbols*: Table[FileIndex, seq[tuple[sym: PSym, info: TLineInfo]]] + suggestSymbols*: Table[FileIndex, seq[SymInfoPair]] suggestErrors*: Table[FileIndex, seq[Suggest]] methods*: seq[tuple[methods: seq[PSym], dispatcher: PSym]] # needs serialization! systemModule*: PSym @@ -374,12 +378,6 @@ template getPContext(): untyped = when defined(nimsuggest): template onUse*(info: TLineInfo; s: PSym) = discard - - template onDef*(info: TLineInfo; s: PSym) = - let c = getPContext() - if c.graph.config.suggestVersion == 3: - suggestSym(c.graph, info, s, c.graph.usageSym) - template onDefResolveForward*(info: TLineInfo; s: PSym) = discard else: template onUse*(info: TLineInfo; s: PSym) = discard @@ -442,7 +440,7 @@ proc initModuleGraphFields(result: ModuleGraph) = result.importStack = @[] result.inclToMod = initTable[FileIndex, FileIndex]() result.owners = @[] - result.suggestSymbols = initTable[FileIndex, seq[tuple[sym: PSym, info: TLineInfo]]]() + result.suggestSymbols = initTable[FileIndex, seq[SymInfoPair]]() result.suggestErrors = initTable[FileIndex, seq[Suggest]]() result.methods = @[] initStrTable(result.compilerprocs) @@ -641,7 +639,13 @@ func belongsToStdlib*(graph: ModuleGraph, sym: PSym): bool = ## Check if symbol belongs to the 'stdlib' package. sym.getPackageSymbol.getPackageId == graph.systemModule.getPackageId -iterator suggestSymbolsIter*(g: ModuleGraph): tuple[sym: PSym, info: TLineInfo] = +proc `==`*(a, b: SymInfoPair): bool = + result = a.sym == b.sym and a.info.exactEquals(b.info) + +proc fileSymbols*(graph: ModuleGraph, fileIdx: FileIndex): seq[SymInfoPair] = + result = graph.suggestSymbols.getOrDefault(fileIdx, @[]).deduplicate + +iterator suggestSymbolsIter*(g: ModuleGraph): SymInfoPair = for xs in g.suggestSymbols.values: for x in xs.deduplicate: yield x diff --git a/compiler/suggest.nim b/compiler/suggest.nim index 7e7d876fb..5e8d896bf 100644 --- a/compiler/suggest.nim +++ b/compiler/suggest.nim @@ -503,7 +503,7 @@ proc suggestSym*(g: ModuleGraph; info: TLineInfo; s: PSym; usageSym: var PSym; i ## misnamed: should be 'symDeclared' let conf = g.config when defined(nimsuggest): - g.suggestSymbols.mgetOrPut(info.fileIndex, @[]).add (s, info) + g.suggestSymbols.mgetOrPut(info.fileIndex, @[]).add SymInfoPair(sym: s, info: info) if conf.suggestVersion == 0: if s.allUsages.len == 0: @@ -699,3 +699,16 @@ proc suggestSentinel*(c: PContext) = dec(c.compilesContextId) produceOutput(outputs, c.config) + +when defined(nimsuggest): + proc onDef(graph: ModuleGraph, s: PSym, info: TLineInfo) = + if graph.config.suggestVersion == 3 and info.exactEquals(s.info): + suggestSym(graph, info, s, graph.usageSym) + + template getPContext(): untyped = + when c is PContext: c + else: c.c + + template onDef*(info: TLineInfo; s: PSym) = + let c = getPContext() + onDef(c.graph, s, info) |