Auto-complete doesn't refresh after cargo-add crate
Check for existing issues
- [X] Completed
Describe the bug / provide steps to reproduce it
cargo add crate dependency using the console
Begin typing an object / fn / trait from the added crate
Observe: no autocomplete suggestions for the added crate
Workaround: re-open project
Environment
Zed: v0.123.2 (Zed) OS: macOS 14.2.1 Memory: 16 GiB Architecture: aarch64
If applicable, add mockups / screenshots to help explain present your vision of the feature
No response
If applicable, attach your ~/Library/Logs/Zed/Zed.log file to this issue.
If you only need the most recent lines, you can run the zed: open log command palette action to see the last 1000.
No response
This is not about Zed but rather about r-a: https://github.com/rust-lang/rust-analyzer/issues/15554
Sorry, apparently things have changed and I did not pay attention — we have to double check that, but I still suspect it might bail down to a rust-analyzer issue.
Oh right, that looks very similar. I tried adding the flag mentioned on that issue to enable server file watching but the issue still seems to occur. Could be that I didn't add the setting properly or it isn't actually supported in Zed.
{
...
"lsp": {
"rust-analyzer": {
"rust-analyzer.files.watcher": "server"
}
...
}
I should also point out that manually editing cargo.toml & saving does refresh the auto completion. Seems like adding the package via console bypasses the file save event that normally triggers re-analysis of the project.
Thank you for trying.
I've observed something similar with npm i the other month, so it might be some issue with Zed FS watched indeed, so let's keep that open for now.
Unfortunately, I have not the bandwidth to check on that deeper this month.
There is some difference in how file changes are handled. Zed "sees" when a file has been changed externally, and when the code breaks, corresponding errors appear in the file editor. But, rescanning of the project (shown as Checking... in the status bar) occurs only when executing “save” inside zed itself.
A likely consequence of this is that external changes are not processed after cargo add or cargo update.
Also, without the "save" command, the "Project Diagnostics" view is not updated, although the number of errors is updated in the status bar.
Cmd+S, after a project file has been changed externally, fixes both issues (it works only when any project file is active in the editor view).
If it is possible to fix this issue with rust-analyzer.files.watcher: "server" or a similar option, we need some example. I also tried to specify it the settings.json, by analogy as this was shown in another example:
"lsp": {
"rust-analyzer": {
"initialization_options": {
"checkOnSave": {
"command": "clippy" // rust-analyzer.checkOnSave.command
},
"files": {
"watcher": "server"
},
But I tried different variants of where to put this option and never saw any error messages about the settings, so there is no certainty that this variant is not incorrect either.