Skip to content

Commit

Permalink
followup nim-lang#16067 --spellSuggest
Browse files Browse the repository at this point in the history
  • Loading branch information
timotheecour committed Mar 16, 2021
1 parent 9bb0e55 commit e4d05b3
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
1 change: 1 addition & 0 deletions compiler/condsyms.nim
Original file line number Diff line number Diff line change
Expand Up @@ -129,3 +129,4 @@ proc initDefines*(symbols: StringTableRef) =
defineSymbol("nimHasJsBigIntBackend")
defineSymbol("nimHasWarningAsError")
defineSymbol("nimHasHintAsError")
defineSymbol("nimHasSpellSuggest")
8 changes: 5 additions & 3 deletions compiler/lookups.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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)

Expand Down

0 comments on commit e4d05b3

Please sign in to comment.