-
-
Notifications
You must be signed in to change notification settings - Fork 801
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Make compiler hint to import unqualified types/values #4304
base: main
Are you sure you want to change the base?
Conversation
The hints should be done now, although I don't if its possible to find the arity (suppose someone wrote |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you! I've added some comments inline, and snapshot tests will need to be added to test all the new paths through the code.
It would be great to also check the arity of the constructors. Suggesting a zero-arity Wibble
when it is being used in a way that takes 2 arguments would be unhelpful.
// Don't suggest importing modules if they are already imported | ||
_ if self | ||
.imported_modules | ||
.contains_key(importable.split('/').last().unwrap_or(importable)) => |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's no fixed relationship between the name used once imported and the name of a module, and this code will produce the same name for multiple modules, so this doesn't successfully skip over already imported modules.
if is_type { | ||
format!("Did you mean to import `{module}.{{type {name}}}`?") | ||
} else { | ||
format!("Did you mean to import `{module}.{{{name}}}`") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't want to encourage unqualified importing of values. Perhaps we should only make these suggestions for types and record constructors.
@@ -23,3 +23,4 @@ error: Unknown type | |||
The type `Wibble` is not defined or imported in this module. | |||
There is a value in scope with the name `Wibble`, but no type in scope with | |||
that name. | |||
Hint: Did you mean to import `module.{type Wibble}`? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the ` should be before the import keyword?
@@ -2326,7 +2331,7 @@ but no type in scope with that name." | |||
Diagnostic { | |||
title: "Unknown variable".into(), | |||
text, | |||
hint: None, | |||
hint: suggestions.first().map(|suggestion| suggestion.suggestion(name, false)), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's a vector of suggestions, but only the first one is used. Seems like only one should be given in that case.
} | ||
|
||
impl TypeOrVariableSuggestion { | ||
pub fn suggestion(&self, name: &str, is_type: bool) -> String { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Never use bools as arguments please 🙏 This could be a Layer
.
This PR closes #4297
Currently the way it decides which module to hint is by preferring imported modules over importable ones, and sorting by name length.