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
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.
Can't reproduce in my nvim.
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:
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:
Now I can reproduce the problem via the former in neovim and vscode: can't get autocompletion working on the added crate after
cargo add it.
But the autocompletion works in neovim and vscode after editing Cargo.toml directly.
I guess it's a bug around rust-analyzer, and I submited one: Autocompletion for newly added crate doesn't work after `cargo add` it, but works after editing Cargo.toml directly · Issue #15554 · rust-lang/rust-analyzer · GitHub
Thanks, hope it gets fixed. For the moment I'll mark your post as solution.
This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.