-
-
Notifications
You must be signed in to change notification settings - Fork 658
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
Suggest functions in imported modules with the same name as an unknown variable #2697
Comments
Good idea! Thank you |
Hi @lpil and everyone, I'm interested in supporting Gleam. It's great to see all the work being done, and it's my first time contributing here. Could anyone help me get started and work on this issue? I think I need to make changes in |
Wonderful, thank you. You'd need to find where the error is emitted and at that point look to see which (if any) of the imported modules have functions with that name with the same number of arguments. If any are found then you can add the names of the modules to the error and then when printing the error include them in the error message in some way. |
…iable This improves the overall compiler unknown variables suggestions by listing all imported modules values in the scope so it can now recommands imports. For example with the following code (described in GitHub issue gleam-lang#2697): ``` import gleam/io pub fn main() { let numbers = [1, 2, 3, 4, 5] debug(numbers) // Intended to use io.debug but mistakenly omitted 'io.' } ``` The current version of the compiler provides the following error: ``` error: Unknown variable ┌─ /path/to/project/src/my_project.gleam:5:3 │ 5 │ debug(numbers) │ ^^^^^ Did you mean `True`? ``` With my changes the suggestions are a bit smarter: ``` error: Unknown variable ┌─ /Users/shellbear/code/gleamio/src/gleamio.gleam:5:3 │ 5 │ debug(numbers) // Intended to use io.debug but mistakenly omitted 'io.' │ ^^^^^ Did you mean `io.debug`? The name `debug` is not in scope here. ```
…iable This improves the overall compiler unknown variables suggestions by listing all imported modules values in the scope so it can now recommends imports. For example with the following code (described in GitHub issue gleam-lang#2697): ``` import gleam/io pub fn main() { let numbers = [1, 2, 3, 4, 5] debug(numbers) // Intended to use io.debug but mistakenly omitted 'io.' } ``` The current version of the compiler provides the following error: ``` error: Unknown variable ┌─ /path/to/project/src/my_project.gleam:5:3 │ 5 │ debug(numbers) │ ^^^^^ Did you mean `True`? ``` With my changes the suggestions are a bit smarter: ``` error: Unknown variable ┌─ /Users/shellbear/code/gleamio/src/gleamio.gleam:5:3 │ 5 │ debug(numbers) // Intended to use io.debug but mistakenly omitted 'io.' │ ^^^^^ Did you mean `io.debug`? The name `debug` is not in scope here. ```
…iable This improves the overall compiler unknown variables suggestions by listing all imported modules values in the scope so it can now recommends imports. For example with the following code (described in GitHub issue gleam-lang#2697): ``` import gleam/io pub fn main() { let numbers = [1, 2, 3, 4, 5] debug(numbers) // Intended to use io.debug but mistakenly omitted 'io.' } ``` The current version of the compiler provides the following error: ``` error: Unknown variable ┌─ /path/to/project/src/my_project.gleam:5:3 │ 5 │ debug(numbers) │ ^^^^^ Did you mean `True`? ``` With my changes the suggestions are a bit smarter: ``` error: Unknown variable ┌─ /Users/shellbear/code/gleamio/src/gleamio.gleam:5:3 │ 5 │ debug(numbers) // Intended to use io.debug but mistakenly omitted 'io.' │ ^^^^^ Did you mean `io.debug`? The name `debug` is not in scope here. ```
Thank you @lpil and @shellbear for resolving this issue ! Good work guys ! |
…iable This improves the overall compiler unknown variables suggestions by listing all imported modules values in the scope so it can now recommends imports. For example with the following code (described in GitHub issue gleam-lang#2697): ``` import gleam/io pub fn main() { let numbers = [1, 2, 3, 4, 5] debug(numbers) // Intended to use io.debug but mistakenly omitted 'io.' } ``` The current version of the compiler provides the following error: ``` error: Unknown variable ┌─ /path/to/project/src/my_project.gleam:5:3 │ 5 │ debug(numbers) │ ^^^^^ Did you mean `True`? ``` With my changes the suggestions are a bit smarter: ``` error: Unknown variable ┌─ /Users/shellbear/code/gleamio/src/gleamio.gleam:5:3 │ 5 │ debug(numbers) // Intended to use io.debug but mistakenly omitted 'io.' │ ^^^^^ Did you mean `io.debug`? The name `debug` is not in scope here. ```
Description of the Problem:
While working with Gleam version 1.0.0, I attempted to use a function to print a list of numbers to the console but mistakenly omitted the package prefix from the function call. Instead of suggesting the correct function from the imported package, the compiler suggested an unrelated term.
Code to Reproduce:
Expected Behavior:
I expected the compiler to suggest using
io.debug
or another relevant function from thegleam/io
package since it was imported and contained functions for console output.Actual Behavior:
The compiler identified
debug
as an unknown variable and suggested unrelated terms, missing the opportunity to suggest the correct function from an already imported package.Error Message:
Suggested Improvement:
Enhance the compiler's error suggestions to consider functions available in the imported modules/packages, especially when an unknown function or variable matches a name in those imports. This feature could significantly improve developer experience by providing more contextually relevant suggestions and reducing potential confusion, particularly for newcomers or in cases of simple typos.
Additional Context:
This issue arose when I tried to print a list of numbers without correctly specifying the
io
module prefix for thedebug
function. The current compiler suggestions did not help in guiding me towards the correct usage of imported functions.Gleam Version: 1.0.0
Operating System: macOS Ventura (Version 13.2)
The text was updated successfully, but these errors were encountered: