Reproducing a rust-analyzer failure in the terminal

I'm using rust-analyzer via neovim's coc. When I start editing a project's files it fails with an error "Failed to read Cargo metadata ..." but the error message disappears after a while. From what I can read before it disappears, it's talking about a feature that is missing in Cargo.toml, but the feature was removed a long time ago, and there are no references to that feature in the code base now.

The same error is also generated when I run rust-analyzer.reloadWorkspace command.

I'd like to reproduce this error in the terminal now so that I can either debug it or report it as a bug, but not sure how. rust-analyzer analysis-stats . generates dozens of Rust panics and does not generate the error I'm trying to fix.

How do I replicate an error in rust-analyzer.reloadWorkspace command in the terminal?

Just cargo metadata is what we are doing. You might want to also check the rust-analyzer log in neovim: we should be logging the info.

I’d also like to take a look at the panics you are seeing! Is the code you are working on public?

cargo metadata works fine. Is rust-analyzer using its own cargo library, or the cargo installed system-wide?

When I look at the neovim language server logs I see the full error is like this:

[ERROR rust_analyzer::reload] failed to switch workspaces: rust-analyzer failed to load workspace: Failed to read Cargo metadata from Cargo.toml file <snip>, cargo 1.54.0 (5ae8d74b3 2021-06-22): Failed to run `cargo metadata --manifest-path <snip>`: `cargo metadata` exited with an error: error: Package `<snip>` does not have the feature `<feature>`

Interestingly the word <feature> does not occur anywhere in the code base (checked with ag <feature>). I have no idea where rust-analyzer/cargo seeing it. I'm guessing rust-analyzer and/or cargo has some cache somewhere that I need to invalidate? <feature> also does not appear in cargo metadata output.

OK, figured it out. ag <feature> does not find anything because it ignores files specified in .gitignore. If I search in all files I see that I have a .vim/coc-settings.json file with an old feature. After updating it everything works fine.

The core problem here is that LSP doesn't have a nice way to display verbose error message for the cases when config is broken, added this to the relevant issue: Discussion: LSP-server readiness indicator · Issue #511 · microsoft/language-server-protocol · GitHub

1 Like

BTW, still curious about those panics :slight_smile:

~ $ rust-analyzer --version
rust-analyzer 85d80df88 2021-08-06 dev

rust-analyzer analysis-stats . stderr:

1 Like

Actually, I now realize that in VS Code we actually do show message in a somewhat readable form:

Might be worth it to open an issue on the coc-rust-anlyzer repo about displaying this better -- the idea is that the message is persistant status, not a one-time error message.

I'm having the same problem with VSCode. I have two projects, only one of which uses a number of features. I get the missing feature error in the other project. My workaround is to just list those features in the second project's Cargo.toml, but I'd really like to know what's going on.

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.