mirror of
https://github.com/nim-lang/Nim.git
synced 2026-01-03 03:32:32 +00:00
nimsuggest supports include files properly; added the compiler itself as a testcase
This commit is contained in:
@@ -25,7 +25,7 @@
|
||||
## - Its dependent module stays the same.
|
||||
##
|
||||
|
||||
import ast, intsets
|
||||
import ast, intsets, tables
|
||||
|
||||
type
|
||||
ModuleGraph* = ref object
|
||||
@@ -34,6 +34,8 @@ type
|
||||
deps*: IntSet # the dependency graph or potentially its transitive closure.
|
||||
suggestMode*: bool # whether we are in nimsuggest mode or not.
|
||||
invalidTransitiveClosure: bool
|
||||
inclToMod*: Table[int32, int32] # mapping of include file to the
|
||||
# first module that included it
|
||||
|
||||
{.this: g.}
|
||||
|
||||
@@ -42,11 +44,13 @@ proc newModuleGraph*(): ModuleGraph =
|
||||
initStrTable(result.packageSyms)
|
||||
result.deps = initIntSet()
|
||||
result.modules = @[]
|
||||
result.inclToMod = initTable[int32, int32]()
|
||||
|
||||
proc resetAllModules*(g: ModuleGraph) =
|
||||
initStrTable(packageSyms)
|
||||
deps = initIntSet()
|
||||
modules = @[]
|
||||
inclToMod = initTable[int32, int32]()
|
||||
|
||||
proc getModule*(g: ModuleGraph; fileIdx: int32): PSym =
|
||||
if fileIdx >= 0 and fileIdx < modules.len:
|
||||
@@ -61,6 +65,18 @@ proc addDep*(g: ModuleGraph; m: PSym, dep: int32) =
|
||||
# this improve efficiency quite a lot:
|
||||
invalidTransitiveClosure = true
|
||||
|
||||
proc addIncludeDep*(g: ModuleGraph; module, includeFile: int32) =
|
||||
discard hasKeyOrPut(inclToMod, includeFile, module)
|
||||
|
||||
proc parentModule*(g: ModuleGraph; fileIdx: int32): int32 =
|
||||
## returns 'fileIdx' if the file belonging to this index is
|
||||
## directly used as a module or else the module that first
|
||||
## references this include file.
|
||||
if fileIdx >= 0 and fileIdx < modules.len and modules[fileIdx] != nil:
|
||||
result = fileIdx
|
||||
else:
|
||||
result = inclToMod.getOrDefault(fileIdx)
|
||||
|
||||
proc transitiveClosure(g: var IntSet; n: int) =
|
||||
# warshall's algorithm
|
||||
for k in 0..<n:
|
||||
|
||||
@@ -208,6 +208,7 @@ proc includeModule*(graph: ModuleGraph; s: PSym, fileIdx: int32;
|
||||
cache: IdentCache): PNode {.procvar.} =
|
||||
result = syntaxes.parseFile(fileIdx, cache)
|
||||
graph.addDep(s, fileIdx)
|
||||
graph.addIncludeDep(s.position.int32, fileIdx)
|
||||
|
||||
proc compileSystemModule*(graph: ModuleGraph; cache: IdentCache) =
|
||||
if magicsys.systemModule == nil:
|
||||
|
||||
@@ -157,13 +157,11 @@ proc execute(cmd: IdeCmd, file, dirtyfile: string, line, col: int;
|
||||
dirtyfile.len == 0:
|
||||
discard "no need to recompile anything"
|
||||
else:
|
||||
#resetModule dirtyIdx
|
||||
#if dirtyIdx != gProjectMainIdx:
|
||||
# resetModule gProjectMainIdx
|
||||
graph.markDirty dirtyIdx
|
||||
graph.markClientsDirty dirtyIdx
|
||||
let modIdx = graph.parentModule(dirtyIdx)
|
||||
graph.markDirty modIdx
|
||||
graph.markClientsDirty modIdx
|
||||
if gIdeCmd != ideMod:
|
||||
graph.compileProject(cache, dirtyIdx)
|
||||
graph.compileProject(cache, modIdx)
|
||||
if gIdeCmd in {ideUse, ideDus}:
|
||||
let u = if suggestVersion >= 2: graph.symFromInfo(gTrackPos) else: usageSym
|
||||
if u != nil:
|
||||
|
||||
7
tools/nimsuggest/tests/tinclude.nim
Normal file
7
tools/nimsuggest/tests/tinclude.nim
Normal file
@@ -0,0 +1,7 @@
|
||||
discard """
|
||||
$nimsuggest --tester compiler/nim.nim
|
||||
>def compiler/semexprs.nim:13:50
|
||||
def;;skType;;ast.PSym;;PSym;;*ast.nim;;668;;2;;"";;100
|
||||
>def compiler/semexprs.nim:13:50
|
||||
def;;skType;;ast.PSym;;PSym;;*ast.nim;;668;;2;;"";;100
|
||||
"""
|
||||
Reference in New Issue
Block a user