-
Notifications
You must be signed in to change notification settings - Fork 230
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: LSP autocompletion for use statement (#5704)
# Description ## Problem Part of #1577 ## Summary Implements autocompletion for use statements, so typing anything after `use`. https://github.com/user-attachments/assets/a9ecd738-30c2-41fc-8ea0-3ea93d5d99ab Note: the gray hints are probably coming from copilot, I should have turned it off before recording 😅 ## Additional Context To begin implementing autocompletion I thought starting with `use` would be the easiest thing, but also not having to look up the std (or your project) module hierarchy could be useful. To implement this I had to allow parsing `use foo::`, that is, allowing trailing colons, because otherwise that wouldn't parse to a use statement and we wouldn't have any information to do the autocompletion. There are still some cases that don't work. For example if you write `use ` and explicitly ask for autocompletion, you don't get anything. The reason is that `use ` gives a parse error so no AST is produced. We could tackle those in later PRs (I didn't want to continue making this PR bigger). This PR also introduces a simple way to test autocompletions, so next autocompletion PRs should be much smaller. Another thought: at first I was worried that caching `def_maps` in the LSP state would increase the memory usage by a lot, but in retrospective I think that's not a heavy data structure, or at least `NodeInterner`, which was already cached, is probably much larger in memory footprint. I tried this PR in a few projects and the memory usage was fine. ## Documentation Check one: - [x] No documentation needed. - [ ] Documentation included in this PR. - [ ] **[For Experimental Features]** Documentation to be submitted in a separate PR. # PR Checklist\* - [x] I have tested the changes locally. - [x] I have formatted the changes with [Prettier](https://prettier.io/) and/or `cargo fmt` on default settings.
- Loading branch information
Showing
11 changed files
with
868 additions
and
87 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.