Skip to content

Conversation

mine-tech-oficial
Copy link

@mine-tech-oficial mine-tech-oficial commented Mar 5, 2025

This PR closes #4297

  • Show hint to import unqualified types
  • Show hint to import unqualified values
  • Consider the type's arity
  • Consider the value's arity

Currently the way it decides which module to hint is by preferring imported modules over importable ones, and sorting by name length.

@mine-tech-oficial
Copy link
Author

The hints should be done now, although I don't if its possible to find the arity (suppose someone wrote Dict, mentioning dict.Dict, but didn't put the types, which the code would recognize as "nullary"). Also, the current code for suggesting modules to import also doesn't take the arity into account.

@mine-tech-oficial mine-tech-oficial marked this pull request as ready for review March 6, 2025 13:22
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.

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.

if is_type {
format!("Did you mean to import `{module}.{{type {name}}}`?")
} else {
format!("Did you mean to import `{module}.{{{name}}}`")
Copy link
Member

@lpil lpil Mar 10, 2025

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.

Copy link
Author

Choose a reason for hiding this comment

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

Okay! Tying with my point below, we could write the "generic" value case as "Did you mean to reference module.{value}" and, in case it isn't already imported, "Did you mean to import module and reference module.{value}". What do you think?

title: "Unknown variable".into(),
text,
hint: None,
hint: suggestions.first().map(|suggestion| suggestion.suggestion(name, false)),
Copy link
Member

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.

Copy link
Author

Choose a reason for hiding this comment

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

I thought this was fine, as that is what the current code for module suggestions does. Anyway, I'll change it!

Copy link
Author

Choose a reason for hiding this comment

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

Actually, having a vector of suggestions allows the LS to give all possible quick fixes when a code action to do so is done (I have one basically ready, will do a PR after this one is pushed)

@lpil lpil marked this pull request as draft March 10, 2025 12:58
@mine-tech-oficial
Copy link
Author

The code should now consider arity, but it is an Option as I don't think it is possible to find the arity in all cases.

@mine-tech-oficial mine-tech-oficial marked this pull request as ready for review March 10, 2025 23:13
@mine-tech-oficial mine-tech-oficial requested a review from lpil March 14, 2025 20:41
@mine-tech-oficial
Copy link
Author

Hey @lpil, I've answered some of your questions, waiting on clarifications!

@mine-tech-oficial
Copy link
Author

I have implemented the code actions locally. Should I push them to this PR or wait for a future one?

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.

Thank you! Looking good. I've left some comments inline, and the tests still need to be added for each possible path through the code.

@lpil lpil marked this pull request as draft March 17, 2025 11:54
@mine-tech-oficial mine-tech-oficial marked this pull request as ready for review March 20, 2025 00:16
@mine-tech-oficial
Copy link
Author

mine-tech-oficial commented Mar 20, 2025

@lpil, I think I have addressed all of your points! Right now I just need to comment and write tests, and I'm waiting on some clarifications.

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.

Thank you

@mine-tech-oficial
Copy link
Author

Should be all done now!

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.

Thank you! Nearly there! Few small things around the wording

@mine-tech-oficial
Copy link
Author

Now it should be ready! Also, the way I've refactored, it allows for the normal module suggestion to consider arity in the future

@mine-tech-oficial mine-tech-oficial requested a review from lpil March 24, 2025 20:32
@mine-tech-oficial
Copy link
Author

@lpil, now the hint is better (thanks Gears for the suggestion) and I have removed the indents in tests, so I think there should be nothing left to do!

@mine-tech-oficial
Copy link
Author

@lpil, I'm thinking on redoing this on the latest Gleam version, to facilitate merging, although it might take a bit. What do you think?

@lpil
Copy link
Member

lpil commented May 15, 2025

Sounds good to me!

@mine-tech-oficial
Copy link
Author

Closed, continued in #4602

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.

Show hint to import unqualified types/values
3 participants