summary refs log tree commit diff stats
path: root/compiler
diff options
context:
space:
mode:
authorAraq <rumpf_a@web.de>2017-03-09 17:09:39 +0100
committerAraq <rumpf_a@web.de>2017-03-09 17:09:39 +0100
commit57ea01309eb7ff1425fb3bc7907c67139fc50edf (patch)
treebea8226184bf8fb63b4f4acc0640e75dae97d6ef /compiler
parent475579541621ca83cfcbb35df7f5d9ef4236cdfa (diff)
downloadNim-57ea01309eb7ff1425fb3bc7907c67139fc50edf.tar.gz
nimsuggest: more things work
Diffstat (limited to 'compiler')
-rw-r--r--compiler/lexer.nim3
-rw-r--r--compiler/sem.nim4
-rw-r--r--compiler/semexprs.nim6
-rw-r--r--compiler/suggest.nim28
4 files changed, 31 insertions, 10 deletions
diff --git a/compiler/lexer.nim b/compiler/lexer.nim
index afdf17baa..04419d92f 100644
--- a/compiler/lexer.nim
+++ b/compiler/lexer.nim
@@ -213,7 +213,8 @@ proc openLexer*(lex: var TLexer, fileIdx: int32, inputstream: PLLStream;
   lex.currLineIndent = 0
   inc(lex.lineNumber, inputstream.lineOffset)
   lex.cache = cache
-  lex.previousToken.fileIndex = fileIdx
+  when defined(nimsuggest):
+    lex.previousToken.fileIndex = fileIdx
 
 proc openLexer*(lex: var TLexer, filename: string, inputstream: PLLStream;
                 cache: IdentCache) =
diff --git a/compiler/sem.nim b/compiler/sem.nim
index 21a5c435a..2ad506b41 100644
--- a/compiler/sem.nim
+++ b/compiler/sem.nim
@@ -167,6 +167,8 @@ proc commonType*(x, y: PType): PType =
 
 proc newSymS(kind: TSymKind, n: PNode, c: PContext): PSym =
   result = newSym(kind, considerQuotedIdent(n), getCurrOwner(c), n.info)
+  when defined(nimsuggest):
+    suggestDecl(c, n, result)
 
 proc newSymG*(kind: TSymKind, n: PNode, c: PContext): PSym =
   proc `$`(kind: TSymKind): string = substr(system.`$`(kind), 2).toLowerAscii
@@ -191,6 +193,8 @@ proc newSymG*(kind: TSymKind, n: PNode, c: PContext): PSym =
     result = newSym(kind, considerQuotedIdent(n), getCurrOwner(c), n.info)
   #if kind in {skForVar, skLet, skVar} and result.owner.kind == skModule:
   #  incl(result.flags, sfGlobal)
+  when defined(nimsuggest):
+    suggestDecl(c, n, result)
 
 proc semIdentVis(c: PContext, kind: TSymKind, n: PNode,
                  allowed: TSymFlags): PSym
diff --git a/compiler/semexprs.nim b/compiler/semexprs.nim
index a419cd000..3dc174527 100644
--- a/compiler/semexprs.nim
+++ b/compiler/semexprs.nim
@@ -1054,7 +1054,9 @@ proc builtinFieldAccess(c: PContext, n: PNode, flags: TExprFlags): PNode =
   # here at all!
   #if isSymChoice(n.sons[1]): return
   when defined(nimsuggest):
-    if gCmd == cmdIdeTools: suggestExpr(c, n)
+    if gCmd == cmdIdeTools:
+      suggestExpr(c, n)
+      if exactEquals(gTrackPos, n[1].info): suggestExprNoCheck(c, n)
 
   var s = qualifiedLookUp(c, n, {checkAmbiguity, checkUndeclared, checkModule})
   if s != nil:
@@ -2234,6 +2236,8 @@ proc semExpr(c: PContext, n: PNode, flags: TExprFlags = {}): PNode =
   of nkCall, nkInfix, nkPrefix, nkPostfix, nkCommand, nkCallStrLit:
     # check if it is an expression macro:
     checkMinSonsLen(n, 1)
+    #when defined(nimsuggest):
+    #  if gIdeCmd == ideCon and gTrackPos == n.info: suggestExprNoCheck(c, n)
     let mode = if nfDotField in n.flags: {} else: {checkUndeclared}
     var s = qualifiedLookUp(c, n.sons[0], mode)
     if s != nil:
diff --git a/compiler/suggest.nim b/compiler/suggest.nim
index c780f8084..e5a9f424a 100644
--- a/compiler/suggest.nim
+++ b/compiler/suggest.nim
@@ -181,7 +181,7 @@ proc `$`*(suggest: Suggest): string =
     result.add(sep)
     when not defined(noDocgen):
       result.add(suggest.doc.escape)
-    if suggestVersion == 2:
+    if suggestVersion == 0:
       result.add(sep)
       result.add($suggest.quality)
       if suggest.section == ideSug:
@@ -202,6 +202,10 @@ proc suggestResult(s: Suggest) =
 proc produceOutput(a: var Suggestions) =
   if gIdeCmd in {ideSug, ideCon}:
     a.sort cmpSuggestions
+  when false:
+    # debug code
+    writeStackTrace()
+    if a.len > 10: a.setLen(10)
   if not isNil(suggestionResultHook):
     for s in a:
       suggestionResultHook(s)
@@ -332,7 +336,7 @@ proc suggestEverything(c: PContext, n, f: PNode, outputs: var Suggestions) =
       var pm: PrefixMatch
       if filterSym(it, f, pm):
         outputs.add(symToSuggest(it, isLocal = isLocal, $ideSug, 0, pm, c.inTypeContext > 0, scopeN))
-    if scope == c.topLevelScope and f.isNil: break
+    #if scope == c.topLevelScope and f.isNil: break
 
 proc suggestFieldAccess(c: PContext, n, field: PNode, outputs: var Suggestions) =
   # special code that deals with ``myObj.``. `n` is NOT the nkDotExpr-node, but
@@ -340,7 +344,7 @@ proc suggestFieldAccess(c: PContext, n, field: PNode, outputs: var Suggestions)
   var typ = n.typ
   var pm: PrefixMatch
   when defined(nimsuggest):
-    if n.kind == nkSym and n.sym.kind == skError and suggestVersion == 2:
+    if n.kind == nkSym and n.sym.kind == skError and suggestVersion == 0:
       # consider 'foo.|' where 'foo' is some not imported module.
       let fullPath = findModule(n.sym.name.s, n.info.toFullPath)
       if fullPath.len == 0:
@@ -429,7 +433,7 @@ var
   lastLineInfo*: TLineInfo
 
 proc findUsages(info: TLineInfo; s: PSym; usageSym: var PSym) =
-  if suggestVersion < 2:
+  if suggestVersion == 1:
     if usageSym == nil and isTracked(info, s.name.s.len):
       usageSym = s
       suggestResult(symToSuggest(s, isLocal=false, $ideUse, 100, PrefixMatch.None, false, 0))
@@ -460,7 +464,7 @@ proc ensureSeq[T](x: var seq[T]) =
 proc suggestSym*(info: TLineInfo; s: PSym; usageSym: var PSym; isDecl=true) {.inline.} =
   ## misnamed: should be 'symDeclared'
   when defined(nimsuggest):
-    if suggestVersion == 2:
+    if suggestVersion == 0:
       if s.allUsages.isNil:
         s.allUsages = @[info]
       else:
@@ -509,7 +513,6 @@ proc sugExpr(c: PContext, n: PNode, outputs: var Suggestions) =
     # line as the object to prevent this from happening:
     let prefix = if n.len == 2 and n[1].info.line == n[0].info.line and
        not gTrackPosAttached: n[1] else: nil
-    echo n[1].kind
     suggestFieldAccess(c, obj, prefix, outputs)
 
     #if optIdeDebug in gGlobalOptions:
@@ -519,8 +522,7 @@ proc sugExpr(c: PContext, n: PNode, outputs: var Suggestions) =
     let prefix = if gTrackPosAttached: nil else: n
     suggestEverything(c, n, prefix, outputs)
 
-proc suggestExpr*(c: PContext, n: PNode) =
-  if not exactEquals(gTrackPos, n.info): return
+proc suggestExprNoCheck*(c: PContext, n: PNode) =
   # This keeps semExpr() from coming here recursively:
   if c.compilesContextId > 0: return
   inc(c.compilesContextId)
@@ -545,6 +547,16 @@ proc suggestExpr*(c: PContext, n: PNode) =
     produceOutput(outputs)
     suggestQuit()
 
+proc suggestExpr*(c: PContext, n: PNode) =
+  if exactEquals(gTrackPos, n.info): suggestExprNoCheck(c, n)
+
+proc suggestDecl*(c: PContext, n: PNode; s: PSym) =
+  let attached = gTrackPosAttached
+  if attached: inc(c.inTypeContext)
+  defer:
+    if attached: dec(c.inTypeContext)
+  suggestExpr(c, n)
+
 proc suggestStmt*(c: PContext, n: PNode) =
   suggestExpr(c, n)