Hello, today I installed nvim with rust-analyzer everything works smoothly. The problem arises when I add a new crate via the cargo add command or the cargo.toml file.
Problem description
After adding the crate I see that rust analyzer is doing something because it deactivates error messages and suggestions and a while later I get updated suggestions. But when I try for example to import the new crate by typing use crate_name:: nothing comes. This is strange because rust analyzer says Consider importing this crate.
I noticed that everything started to work as expected only after I manually typed :LspRestart to restart the server.
What I tried
I tried different configurations for nvim (including the ones suggested in the rust analyzer website)
Using rust analyzer from mason
Using rust analyzer from rustup
Is someone experimenting the same behavior? Any help is accepted.
for vscode, there's "rust-analyzer reload workspace" command, the nvim equivalence should be :CargoReload. if you save Cargo.toml in vscode, this command will automatically run, I'm not a vim user, so I don't know how to configure neovim to monitor file change and trigger a command.
I've made my own configs from scratch for two years, use them (but not using mason) in daily Rust programming, and come across minor problems from time to time which might be similar to yours.
If the problem only occasionally appears and LspRestart works, then it's not a big deal at least for me.
But here are some suggestions:
you can try https://helix-editor.com/ which works out of the box and brings the core basic & lsp functionalities from neovim to check if the problem still exists
Ok so I have tried the :CargoReload command and this fix the problem without needing to restart the whole lsp. Maybe there something wrong in my config. If i found something i will update here.
Thanks to everyone for the help
I have tried with a clean config using kickstart.vim, installed rust-analyzer with mason and there is the same problem. @vague can i ask what version of rust analyzer are you using? Mine is: