-
Notifications
You must be signed in to change notification settings - Fork 243
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: correctly track sources for open LSP documents (#5561)
# Description ## Problem Resolves #5562 ## Summary I noticed that our LSP code puts unsaved files into an `input_files` dictionary, but that dictionary was not used when adding files to a FileManager, meaning that file sources always corresponded to disk contents, never unsaved content. Additionally, when we got a notification that a file changed, only that file (without everything it depended on) was processed, just to get code lenses. That means that references to types and variables weren't updated here, so things like hover, go to reference and inlay hints wouldn't work well. To fix this, a few things have been done in this PR: 1. When creating a FileManager, always add these unsaved files first. 2. When we get the notification that a file was changed, type-check only the current package but without producing errors (at least Rust Analyzer doesn't update the Problems list until you save a file). This is also how it used to work before this PR. 3. When a file is closed, we also type-check the current package to update references (to avoid keeping references to that unsaved code locations). Type-checking a package on every edit sounds a bit too much... but I checked a few big crates and type-checking just a single package (in a workspace of many packages) takes around 300ms on my machine (with a debug build), so I think it's acceptable. If it's slower then it might still be good enough (it's worse if things break and you get incorrect inlay hints or error notifications). Maybe ideally we'd process all top-level definitions in a package, but only fully type-check (looking inside function definitions) in the file that just changed, but I couldn't find an easy way to do that, so that would be an optimization for later (if really needed). ## Additional Context ## 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
7 changed files
with
236 additions
and
97 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
Oops, something went wrong.