-
Notifications
You must be signed in to change notification settings - Fork 5.4k
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
feat: auto-import for sway #5174
Conversation
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.
🚀
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.
LGTM but I do insist on that name change as people seem to be easily confused about the fact that CallPath
values from the typed AST are not guaranteed to be valid top level fullpaths, which this explicitly needs to be as I understand the usage.
It doesn't need to be a full path actually, since I end up calling |
Ah never mind that then |
Description
Closes #4782
Notes
This implementation relies on the diagnostics that are provided in the context of a code action request. Conveniently, only the diagnostics related to the symbol in the request are provided in the context. Since we also need the name of the symbol to look up, I added a
DiagnosticData
type to the metadata that is published with diagnostics. For the errors that indicate a missing symbol, this data is attached, and then used to look for possible imports when the code action request handler runs.ProgramTypeKeyword
symbol kind to distinguish them from other keywordssubmodules_recursive
to lexed and parsed modules because LSP wasn't collecting tokens inside of nested submodules. This implementation comes from typed module, I just made it generic via theHasSubmodules
andHasModule
traits.TyIncludeStatement
to the compiler, and span and mod_name toIncludeStatement
to populate it. This was needed to identify where the end of the lastmod
statement is in the file.span
toUseStatment
andTyUseStatement
so that we can replace an entire Group statement with the new one. e.g.use a::b::{C, D, E};
CallPath
to several of the typed tokens that were missing it.Testing
Limitations
I found several bugs / edge cases where auto-import doesn't work:
Checklist
Breaking*
orNew Feature
labels where relevant.