-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
How to determine whether a file is indexed by Rust Analyzer #15837
Comments
The VFS records a number of changes, returns them from I think |
Ah, thanks for the help. Setting the file and calling |
…, r=Veykril feature: Create `UnindexedProject` notification to be sent to the client (Note that this branch contains commits from #15830, which I'll rebase atop of as needed.) Based on the discussion in #15837, I've added a notification and off-by-default toggle to send that notification from `handle_did_open_text_document`. I'm happy to rename/tweak this as needed. I've been using this for a little bit, and it does seem to cause a little bit more indexing/work in rust-analyzer, but it's something that I'll profile as needed, I think.
(While this is marked as a feature request, it's more of a design document/me laying my thoughts out as how to tackle this problem. Thoughts, if any, would be appreciated)
In my employer's monorepo, people are generally using rust-analyzer pretty successfully, but run into issues when they navigate/open a Rust file that isn't part of the workspace that rust-analyzer indexed, which results in—unsurprisingly—a lack of IDE functionality. That's not great, and people don't necessarily know why things aren't working. I'd like to fix this problem by detecting whether the file they've opened is/isn't indexed by rust-analyzer, and if it's not, asking if they'd like that file to be added to their workspace via our enterprisey companion server.
My initial attempt consisted changing
handle_did_open_text_document
to the following (as an experiment, not as a proper solution):This, unfortunately, results in panics coming inside of Salsa along the lines of:
This particular panic occurred after rust-analyzer already indexed a workspace and I navigated to crate I knew wasn't indexed by it. Despite following in the footsteps of how
handle_analyzer_status
command works, it seems that it's not possible to read from the Salsa databases immediately after writing to the VFS. Here are my questions:handle_did_open_text_document
?If the answer to any of the above is no, then the approach that I'll probably take is the following:
handle_did_open_text_document
, we'll check if that file is in the cratedb, and if it's not, do abuck2 uquery "owner(opened_file.rs)"
(we can typically get a response back in ~200 milliseconds).rust-project.json
generation and reload rust-analyzer, so that new file is now indexed.The text was updated successfully, but these errors were encountered: