nimsuggest prioritize non-deprecated suggestions (#16816)

* penalizes the quality score of deprecated symbols
* uses quality more pervasively in order to reflect deprecation impact
* impacts both sug and con

additional notes:
* linux i386 CI was failing
* this is because the suggested results differ slightly in their sort
* 64 bit tables.getOrDefault:441 was returned, while 32 bit returned 422
* for now simply removing the last line is good enough
This commit is contained in:
Saem Ghani 2021-01-29 06:15:35 -08:00 • committed by GitHub
commit 1097cc4173
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 39 additions and 25 deletions

View file

@ -258,17 +258,22 @@ proc fieldVisible*(c: PContext, f: PSym): bool {.inline.} =
result = true
break
proc suggestField(c: PContext, s: PSym; f: PNode; info: TLineInfo; outputs: var Suggestions) =
var pm: PrefixMatch
if filterSym(s, f, pm) and fieldVisible(c, s):
outputs.add(symToSuggest(c.graph, s, isLocal=true, ideSug, info, 100, pm, c.inTypeContext > 0, 0))
proc getQuality(s: PSym): range[0..100] =
result = 100
if s.typ != nil and s.typ.len > 1:
var exp = s.typ[1].skipTypes({tyGenericInst, tyVar, tyLent, tyAlias, tySink})
if exp.kind == tyVarargs: exp = elemType(exp)
if exp.kind in {tyUntyped, tyTyped, tyGenericParam, tyAnything}: return 50
return 100
if exp.kind in {tyUntyped, tyTyped, tyGenericParam, tyAnything}: result = 50
# penalize deprecated symbols
if sfDeprecated in s.flags:
result = result - 5
proc suggestField(c: PContext, s: PSym; f: PNode; info: TLineInfo; outputs: var Suggestions) =
var pm: PrefixMatch
if filterSym(s, f, pm) and fieldVisible(c, s):
outputs.add(symToSuggest(c.graph, s, isLocal=true, ideSug, info,
s.getQuality, pm, c.inTypeContext > 0, 0))
template wholeSymTab(cond, section: untyped) {.dirty.} =
for (item, scopeN, isLocal) in allSyms(c):
@ -347,8 +352,8 @@ proc suggestEverything(c: PContext, n, f: PNode, outputs: var Suggestions) =
for (it, scopeN, isLocal) in allSyms(c):
var pm: PrefixMatch
if filterSym(it, f, pm):
outputs.add(symToSuggest(c.graph, it, isLocal = isLocal, ideSug, n.info, 0, pm,
c.inTypeContext > 0, scopeN))
outputs.add(symToSuggest(c.graph, it, isLocal = isLocal, ideSug, n.info,
it.getQuality, pm, c.inTypeContext > 0, scopeN))
proc suggestFieldAccess(c: PContext, n, field: PNode, outputs: var Suggestions) =
# special code that deals with ``myObj.``. `n` is NOT the nkDotExpr-node, but
@ -368,9 +373,12 @@ proc suggestFieldAccess(c: PContext, n, field: PNode, outputs: var Suggestions)
else:
for it in allSyms(c.graph, n.sym):
if filterSym(it, field, pm):
outputs.add(symToSuggest(c.graph, it, isLocal=false, ideSug, n.info, 100, pm, c.inTypeContext > 0, -100))
outputs.add(symToSuggest(c.graph, m, isLocal=false, ideMod, n.info, 100, PrefixMatch.None,
c.inTypeContext > 0, -99))
outputs.add(symToSuggest(c.graph, it, isLocal=false, ideSug,
n.info, it.getQuality, pm,
c.inTypeContext > 0, -100))
outputs.add(symToSuggest(c.graph, m, isLocal=false, ideMod, n.info,
100, PrefixMatch.None, c.inTypeContext > 0,
-99))
if typ == nil:
# a module symbol has no type for example:
@ -379,11 +387,15 @@ proc suggestFieldAccess(c: PContext, n, field: PNode, outputs: var Suggestions)
# all symbols accessible, because we are in the current module:
for it in items(c.topLevelScope.symbols):
if filterSym(it, field, pm):
outputs.add(symToSuggest(c.graph, it, isLocal=false, ideSug, n.info, 100, pm, c.inTypeContext > 0, -99))
outputs.add(symToSuggest(c.graph, it, isLocal=false, ideSug,
n.info, it.getQuality, pm,
c.inTypeContext > 0, -99))
else:
for it in allSyms(c.graph, n.sym):
if filterSym(it, field, pm):
outputs.add(symToSuggest(c.graph, it, isLocal=false, ideSug, n.info, 100, pm, c.inTypeContext > 0, -99))
outputs.add(symToSuggest(c.graph, it, isLocal=false, ideSug,
n.info, it.getQuality, pm,
c.inTypeContext > 0, -99))
else:
# fallback:
suggestEverything(c, n, field, outputs)
@ -667,7 +679,7 @@ proc suggestSentinel*(c: PContext) =
var pm: PrefixMatch
if filterSymNoOpr(it, nil, pm):
outputs.add(symToSuggest(c.graph, it, isLocal = isLocal, ideSug,
newLineInfo(c.config.m.trackPos.fileIndex, 0, -1), 0,
newLineInfo(c.config.m.trackPos.fileIndex, 0, -1), it.getQuality,
PrefixMatch.None, false, scopeN))
dec(c.compilesContextId)