[nimsuggest] return the type when on symbol in let/var (#19639)

- make sure `suggestSym` is called after `PSym.typ` is set.
This commit is contained in:
Ivan Yonchovski 2022-04-07 14:39:27 +03:00 • committed by GitHub
commit 810d5e91e4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 3 deletions

View file

@ -306,7 +306,7 @@ proc identWithin(n: PNode, s: PIdent): bool =
if identWithin(n[i], s): return true if identWithin(n[i], s): return true
result = n.kind == nkSym and n.sym.name.id == s.id result = n.kind == nkSym and n.sym.name.id == s.id
proc semIdentDef(c: PContext, n: PNode, kind: TSymKind): PSym = proc semIdentDef(c: PContext, n: PNode, kind: TSymKind, reportToNimsuggest = true): PSym =
if isTopLevel(c): if isTopLevel(c):
result = semIdentWithPragma(c, kind, n, {sfExported}) result = semIdentWithPragma(c, kind, n, {sfExported})
incl(result.flags, sfGlobal) incl(result.flags, sfGlobal)
@ -330,6 +330,7 @@ proc semIdentDef(c: PContext, n: PNode, kind: TSymKind): PSym =
discard discard
result = n.info result = n.info
let info = getLineInfo(n) let info = getLineInfo(n)
if reportToNimsuggest:
suggestSym(c.graph, info, result, c.graph.usageSym) suggestSym(c.graph, info, result, c.graph.usageSym)
proc checkNilable(c: PContext; v: PSym) = proc checkNilable(c: PContext; v: PSym) =
@ -660,7 +661,7 @@ proc semVarOrLet(c: PContext, n: PNode, symkind: TSymKind): PNode =
if a.kind != nkVarTuple: typ else: tup[j]) if a.kind != nkVarTuple: typ else: tup[j])
addToVarSection(c, result, n, a) addToVarSection(c, result, n, a)
continue continue
var v = semIdentDef(c, a[j], symkind) var v = semIdentDef(c, a[j], symkind, false)
styleCheckDef(c.config, v) styleCheckDef(c.config, v)
onDef(a[j].info, v) onDef(a[j].info, v)
if sfGenSym notin v.flags: if sfGenSym notin v.flags:
@ -725,6 +726,8 @@ proc semVarOrLet(c: PContext, n: PNode, symkind: TSymKind): PNode =
if v.flags * {sfGlobal, sfThread} == {sfGlobal}: if v.flags * {sfGlobal, sfThread} == {sfGlobal}:
message(c.config, v.info, hintGlobalVar) message(c.config, v.info, hintGlobalVar)
suggestSym(c.graph, v.info, v, c.graph.usageSym)
proc semConst(c: PContext, n: PNode): PNode = proc semConst(c: PContext, n: PNode): PNode =
result = copyNode(n) result = copyNode(n)
inc c.inStaticContext inc c.inStaticContext

View file

@ -0,0 +1,7 @@
discard """
$nimsuggest --tester $file
>def $1
def;;skLet;;tdef_let.intVar;;int;;$file;;7;;4;;"";;100
"""
let int#[!]#Var = 10