compiler: print more suggestions, without a good specific match

pull/6514/head^2
Delyan Angelov 2020-10-01 16:35:14 +03:00
parent d9aa6919d8
commit a0e4be04be
1 changed files with 14 additions and 0 deletions

View File

@ -64,12 +64,26 @@ pub fn (mut s Suggestion) sort() {
pub fn (s Suggestion) say(msg string) string {
mut res := msg
mut found := false
if s.known.len > 0 {
top_posibility := s.known.last()
if top_posibility.similarity > 0.10 {
val := top_posibility.value
if !val.starts_with('[]') {
res += '.\nDid you mean `$val`?'
found = true
}
}
}
if !found {
if s.known.len > 0 {
mut values := s.known.map('`$it.svalue`')
values.sort()
if values.len == 1 {
res += '.\n1 possibility: ${values[0]}.'
} else if values.len < 25 {
// it is hard to read/use too many suggestions
res += '.\n$values.len possibilities: ' + values.join(', ') + '.'
}
}
}