add more helpful error for calling a decl that exists in a module (#6752)

* add more helpful error for calling a decl that exists in a module

* accord to suggestions

* make error more helpful
This commit is contained in:
pwygab
2022-10-23 00:41:31 +08:00
committed by GitHub
parent 4fdf5c663c
commit 3f555a6836
3 changed files with 42 additions and 0 deletions

View File

@ -270,6 +270,14 @@ impl ExternalCommand {
"'{}' was not found, did you mean '{s}'?",
self.name.item
)
} else if self.name.item == s {
let sugg = engine_state.which_module_has_decl(s.as_bytes());
if let Some(sugg) = sugg {
let sugg = String::from_utf8_lossy(sugg);
format!("command '{s}' was not found but it exists in module '{sugg}'; try using `{sugg} {s}`")
} else {
format!("did you mean '{s}'?")
}
} else {
format!("did you mean '{s}'?")
}