rust-analyzer failed to load workspace
Using Visual Studio Code Insiders, version:
Version: 1.42.0-insider
Commit: 536757fcc0308b444cbe9ce04f1f013903641ae3
Date: 2020-02-05T16:51:11.916Z
Electron: 6.1.6
Chrome: 76.0.3809.146
Node.js: 12.4.0
V8: 7.6.303.31-electron.0
OS: Linux x64 5.5.2-arch1-1
I have no other extensions installed but rust-analyzer.
I installed rust-analyzer following docs/user/README.md, but when opening any folder or adding it to workspace, it fails with the following error:
rust-analyzer failed to load workspace: No such file or directory (os error 2)
and with information:
workspace loaded, 0 rust packages
This happens with extension and ra_lsp_server build from master and when downloaded from Github releases.
There's no messages in output.
Rust Analyzer: Status shows:
no workspaces
analysis:
2 (8kb) files
0 (0b) symbols
1 trees, 1 retained
0 trees, 0 retained (macros)
memory:
0b allocated 0b resident
gc 110 seconds ago
requests:
* 1 textDocument/codeAction 5ms
2 rust-analyzer/inlayHints 1ms
4 textDocument/documentSymbol 3ms
3 rust-analyzer/decorationsRequest 6ms
5 textDocument/codeLens 3ms
6 textDocument/hover 0ms
7 codeLens/resolve 0ms
8 textDocument/hover 0ms
9 textDocument/codeAction 0ms
11 rust-analyzer/inlayHints 1ms
I also tried to use latest stable Visual Studio Code, but with no result there either.
I'm using fish-shell, this is my $PATH:
/home/kyu/bin /home/kyu/sys/bin /home/kyu/sys/local/bin /usr/local/sbin
/usr/local/bin /usr/bin /usr/bin/site_perl /usr/bin/vendor_perl /usr/bin/core_perl
ra_lsp_server is located in /home/kyu/sys/local/bin
(Please, don't ask why do I have such a weird folder structutre. I'm ashamed of it myself enough.)
Is your crate in a subfolder of the workspace?
No, it's either the only folder in the workspace or when I just open folder.
This is what happens:

What does the error message say after No such file or directory? (You can click on the ^ that shows when you hover over it to reveal the rest.)
It shows rust-analyzer failed to load workspace: No such file or directory (os error 2).
Saving workspace also doesn’t change anything, it still fails.
One guess: do you have the rust-src rustup component installed?
Yes, I have:
cargo-x86_64-unknown-linux-gnu
clippy-x86_64-unknown-linux-gnu
rls-x86_64-unknown-linux-gnu
rust-analysis-x86_64-unknown-linux-gnu
rust-docs-x86_64-unknown-linux-gnu
rust-src
rust-std-x86_64-unknown-linux-gnu
rustc-x86_64-unknown-linux-gnu
rustc-dev-x86_64-unknown-linux-gnu
rustfmt-x86_64-unknown-linux-gnu
I still didn't have resolved the problem, but it seems like no one cares about this issue anymore.
@aodhneine I would advise against leaving comments like "no one cares about this issue anymore". Most people who work on rust-analyzer care a lot about it working great, but at the same time the amount of effort one needs to put in to make this happen far outweighs the available resources.
This in general applies to all open source and closed source projects: inferring that the issue does not get "enough" attention due to the lack of care is not really right (most time the issue is available time) and not really helpful (as it, to put it bluntly, makes the maintainers feel bad).
Regardless of this, thank you for the bug report :heart: ! It is helpful.
Thank you for the response! I was really tired and frustrated after three days of no one responding, but I think that letting my frustration out here was inappropiate, and I'm sorry for that.
Nevertheless, I hope that this bug report will help to improve such an awesome project (I used to use it few months ago without issues) and that it'll be resolved quickly. Feel free to ask if there's something I can help with.
I wish we could reproduce your bug, otherwise we have no ideas of what file is missing. I tried looking over the code and indeed missing sysroot was my only supposition. I wish we could have all of your pc on our side ...
I think I resolved the issue. But I have no idea what happened or how I solved it. I cannot reproduce the bug anymore on my computer.
I just reinstalled the rust one more time using rustup-init.sh and for some reason everything worked correctly.
I think the issue might be with how I store programs on my computer.
Basically, every program that I install from source or from binary package (like rust) I keep in separate directory and just symlink various files to the places they're expected to be - so in this case I kept ~/.cargo and ~/.rustup as symlinks to ~/sys/local/share/cargo and ~/sys/local/share/rustup.
And usually this works fine, I have home directory clean of folders and structure I can easily naviagate through and manage.
However it seems like this time something went wrong, and probably rustup was keeping location of installed components incorrectly. (But I have no idea how rustup works)
When I reinstalled rust, I first installed all required components and launched vscode, which (expectedly) was working fine. Then I moved the .cargo and .rustup into the folders mentioned above, but this didn't break anything.
So... I still have no clue what happened.
I will try to recreate the issue when I will have access to the computer.
I cannot reproduce the issue anymore, even when doing the same exact steps I did when installed rust and this bug occured. It seems to be a heisenbug, should I close this issue then, or does it still make any sense to investigate it?
I think it might make sense to close. I've opened https://github.com/rust-analyzer/rust-analyzer/issues/3085 to make sure that the next time we have a better error message to work with.
Okay, thanks everyone for spending your time trying to fix this. :heart:
@aodhneine , thank you for the report, we do value all of them, I hope we will tackle your bug once we are done with better error logging!
For reference, I received the same error when I tried running vscode with rust 1.22.0, running vscode again with the stable(1.45) fixed it.
@sanket1729 I recommend you to open Output > Rust Analyzer Client and if present Output > Rust Analyzer Language Server (without Trace) and send these logs to us next time you see something weird.
And turning this on should also help us:
{
"rust-analyzer.trace.extension": true
}
I have a similar error:
[ERROR rust_analyzer::reload] failed to switch workspaces: rust-analyzer failed to load workspace: "cargo" "--version" failed: No such file or directory (os error 2)
I am working inside a dev container, and cargo is installed under "$HOME/.cargo" also present in $PATH.+ I attached the Output of Rust Analyzer Client as well. Rust Analyzer Client Output.txt