Hi!
I noticed that rust-analyzer features (such as code completion or highlighting code issues ) doesn't work anymore in my VSCode. Rust-analyzer briefly and intermittently worked at the first VSCode installation but since then, no matter what I tried, it doesn't do anything although it doesn't report a crashing error, either.
I use Ubuntu 22 and VScode 1.91.0.
I tried to clean remove and reinstall VSCode + rust-analyzer and I tried cargo clean.
It recognizes Cargo.toml files in the current directory.
You can go to rust-analyzer, edit setting.json. Check if the Cargo.toml file is in this place:
You should likely set this one in the workspace config, rather than the user config. The workspace config can be found at .vscode/settings.json inside the root of the project you are working on. If it doesn't exist yet you can create it.
@bjorn3 So my code is organized in subfolders within a 'parent' directory named RUST. In the parent dir I found a folder .vscode containing only one file: "launch.json". I created here the settings.json file. In my project directory there was no .vscode dir so I created one along with the settings.json file where I put: " ```
"rust-analyzer.linkedProjects": [
"Cargo.toml"
],
The problem persists. I was thinking that all there config files should be created automatically by the VSCode and rust-analyzer, not manually by the user?
You need to point to the Cargo.toml of each cargo workspace you want to work with. For example foo/Cargo.toml and bar/Cargo.toml if you want to work on fok and bar.
Thanks, also the absolute path is needed. Nevertheless it is strange that after I put only one path in linkedProjects, rust-anayzer works again for all projects. I was expecting that by default rust-analyzed should look for all Cargo.toml files from subdirectories
My understanding is that rust-analyzer's default behavior is to search at most one directory deep for Cargo.toml files, to avoid the potentially large cost of scanning the entire workspace file tree. I don't know why adding linkedProjects would change anything not explicitly listed, though.
Is it possible that the server crate depends on your other crates? All dependencies of a crate you mention in rust-analyzer.linkedProjects will be analyzed too and get ide functionality as a result.
There are small independent projects, not relying on each other. All of them are within a parent directory. I think I know what it happens, after I did a clean uninstall of VSCode. If the Cargo.toml of a project is not specified in the settings.json file it is not checked anymore (behavior changed after clean reinstall). If no project is registered, I get the error "failed to discover a workspace". My understanding is that when I open a parent folder in VSCode, the program should scan all its subfoders for Cargo.toml files. Apparently it is not doing this.