Closed tempdragon closed 6 months ago
Adding these lines doesn't fix the issue for me (I use neovim and nvm-lspconfig).
Maybe you could add this setting directly in your editor-specific LSP config until we find a proper fix that also works in neovim?
In my case, it also requires setting the "Lsp Rust Analyzer Rustc Source" to discover
. Having finished these two steps, my rust-analyzer can correctly index the rustc
. But according to GPT, there doesn't seem to be any alternatives to putting rustc_private
in Cargo.toml
.(However, being a workaround itself, it may be unnecessary for parsing the backend.)
I don't use vim myself but it might be related to this: rustc source in lspconfig, as is used by init.vim(on ln 233)
So how what configurations do you use to have it indexed properly now? BTW, You can see here for the original answer to this question. And, remember to install rustc source code(rust-src) with cargo. Rust Forum
I got rust-analyzer working in neovim a while back. I needed to do two things:
Cargo.toml
.rust-analyzer.rustc.source = "discover"
(you can also set it to an explicit path).For nvim-lspconfig
in particular, you need to have the following:
require('lspconfig').rust_analyzer.setup{
settings = {
['rust-analyzer'] = {
-- add this section
rustc = {
source = "discover",
},
},
},
}
The way I see it, there are two things that need to change. First, we need to add these lines into Cargo.toml
to get things working out-of-the-box there; expecting users to juggle this in and out of their local tree doesn't make a ton of sense to me IMO. Second, we should add a section in the readme letting users know that if they want rust-analyzer
support in their editor/IDE of choice, they need to set the rustc.source = "discover"
option in their editor. This is going to vary from one setup to another, but it might make sense to have the configuration changes for common setups (e.g. VSCode, nvim, emacs, etc.) documented so that users don't have to figure this out.
@sadlerap: Thanks, now it works for me!
@tempdragon: Please open a PR with the change and I'll accept it.
Fixed in #447.
I noticed that on Emacs, the
rustc_codegen_gcc
along with some other rustc-related libraries/projects can be correctly parsed with the following lines added toCargo.toml
,according to rust-analyzer manual (Search for "rustc_private" if you can't see it directly.).
Otherwise, the rust-analyzer will fail to parse with
unresolved external crate
for rustc-related crates.Since there is probably other methods to allow the correct analysis in your IDE without this line, could you please give me some hints about how to have them parse the gcc backend correctly if you choose not to add these lines?
Thanks in advance.