Skip to content

Suggest functions in imported modules with the same name as an unknown variable #2697

@JS-JeevaSaravanan

Description

@JS-JeevaSaravanan

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:

import gleam/io

pub fn main() {
  let numbers = [1, 2, 3, 4, 5]
  debug(numbers) // Intended to use io.debug but mistakenly omitted 'io.'
}

Expected Behavior:

I expected the compiler to suggest using io.debug or another relevant function from the gleam/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:

error: Unknown variable
  ┌─ /path/to/project/src/my_project.gleam:5:3
  │
5 │   debug(numbers)
  │   ^^^^^ Did you mean `True`?

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 the debug 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)

image

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions