summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorSaem Ghani <saemghani+github@gmail.com>2021-01-06 11:26:16 -0800
committerGitHub <noreply@github.com>2021-01-06 20:26:16 +0100
commit21dfa04cbf638f4059244b4cecf1906b84889a1e (patch)
tree0f4033bb685bf751bce947c5ff151467fa55c31a
parent8a3b6190c3559061ca43cd73faba1a44170b1ee6 (diff)
downloadNim-21dfa04cbf638f4059244b4cecf1906b84889a1e.tar.gz
fixes nim-lang/nimsuggest#119 outline includes (#16608)
nimsuggest outline should account for includes, now it does:
- the module prefix will be of the module doing the including
- the filename will be of the module that was included
- adds a test case for it
-rw-r--r--compiler/suggest.nim16
-rw-r--r--nimsuggest/tests/tinclude.nim10
2 files changed, 21 insertions, 5 deletions
diff --git a/compiler/suggest.nim b/compiler/suggest.nim
index 186b23cd9..73929f813 100644
--- a/compiler/suggest.nim
+++ b/compiler/suggest.nim
@@ -491,9 +491,19 @@ proc suggestSym*(conf: ConfigRef; info: TLineInfo; s: PSym; usageSym: var PSym;
       findUsages(conf, info, s, usageSym)
     elif conf.ideCmd == ideHighlight and info.fileIndex == conf.m.trackPos.fileIndex:
       suggestResult(conf, symToSuggest(conf, s, isLocal=false, ideHighlight, info, 100, PrefixMatch.None, false, 0))
-    elif conf.ideCmd == ideOutline and info.fileIndex == conf.m.trackPos.fileIndex and
-        isDecl:
-      suggestResult(conf, symToSuggest(conf, s, isLocal=false, ideOutline, info, 100, PrefixMatch.None, false, 0))
+    elif conf.ideCmd == ideOutline and isDecl:
+      # if a module is included then the info we have is inside the include and
+      # we need to walk up the owners until we find the outer most module,
+      # which will be the last skModule prior to an skPackage.
+      var
+        parentFileIndex = info.fileIndex # assume we're in the correct module
+        parentModule = s.owner
+      while parentModule != nil and parentModule.kind == skModule:
+        parentFileIndex = parentModule.info.fileIndex
+        parentModule = parentModule.owner
+
+      if parentFileIndex == conf.m.trackPos.fileIndex:
+        suggestResult(conf, symToSuggest(conf, s, isLocal=false, ideOutline, info, 100, PrefixMatch.None, false, 0))
 
 proc extractPragma(s: PSym): PNode =
   if s.kind in routineKinds:
diff --git a/nimsuggest/tests/tinclude.nim b/nimsuggest/tests/tinclude.nim
index 23aa2d727..b67440b9e 100644
--- a/nimsuggest/tests/tinclude.nim
+++ b/nimsuggest/tests/tinclude.nim
@@ -1,4 +1,6 @@
-# import that has an include, def calls must work into and out of includes
+# import that has an include:
+# * def calls must work into and out of includes
+# * outline calls on the import must show included members
 import fixtures/minclude_import
 
 proc go() =
@@ -8,12 +10,16 @@ go()
 
 discard """
 $nimsuggest --tester $file
->def $path/tinclude.nim:5:14
+>def $path/tinclude.nim:7:14
 def;;skProc;;minclude_import.create;;proc (greeting: string, subject: string): Greet{.noSideEffect, gcsafe, locks: 0.};;*fixtures/minclude_include.nim;;3;;5;;"";;100
 >def $path/fixtures/minclude_include.nim:3:71
 def;;skType;;minclude_types.Greet;;Greet;;*fixtures/minclude_types.nim;;4;;2;;"";;100
 >def $path/fixtures/minclude_include.nim:3:71
 def;;skType;;minclude_types.Greet;;Greet;;*fixtures/minclude_types.nim;;4;;2;;"";;100
+>outline $path/fixtures/minclude_import.nim
+outline;;skProc;;minclude_import.say;;*fixtures/minclude_import.nim;;7;;5;;"";;100
+outline;;skProc;;minclude_import.create;;*fixtures/minclude_include.nim;;3;;5;;"";;100
+outline;;skProc;;minclude_import.say;;*fixtures/minclude_import.nim;;13;;5;;"";;100
 """
 
 # TODO test/fix if the first `def` is not first or repeated we get no results