Skip to content

Commit 3b79656

Browse files
committed
refactor
1 parent 4c66dfb commit 3b79656

File tree

2 files changed

+4
-32
lines changed

2 files changed

+4
-32
lines changed

compiler/tools/suggest.nim

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -468,7 +468,7 @@ proc inCheckpoint*(current, trackPos: TLineInfo): TCheckPointResult =
468468

469469
proc isTracked*(current, trackPos: TLineInfo, tokenLen: int): bool =
470470
if current.fileIndex == trackPos.fileIndex and
471-
current.line == trackPos.line:
471+
current.line == trackPos.line:
472472
let col = trackPos.col
473473
if col >= current.col and col <= current.col + tokenLen - 1:
474474
return true

nimlsp/nimlsppkg/nimsuggest.nim

Lines changed: 3 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,11 @@ import
2020
compiler/front/[
2121
options,
2222
optionsprocessor,
23-
# commands,
2423
msgs,
2524
cmdlinehelper,
2625
cli_reporter
2726
],
2827
compiler/utils/[
29-
# prefixmatches,
3028
pathutils
3129
],
3230
compiler/sem/[
@@ -42,7 +40,7 @@ from compiler/ast/reports import Report,
4240

4341
from compiler/front/main import customizeForBackend
4442

45-
from compiler/tools/suggest import isTracked, listUsages, suggestSym, `$`
43+
from compiler/tools/suggest import findTrackedSym, executeCmd, listUsages, suggestSym, `$`
4644

4745
export Suggest
4846
export IdeCmd
@@ -126,19 +124,6 @@ proc initNimSuggest*(project: string, nimPath: string = ""): NimSuggest =
126124
retval.doStopCompile = proc (): bool = false
127125
return NimSuggest(graph: retval, idle: 0, cachedMsgs: @[])
128126

129-
proc findNode(n: PNode; trackPos: TLineInfo): PSym =
130-
if n.kind == nkSym:
131-
if isTracked(n.info, trackPos, n.sym.name.s.len): return n.sym
132-
else:
133-
for i in 0 ..< safeLen(n):
134-
let res = findNode(n[i], trackPos)
135-
if res != nil: return res
136-
137-
proc symFromInfo(graph: ModuleGraph; trackPos: TLineInfo; moduleIdx: FileIndex): PSym =
138-
let m = graph.getModule(moduleIdx)
139-
if m != nil and m.ast != nil:
140-
result = findNode(m.ast, trackPos)
141-
142127
proc getSymNode(node: ParsedNode): ParsedNode =
143128
result = node
144129
if result.kind == pnkPostfix:
@@ -262,22 +247,9 @@ proc executeNoHooks(cmd: IdeCmd, file, dirtyfile: AbsoluteFile, line, col: int,
262247
needCompile = false
263248

264249
if needCompile:
265-
if not isKnownFile:
266-
moduleIdx = dirtyIdx
267-
# stderr.writeLine "Compile unknown module: " & toFullPath(conf, moduleIdx)
268-
discard graph.compileModule(moduleIdx, {})
269-
else:
270-
moduleIdx = graph.parentModule(dirtyIdx)
271-
# stderr.writeLine "Compile known module: " & toFullPath(conf, moduleIdx)
272-
graph.markDirty dirtyIdx
273-
graph.markClientsDirty dirtyIdx
274-
# partially recompiling the project means that that VM and JIT state
275-
# would become stale, which we prevent by discarding all of it:
276-
graph.vm = nil
277-
if conf.ideCmd != ideMod:
278-
discard graph.compileModule(moduleIdx, {})
250+
executeCmd(cmd, file, dirtyfile, line, col, graph)
279251
if conf.ideCmd in {ideUse, ideDus}:
280-
let u = graph.symFromInfo(conf.m.trackPos, moduleIdx)
252+
let u = graph.findTrackedSym()
281253
if u != nil:
282254
listUsages(graph, u)
283255
else:

0 commit comments

Comments
 (0)