suggest: try to find the implementation of a symbol when def is used (#15555)
* suggest: try to find the implementation of a symbol when def is used * suggest: return all declarations of the symbol on `def`
This commit is contained in:
parent
977bccdbff
commit
c2ba4ef979
4 changed files with 33 additions and 7 deletions
|
|
@ -361,3 +361,7 @@ proc mydiv(a, b): int {.raises: [].} =
|
||||||
|
|
||||||
|
|
||||||
## Tool changes
|
## Tool changes
|
||||||
|
|
||||||
|
- `nimsuggest` will now return both the forward declaration and the
|
||||||
|
implementation location upon a `def` query. Previously the behavior was
|
||||||
|
just to return the forward declaration.
|
||||||
|
|
|
||||||
|
|
@ -1943,6 +1943,7 @@ proc semProcAux(c: PContext, n: PNode, kind: TSymKind,
|
||||||
if not comesFromShadowScope:
|
if not comesFromShadowScope:
|
||||||
excl(proto.flags, sfForward)
|
excl(proto.flags, sfForward)
|
||||||
incl(proto.flags, sfWasForwarded)
|
incl(proto.flags, sfWasForwarded)
|
||||||
|
suggestSym(c.config, s.info, proto, c.graph.usageSym)
|
||||||
closeScope(c) # close scope with wrong parameter symbols
|
closeScope(c) # close scope with wrong parameter symbols
|
||||||
openScope(c) # open scope for old (correct) parameter symbols
|
openScope(c) # open scope for old (correct) parameter symbols
|
||||||
if proto.ast[genericParamsPos].kind != nkEmpty:
|
if proto.ast[genericParamsPos].kind != nkEmpty:
|
||||||
|
|
|
||||||
|
|
@ -119,7 +119,8 @@ proc getTokenLenFromSource(conf: ConfigRef; ident: string; info: TLineInfo): int
|
||||||
|
|
||||||
proc symToSuggest(conf: ConfigRef; s: PSym, isLocal: bool, section: IdeCmd, info: TLineInfo;
|
proc symToSuggest(conf: ConfigRef; s: PSym, isLocal: bool, section: IdeCmd, info: TLineInfo;
|
||||||
quality: range[0..100]; prefix: PrefixMatch;
|
quality: range[0..100]; prefix: PrefixMatch;
|
||||||
inTypeContext: bool; scope: int): Suggest =
|
inTypeContext: bool; scope: int;
|
||||||
|
useSuppliedInfo = false): Suggest =
|
||||||
new(result)
|
new(result)
|
||||||
result.section = section
|
result.section = section
|
||||||
result.quality = quality
|
result.quality = quality
|
||||||
|
|
@ -156,7 +157,11 @@ proc symToSuggest(conf: ConfigRef; s: PSym, isLocal: bool, section: IdeCmd, info
|
||||||
result.forth = ""
|
result.forth = ""
|
||||||
when defined(nimsuggest) and not defined(noDocgen) and not defined(leanCompiler):
|
when defined(nimsuggest) and not defined(noDocgen) and not defined(leanCompiler):
|
||||||
result.doc = s.extractDocComment
|
result.doc = s.extractDocComment
|
||||||
let infox = if section in {ideUse, ideHighlight, ideOutline}: info else: s.info
|
let infox =
|
||||||
|
if useSuppliedInfo or section in {ideUse, ideHighlight, ideOutline}:
|
||||||
|
info
|
||||||
|
else:
|
||||||
|
s.info
|
||||||
result.filePath = toFullPath(conf, infox)
|
result.filePath = toFullPath(conf, infox)
|
||||||
result.line = toLinenumber(infox)
|
result.line = toLinenumber(infox)
|
||||||
result.column = toColumn(infox)
|
result.column = toColumn(infox)
|
||||||
|
|
@ -463,11 +468,14 @@ when defined(nimsuggest):
|
||||||
let x = if info == s.info and info.col == s.info.col: ideDef else: ideUse
|
let x = if info == s.info and info.col == s.info.col: ideDef else: ideUse
|
||||||
suggestResult(conf, symToSuggest(conf, s, isLocal=false, x, info, 100, PrefixMatch.None, false, 0))
|
suggestResult(conf, symToSuggest(conf, s, isLocal=false, x, info, 100, PrefixMatch.None, false, 0))
|
||||||
|
|
||||||
proc findDefinition(conf: ConfigRef; info: TLineInfo; s: PSym) =
|
proc findDefinition(conf: ConfigRef; info: TLineInfo; s: PSym; usageSym: var PSym) =
|
||||||
if s.isNil: return
|
if s.isNil: return
|
||||||
if isTracked(info, conf.m.trackPos, s.name.s.len):
|
if isTracked(info, conf.m.trackPos, s.name.s.len) or (s == usageSym and sfForward notin s.flags):
|
||||||
suggestResult(conf, symToSuggest(conf, s, isLocal=false, ideDef, info, 100, PrefixMatch.None, false, 0))
|
suggestResult(conf, symToSuggest(conf, s, isLocal=false, ideDef, info, 100, PrefixMatch.None, false, 0, useSuppliedInfo = s == usageSym))
|
||||||
suggestQuit()
|
if sfForward notin s.flags:
|
||||||
|
suggestQuit()
|
||||||
|
else:
|
||||||
|
usageSym = s
|
||||||
|
|
||||||
proc ensureIdx[T](x: var T, y: int) =
|
proc ensureIdx[T](x: var T, y: int) =
|
||||||
if x.len <= y: x.setLen(y+1)
|
if x.len <= y: x.setLen(y+1)
|
||||||
|
|
@ -487,7 +495,7 @@ proc suggestSym*(conf: ConfigRef; info: TLineInfo; s: PSym; usageSym: var PSym;
|
||||||
if conf.ideCmd == ideUse:
|
if conf.ideCmd == ideUse:
|
||||||
findUsages(conf, info, s, usageSym)
|
findUsages(conf, info, s, usageSym)
|
||||||
elif conf.ideCmd == ideDef:
|
elif conf.ideCmd == ideDef:
|
||||||
findDefinition(conf, info, s)
|
findDefinition(conf, info, s, usageSym)
|
||||||
elif conf.ideCmd == ideDus and s != nil:
|
elif conf.ideCmd == ideDus and s != nil:
|
||||||
if isTracked(info, conf.m.trackPos, s.name.s.len):
|
if isTracked(info, conf.m.trackPos, s.name.s.len):
|
||||||
suggestResult(conf, symToSuggest(conf, s, isLocal=false, ideDef, info, 100, PrefixMatch.None, false, 0))
|
suggestResult(conf, symToSuggest(conf, s, isLocal=false, ideDef, info, 100, PrefixMatch.None, false, 0))
|
||||||
|
|
|
||||||
13
nimsuggest/tests/tdef_forward.nim
Normal file
13
nimsuggest/tests/tdef_forward.nim
Normal file
|
|
@ -0,0 +1,13 @@
|
||||||
|
discard """
|
||||||
|
$nimsuggest --tester $file
|
||||||
|
>def $1
|
||||||
|
def;;skProc;;tdef_forward.hello;;proc (): string;;$file;;8;;5;;"";;100
|
||||||
|
def;;skProc;;tdef_forward.hello;;proc (): string;;$file;;12;;5;;"";;100
|
||||||
|
"""
|
||||||
|
|
||||||
|
proc hello(): string
|
||||||
|
|
||||||
|
hel#[!]#lo()
|
||||||
|
|
||||||
|
proc hello(): string =
|
||||||
|
"Hello"
|
||||||
Loading…
Add table
Add a link
Reference in a new issue