Skip to content

Adding rustc_private = true to Global Cargo.toml to Allow Parsing in Some lsp-based IDE/editor Backends #428

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

Closed
tempdragon opened this issue Feb 12, 2024 · 5 comments

Comments

@tempdragon
Copy link
Contributor

tempdragon commented Feb 12, 2024

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 to Cargo.toml,

[package.metadata.rust-analyzer]
rustc_private = true

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.

@antoyo
Copy link
Contributor

antoyo commented Feb 12, 2024

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?

@tempdragon
Copy link
Contributor Author

tempdragon commented Feb 13, 2024

Further Comments to the Original Question

  1. 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.)

  2. 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)

My Questions

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

@sadlerap
Copy link
Contributor

sadlerap commented Feb 17, 2024

I got rust-analyzer working in neovim a while back. I needed to do two things:

  1. Set the lines above in Cargo.toml.
  2. Set the lsp option 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.

@antoyo
Copy link
Contributor

antoyo commented Feb 17, 2024

@sadlerap: Thanks, now it works for me!

@tempdragon: Please open a PR with the change and I'll accept it.

@antoyo
Copy link
Contributor

antoyo commented Feb 18, 2024

Fixed in #447.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants