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
|
|
@ -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;
|
||||
quality: range[0..100]; prefix: PrefixMatch;
|
||||
inTypeContext: bool; scope: int): Suggest =
|
||||
inTypeContext: bool; scope: int;
|
||||
useSuppliedInfo = false): Suggest =
|
||||
new(result)
|
||||
result.section = section
|
||||
result.quality = quality
|
||||
|
|
@ -156,7 +157,11 @@ proc symToSuggest(conf: ConfigRef; s: PSym, isLocal: bool, section: IdeCmd, info
|
|||
result.forth = ""
|
||||
when defined(nimsuggest) and not defined(noDocgen) and not defined(leanCompiler):
|
||||
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.line = toLinenumber(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
|
||||
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 isTracked(info, conf.m.trackPos, s.name.s.len):
|
||||
suggestResult(conf, symToSuggest(conf, s, isLocal=false, ideDef, info, 100, PrefixMatch.None, false, 0))
|
||||
suggestQuit()
|
||||
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, useSuppliedInfo = s == usageSym))
|
||||
if sfForward notin s.flags:
|
||||
suggestQuit()
|
||||
else:
|
||||
usageSym = s
|
||||
|
||||
proc ensureIdx[T](x: var T, y: int) =
|
||||
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:
|
||||
findUsages(conf, info, s, usageSym)
|
||||
elif conf.ideCmd == ideDef:
|
||||
findDefinition(conf, info, s)
|
||||
findDefinition(conf, info, s, usageSym)
|
||||
elif conf.ideCmd == ideDus and s != nil:
|
||||
if isTracked(info, conf.m.trackPos, s.name.s.len):
|
||||
suggestResult(conf, symToSuggest(conf, s, isLocal=false, ideDef, info, 100, PrefixMatch.None, false, 0))
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue