Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
timotheecour committed Nov 20, 2020
1 parent b425d3e commit d4125a3
Showing 1 changed file with 7 additions and 14 deletions.
21 changes: 7 additions & 14 deletions compiler/lookups.nim
Original file line number Diff line number Diff line change
Expand Up @@ -264,13 +264,11 @@ when false:
of 'a'..'z': result = getIdent(c.cache, toLowerAscii(x.s[0]) & x.s.substr(1))
else: result = x

import std/editdistance
import std/heapqueue

import std/[editdistance, heapqueue]
proc fixSpelling(c: PContext, n: PNode, ident: PIdent, result: var string) =
## when we cannot find the identifier, retry with a changed identifier
# xxx nimfix used to call: prettybase.replaceDeprecated(n.info, ident, alt)
# if not (isDefined(c.config, "nimFixSpelling") or defined(nimfix)): return
## when we cannot find the identifier, suggest nearby spellings
# note: defined(nimfix) used to try `altSpelling` and
# prettybase.replaceDeprecated(n.info, ident, alt)
if optSpellSuggest notin c.config.globalOptions: return
type E = tuple[dist: int, depth: int, sym: PSym]
proc `<`(a, b: E): bool =
Expand All @@ -283,22 +281,17 @@ proc fixSpelling(c: PContext, n: PNode, ident: PIdent, result: var string) =
for h in 0..high(scope.symbols.data):
if scope.symbols.data[h] != nil:
let identi = scope.symbols.data[h]
let si = identi.name.s
let dist = editDistance(name0, si.nimIdentNormalize)
let dist = editDistance(name0, identi.name.s.nimIdentNormalize)
list.push (dist, depth, identi)
depth.inc

# xxx: items(list) should work for HeapQueue
if list.len == 0: return
let e0 = list[0]
# let dist0 = list[0].dist
for i in 0..<list.len:
for i in 0..<list.len: # xxx: items(list) should work for HeapQueue
let e = list[i]
if e0 < e: break
let (dist, depth, sym) = e
result.add "\n candidate misspelling: '" & sym.name.s & "'"
# TODO: .skipAlias(n, c.config) >
addDeclaredLocMaybe(result, c.config, sym)
addDeclaredLocMaybe(result, c.config, sym) # skipAlias not needed

proc errorUseQualifier*(c: PContext; info: TLineInfo; s: PSym) =
var err = "ambiguous identifier: '" & s.name.s & "'"
Expand Down

0 comments on commit d4125a3

Please sign in to comment.