Fix nimsuggest def being different on proc definition/use (#23025)

Currently the documentation isn't shown when running `def` on the
definition of a proc (Which works for things like variables).
`gcsafe`/`noSideEffects` status also isn't showing up when running `def`
on the definition

Images of current behavior. After PR both look like "Usage"
**Definition**

![image](https://github.com/nim-lang/Nim/assets/19339842/bf75ff0b-9a96-49e5-bf8a-d2c503efa784)
**Usage**

![image](https://github.com/nim-lang/Nim/assets/19339842/15ea3ebf-64e1-48f5-9233-22605183825f)


Issue was the symbol getting passed too early to nimsuggest so it didn't
have all that info, now gets passed once proc is fully semmed
This commit is contained in:
Jake Leahy
2023-12-04 17:15:16 +11:00
committed by GitHub
parent d5780a3e4e
commit b8fa789393
3 changed files with 26 additions and 6 deletions

View File

@@ -2153,7 +2153,9 @@ proc semProcAux(c: PContext, n: PNode, kind: TSymKind,
result = n
checkMinSonsLen(n, bodyPos + 1, c.config)
let isAnon = n[namePos].kind == nkEmpty
let
isAnon = n[namePos].kind == nkEmpty
isHighlight = c.config.ideCmd == ideHighlight
var s: PSym
@@ -2166,7 +2168,10 @@ proc semProcAux(c: PContext, n: PNode, kind: TSymKind,
s = n[namePos].sym
s.owner = c.getCurrOwner
else:
s = semIdentDef(c, n[namePos], kind)
# Highlighting needs to be done early so the position for
# name isn't changed (see taccent_highlight). We don't want to check if this is the
# defintion yet since we are missing some info (comments, side effects)
s = semIdentDef(c, n[namePos], kind, reportToNimsuggest=isHighlight)
n[namePos] = newSymNode(s)
when false:
# disable for now
@@ -2413,6 +2418,11 @@ proc semProcAux(c: PContext, n: PNode, kind: TSymKind,
elif isTopLevel(c) and s.kind != skIterator and s.typ.callConv == ccClosure:
localError(c.config, s.info, "'.closure' calling convention for top level routines is invalid")
# Prevent double highlights. We already highlighted before.
# When not highlighting we still need to allow for suggestions though
if not isHighlight:
suggestSym(c.graph, s.info, s, c.graph.usageSym)
proc determineType(c: PContext, s: PSym) =
if s.typ != nil: return
#if s.magic != mNone: return

View File

@@ -1,12 +1,14 @@
discard """
$nimsuggest --tester $file
>def $1
def;;skProc;;tdef1.hello;;proc (): string{.noSideEffect, gcsafe.};;$file;;9;;5;;"Return hello";;100
>def $1
def;;skProc;;tdef1.hello;;proc (): string{.noSideEffect, gcsafe.};;$file;;9;;5;;"Return hello";;100
def;;skProc;;tdef1.hello;;proc (): string{.noSideEffect, gcsafe.};;$file;;11;;5;;"Return hello";;100
>def $2
def;;skProc;;tdef1.hello;;proc (): string{.noSideEffect, gcsafe.};;$file;;11;;5;;"Return hello";;100
>def $2
def;;skProc;;tdef1.hello;;proc (): string{.noSideEffect, gcsafe.};;$file;;11;;5;;"Return hello";;100
"""
proc hello(): string =
proc hel#[!]#lo(): string =
## Return hello
"Hello"

View File

@@ -0,0 +1,8 @@
discard """
$nimsuggest --tester $file
>sug $1
sug;;skProc;;tsug_recursive.fooBar;;proc ();;$file;;7;;5;;"";;100;;Prefix
"""
proc fooBar() =
fooBa#[!]#