Skip to content
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

Improve import error suggestions #3553

Draft
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

sobolevn
Copy link
Contributor

This is the first PR in the series.

This case is not covered yet:

#[test]
fn import_submodule_as_value() {
    assert_with_module_error!(
        ("one/two", "pub fn whatever() {}"),
        "
        import one.{two}
        "
    );
}

It requires a bit tricky logic to get right, so I decided to split it out.

Better wordings are more than welcome! 👍

CHANGELOG.md Outdated Show resolved Hide resolved
@sobolevn
Copy link
Contributor Author

Ok, I failed to make suggestions shorter 🙈 They are now longer.

Changes:

  1. I modified how did_you_mean suggestions are applied, because we can literally have this use-case:
#[test]
fn import_value_as_submodule3() {
    // Two possible suggestions: `import one/wobble` or `import one.{wibble}`
    // One via hint, one via `did_you_mean`.
    assert_with_module_error!(
        ("one", "pub fn wibble() {}"),
        ("one/wobble", ""),
        "import one/wibble"
    );
}

We should suggest both:

  • import one/wobble
  • import one.{wibble}

Because it is not clear what was meant. Now we do both suggestions.

  • I changed imported_modules to importable_modules, because imported_modules were always empty in analyze, so we can have better suggestions.
  • I provided a link to the docs, since this topic is rather complex.

Sadly, we cannot apply suggestions from #3553 (comment) which are great, because of syntax error limitations :(
Ideally there should be no syntax error here and all errors should come from analyze step, but it is a very complex and probably-not-justified change.

Please, take a look!

@lpil lpil marked this pull request as draft August 22, 2024 11:13
@sobolevn sobolevn marked this pull request as ready for review August 23, 2024 11:54
Copy link
Member

@lpil lpil left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm finding it confusing the way that 2 different suggestions are presenting in 2 different ways now. I think it should only present 1 suggestion and it should always be presented in the same way.

I was not expecting this.

This syntax for import is not correct. Probably, you meant:
- `import gleam/io` to import module `io` from package `gleam`
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

gleam isn't a package, this would be to import the module gleam/io

name: EcoString,
name_parts: (EcoString, EcoString),
importable_modules: Vec<EcoString>,
},
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Merge this into the existing unknown module error please

UnknownModuleWithRichSuggestions {
location: SrcSpan,
name: EcoString,
name_parts: (EcoString, EcoString),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What are name parts?

No module has been found with the name `this_is_a_very_long_name_for_a_module_even_hard_to_read/this_is_a_very_long_submodule_name`.
Hint: Did you mean `import
this_is_a_very_long_name_for_a_module_even_hard_to_read.
{this_is_a_very_long_submodule_name}`?
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This isn't the correct formatting. Wrapping shouldn't be applied to code.

@lpil lpil marked this pull request as draft September 20, 2024 15:04
@lpil
Copy link
Member

lpil commented Dec 2, 2024

Hello! Are you still working on this one? Thanks

@sobolevn
Copy link
Contributor Author

sobolevn commented Dec 2, 2024

Sorry, no :(
I got busy on my work projects. Feel free to close / transfer to someone else.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants