followup #16067 --spellSuggest (#17401)

* followup #16067 --spellSuggest

* enable --spellSuggest by default

* fixup
This commit is contained in:
Timothee Cour 2021-03-16 23:40:29 -07:00 • committed by GitHub
commit 4d3f3513e2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 25 additions and 23 deletions

View file

@ -382,10 +382,12 @@ template toOrderTup(a: SpellCandidate): auto =
proc `<`(a, b: SpellCandidate): bool =
a.toOrderTup < b.toOrderTup
proc mustFixSpelling(c: PContext): bool {.inline.} =
result = c.config.spellSuggestMax != 0 and c.compilesContextId == 0
# don't slowdown inside compiles()
proc fixSpelling(c: PContext, n: PNode, ident: PIdent, result: var string) =
## when we cannot find the identifier, suggest nearby spellings
if c.config.spellSuggestMax == 0: return
if c.compilesContextId > 0: return # don't slowdown inside compiles()
var list = initHeapQueue[SpellCandidate]()
let name0 = ident.s.nimIdentNormalize
@ -458,7 +460,7 @@ proc errorUndeclaredIdentifier*(c: PContext; info: TLineInfo; name: string, extr
proc errorUndeclaredIdentifierHint*(c: PContext; n: PNode, ident: PIdent): PSym =
var extra = ""
fixSpelling(c, n, ident, extra)
if c.mustFixSpelling: fixSpelling(c, n, ident, extra)
errorUndeclaredIdentifier(c, n.info, ident.s, extra)
result = errorSym(c, n)