summary refs log tree commit diff stats
path: root/compiler/suggest.nim
diff options
context:
space:
mode:
authoralaviss <alaviss@users.noreply.github.com>2019-11-04 17:29:26 +0000
committerAndreas Rumpf <rumpf_a@web.de>2019-11-04 18:29:26 +0100
commit558ecd1ca64fecc2ef43bb327dcd055e199beec5 (patch)
tree0f61e09b71e165010887a27de8abd7ebaaa795ba /compiler/suggest.nim
parentae32d637f7f6a590d8cd1b825df004359999bb90 (diff)
downloadNim-558ecd1ca64fecc2ef43bb327dcd055e199beec5.tar.gz
compiler/suggest: add variable support to `con` (#12569)
This allows for the type of a variable to be retrieved.
Diffstat (limited to 'compiler/suggest.nim')
-rw-r--r--compiler/suggest.nim10
1 files changed, 9 insertions, 1 deletions
diff --git a/compiler/suggest.nim b/compiler/suggest.nim
index a254c1f13..85761a8a9 100644
--- a/compiler/suggest.nim
+++ b/compiler/suggest.nim
@@ -293,7 +293,7 @@ proc suggestObject(c: PContext, n, f: PNode; info: TLineInfo, outputs: var Sugge
   else: discard
 
 proc nameFits(c: PContext, s: PSym, n: PNode): bool =
-  var op = n.sons[0]
+  var op = if n.kind in nkCallKinds: n.sons[0] else: n
   if op.kind in {nkOpenSymChoice, nkClosedSymChoice}: op = op.sons[0]
   var opr: PIdent
   case op.kind
@@ -317,6 +317,10 @@ proc suggestCall(c: PContext, n, nOrig: PNode, outputs: var Suggestions) =
   wholeSymTab(filterSym(it, nil, pm) and nameFits(c, it, n) and argsFit(c, it, n, nOrig),
               ideCon)
 
+proc suggestVar(c: PContext, n: PNode, outputs: var Suggestions) =
+  let info = n.info
+  wholeSymTab(nameFits(c, it, n), ideCon)
+
 proc typeFits(c: PContext, s: PSym, firstArg: PType): bool {.inline.} =
   if s.typ != nil and len(s.typ) > 1 and s.typ.sons[1] != nil:
     # special rule: if system and some weird generic match via 'tyUntyped'
@@ -601,6 +605,10 @@ proc suggestExprNoCheck*(c: PContext, n: PNode) =
         if x.kind == nkEmpty or x.typ == nil: break
         addSon(a, x)
       suggestCall(c, a, n, outputs)
+    elif n.kind in nkIdentKinds:
+      var x = safeSemExpr(c, n)
+      if x.kind == nkEmpty or x.typ == nil: x = n
+      suggestVar(c, x, outputs)
 
   dec(c.compilesContextId)
   if outputs.len > 0 and c.config.ideCmd in {ideSug, ideCon, ideDef}: