compiler: fix module typo detection

pull/1968/head^2
joe-conigliaro 2019-09-16 03:39:48 +10:00 committed by Alexander Medvednikov
parent 075a8e5ccb
commit 5db25352e5
1 changed files with 4 additions and 5 deletions

View File

@ -881,8 +881,7 @@ fn (table &Table) identify_typo(name string, current_fn &Fn, fit &FileImportTabl
fn (table &Table) find_misspelled_fn(name string, fit &FileImportTable, min_match f32) string { fn (table &Table) find_misspelled_fn(name string, fit &FileImportTable, min_match f32) string {
mut closest := f32(0) mut closest := f32(0)
mut closest_fn := '' mut closest_fn := ''
is_main_fn := name.starts_with('main__') n1 := if name.starts_with('main__') { name.right(6) } else { name }
n1 := if is_main_fn { name.right(6) } else { name }
for _, f in table.fns { for _, f in table.fns {
if n1.len - f.name.len > 2 || f.name.len - n1.len > 2 { continue } if n1.len - f.name.len > 2 || f.name.len - n1.len > 2 { continue }
if !(f.mod in ['', 'main', 'builtin']) { if !(f.mod in ['', 'main', 'builtin']) {
@ -908,10 +907,10 @@ fn (table &Table) find_misspelled_fn(name string, fit &FileImportTable, min_matc
fn (table &Table) find_misspelled_imported_mod(name string, fit &FileImportTable, min_match f32) string { fn (table &Table) find_misspelled_imported_mod(name string, fit &FileImportTable, min_match f32) string {
mut closest := f32(0) mut closest := f32(0)
mut closest_mod := '' mut closest_mod := ''
n1 := if name.starts_with('main.') { name.right(5) } else { name }
for alias, mod in fit.imports { for alias, mod in fit.imports {
n := '${fit.module_name}.$alias' if (n1.len - alias.len > 2 || alias.len - n1.len > 2) { continue }
if !name.starts_with(fit.module_name) || (n.len - name.len > 2 || name.len - n.len > 2) { continue } p := strings.dice_coefficient(n1, alias)
p := strings.dice_coefficient(name, n)
if p > closest { if p > closest {
closest = p closest = p
closest_mod = '$alias ($mod)' closest_mod = '$alias ($mod)'