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
Extend ImportCompletion with declarationType #3997
Extend ImportCompletion with declarationType #3997
Conversation
This is probably my favourite PR I've gotten so far :) Thank you for the detailed write-up. I don't think it's a big deal, but we might want to think about how before this PR it doesn't matter if you pick the type or data constructor completion for a newtype, because you'll always get the import that includes the constructor. Once we merge this users will get the choice which is nice, but it also means they have to think about which of the two completions to pick. You can always automatically fix the compiler warning if you didn't need the constructor, but failing to import it when you need it produces a compiler error, that requires more thinking than just applying a suggestion. Code-wise you can use the purescript/src/Language/PureScript/Ide/Filter/Declaration.hs Lines 13 to 22 in 7ecc426
That way the clients could also just use that field and plug it directly into a declaration type filter, rather than moving back and forth between namespaces and declaration types: https://github.com/purescript/purescript/blob/7ecc42669c69682996f2196ba2eef6c4ca827348/psc-ide/PROTOCOL.md#declaration-type-filter Also thanks for the note about how the ide servers "Can't parse your command" errors aren't helpful when you're hacking on it, I know how to fix that problem but just forgot about doing it. |
Thanks for the praise for the PR, it makes me very happy! I changed the code to use the existing declaration type. It's much simpler that way! Concerning potential confusion for imports, I completely agree with you that there's no need to confuse users when there's really one good option of imports for an identifier. However, since we have these edge cases I prefer exposing this right away here, and then deciding how to present the right information to the user in the language server. Something along the lines of: If there are duplicates where not specifying a type declaration filter will lead to an exception we add the information to the import label. Otherwise, we could merge multiple non-conflicting suggestions into just the one for the Having said that, we could use the same logic that we use for always importing |
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.
Just one more nit, thanks again, this looks great!
Description of the change
This change extends the
Completion
datatype in the IDE. More specifically, it addsdeclarationType
as a field to import completions. This type represents what type of declaration (value, type, typeclass, operator, type operator, etc.) the IDE will add to the file if applied.This addresses #3083 which currently prevents users from importing identifiers if there is more than one candidate with the same name in a file (for example the type-level
/\
and the value level/\
fromData.Tuple.Nested
). Today, attempting to import/\
causespsc-ide
to throw an exception.It's already possible to refine the import command with a namespace filter to make the import succeed, however users (and clients) currently lack the necessary information to make a decision about the namespace. This PR adds this information.
You can also read a longer background story
Checklist: