-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
"rust-analyzer failed to discover workspace" could be so much more helpful #13226
Comments
On this line of thought - I had some prototype work that added logic to search for all Also related to #9661 |
@matklad Did something in the extension change recently that now prevents it from auto-discovering projects that aren't at the root of the vscode workspace? I could've sworn it was working fine before the last week or two. But now I see the "failed to discover workspace" message every time I open vscode (with my Rust project is two levels down). I'm on the latest insiders release, with the extension set to the pre-release channel. |
We only auto-discover Rust projects one-level deep. |
@matklad Interesting -- thanks! |
Could we change this to a configurable depth? |
Yes, please. Something like the recently implemented Most often, my vscode workspace is a collection of clones, with several of the nested clones being Rust projects. Previously with RLS (before switching to rust-analyzer), all the nested Rust projects would automatically be "discovered", and I'd have access to all the RLS tools any time a Rust file was opened. Now with RA, I have no features available in my opened Rust files. Unfortunately, all my workspaces are different/dynamic, so keeping track of them all as |
For activating the extension, I don't think so. It isn't possible to change the activationEvents of an extension: rust-analyzer/editors/code/package.json Line 63 in 61504c8
rust-analyzer/crates/project-model/src/lib.rs Lines 122 to 131 in 61504c8
|
Is there a way to manually resolve this? I have my workspace Cargo.toml a few directories deep in my project. I've scanned the extension settings and can't find a place to manually point rust-analyzer to a Cargo.toml. It seems my only option is to open the subfolder as the root of my VSCode project when I'm working in the Rust portion of it, and switch back to a VSCode window that's at the actual root of my repository for the rest. I've confirmed this works, but it's certainly not ideal. |
That was it! Thank you @matklad |
I was struggling with strange behaviours from rust-analyzer (sometimes working, others not) for some days, and only now found out this issue of rust projects only being automatically detected on one-level-deep directories. I think this should be more clear, at least with an error message when no projects are being discovered. But ideally it would probably be useful to allow automatically detecting projects more levels deep by defaulf. If the workspace of the user is too cluttered, he can always exclude folders (such as target etc) from the workspace, or set the depth-level of automatic discovery manually, or set the linkedProjects variable, for example. |
I had a similar situation where I had multiple projects in subdirectories that each had their own Cargo.toml file. I got overcame the error |
Being able co configure the depth of auto-discovery would be so very helpful. Having to configure my VS Code to include specific directories for all my projects sounds like tedium. That would be a lot of unnecessary manual setting maintenance. |
Currently, rust-analyzer highlights the entire region when a `cfg` is inactive (e.g. `#[cfg(windows)]` on a Linux machine). However, unlinked files only highlight the first three characters of the file. This was introduced in rust-lang#8444, but users have repeatedly found themselves with no rust-analyzer support for a file and unsure why (see e.g. rust-lang#13226 and the intentionally prominent pop-up added in PR rust-lang#14366). (Anecdotally, we see this issue bite our users regularly, particularly people new to Rust.) Instead, highlight the entire inactive file, but mark it as all as unused. This allows users to hover and run the quickfix from any line. Whilst this is marginally more prominent, it's less invasive than a pop-up, and users do want to know why they're getting no rust-analyzer support in certain files.
fix: Highlight unlinked files consistently with inactive files Currently, rust-analyzer highlights the entire region when a `cfg` is inactive (e.g. `#[cfg(windows)]` on a Linux machine). However, unlinked files only highlight the first three characters of the file. This was introduced in #8444, but users have repeatedly found themselves with no rust-analyzer support for a file and unsure why (see e.g. #13226 and the intentionally prominent pop-up added in PR #14366). (Anecdotally, we see this issue bite our users regularly, particularly people new to Rust.) Instead, highlight the entire inactive file, but mark it as all as unused. This allows users to hover and run the quickfix from any line. Whilst this is marginally more prominent, it's less invasive than a pop-up, and users do want to know why they're getting no rust-analyzer support in certain files. Before (note the subtle grey underline is only at the beginning of the first line): ![Screenshot 2024-06-05 at 5 41 17 PM](https://github.com/rust-lang/rust-analyzer/assets/70800/96f5d778-612e-4838-876d-35d9647fe2aa) After (user can hover and fix from any line): ![Screenshot 2024-06-05 at 5 42 13 PM](https://github.com/rust-lang/rust-analyzer/assets/70800/6af90b79-018c-42b9-b3c5-f497de2ccbff)
Just wanted to thank you, alfredotasty !!!! |
I think this needs a better solution unfortunately. vscode, zed, nvim all needs it's own solutions due to the lack of a rust analyzer becoming able to pick this up in a IDE agnostic way. Would be great if rust analyzer is able to add a section into one of Unfortunately, there is no good way to work with large repos, esp. on mono-repos since each editor will require it's own way to tell the LSP about it's projects. |
#17537 will help a bit, even if it doesn't solve all issues. |
Today I've got to help a new Rust user to start their Rust project, and our logic to discovering Cargo.tomls was a huge roadblock. Comically gigantic I would say even :)
Basically, the project was in the subdir of the subdir, so nothing worked. But I wasn't able to diagnose on the spot! I had to do the "ok, let's create a new hello-world project and see if it works there" dance to debug this (and it was actually the person whom I was trying to help who said "huh, maybe the problem is that Cargo.toml is in a subdirectory?")
Here's a bunch of ways we can improve this:
The text was updated successfully, but these errors were encountered: