How to get cfg(target_arch) rust-analyzer warnings to be quiet

I'm very new to rust and especially rust-analyzer so apologies in advance if this is a little incomprehensible like that.

I'm trying to follow along a tutorial for wgpu and they have a lot of the #[cfg(target_arch = "wasm32")] attribute going on. And for each of them I get the note rust-analyzer: code is inactive due to #[cfg] directives: target_arch = "wasm32" is disabled. This is, to say the least, annoying. How can I get them to be quiet?

For context, I am using Neovim (specifically LazyVim, with which I have { "LazyVim/LazyVim", import = "lazyvim.plugins.extras.lang.rust" } in my plugins. And I use Nix/Home Manager as a package manager/config management if that's relevant though it should be effectively just editing a Neovim config. Also, ideally, whatever solution wouldn't be global; I imagine other projects would benefit from the warnings.

That said, I have tried a few basic things I found:

  • setting cargo.target = "wasm32-unknown-unknown"
  • setting cargo.cfgs = [ "debug_assertions", "miri", "target_arch=\"wasm32\"" ]
  • well, specifically opts.default_settings.["rust-analyzer"].<above> and appropriately formatted for a Lua-based Neovim config.

Neither of those seemed to work. (Final note: it's very late and I need sleep so sorry if I take a while to respond.)

Mahbe you need to write it as { cargo = { target = "wasm32-unknown-unknown } } or something like that. In vscode you would write it as rust-analyzer.cargo.target, bus the LSP protocol would pass that as { "rust-analyzer": { "cargo": { "target": "wasm32-unknown-unknown" } } } to the language server. Many editors other than vscode use this nesting verbatim rather than flattening it like vscode.

I should have been more clear that I was using the nesting format. I have solved the problem though. My biggest problem was being a dunce and forgetting a nest level and misspelling. Also, I found that the relevant option is rust-analyzer.diagnostics.disabled = ["inactive-code"].

For future solution seekers, the complete solution was

return {
	{
		"mrcjkb/rustaceanvim",
		opts = {
			server = {
				default_settings = {
					["rust-analyzer"] = {
						diagnostics = {
							disabled = { "inactive-code" },
						},
					},
				},
			},
		},
	},
}

Note the nest level server and rust-analyzer uses a hyphen -, not an underscore _. Also, Using LazyVim, you can easily stick a file .lazy.lua in the root (i.e. where you call nvim in the terminal) for project-local configuration.