Hey awesome people, I am very new to both programming and linux. I am using Ubuntu 22.0.4 on WSL2 to learn programming using VS Code connected via WSL remote. I created a rust project using "cargo new basic" inside q:/learn/rust. So, now I am working in "q:/learn/rust/basic" and of obviously there's a "src" directory inside the "basic" and "main.rs" is inside the "src." All the other files are in the correct directory, cargo.toml, cargo.lock, target directory, everything is in place. "cargo build" builds the file, same with run and check, everything works, except I have three problems.
- Gitignore is created but Git is not.(not much important, guess I need to install Git for that.)
- Somewhere in the output, I saw something in the terminal saying something like "main function is unused", but I guess that's the full hello world program and I think there's anything more to be done in it.(A bit important, as I need to know, even if we used the function to print hello world, it still says unused.
- Now this is the most important and I searched about this problem for almost 3 days and found nothing that solves my problem. The extension, rust-analyzer gives the following error:
[ERROR rust_analyzer::main_loop] FetchWorkspaceError:
rust-analyzer failed to discover workspace
[ERROR rust_analyzer::config] failed to load linked project: project root must point to Cargo.toml or rust-project.json: /mnt/q/Learn/Rust/basic/cargo.toml.
I'd be so grateful if Rustaceans would help me. I too hope to become a Rustacean someday, asap.
This usually means you need to open the
/mnt/q/Learn/Rust/basic/ folder up rather than something like
/mnt/q/. The way Rust Analyzer works is to look for a
Cargo.toml file at the top level of whatever folder VS Code was opened in.
Oh man, you didn't get the problem at all, that's just according to LINUX filesystem, it's inside "Q:/LEARN/RUST/BASIC" as per WINDOWS filesystem.
What I'm saying is to open the
Q:/LEARN/RUST/BASIC folder directly, not
From your screenshot, I can see that the
Cargo.toml is nested down 3 levels and isn't at the top level like in my screenshot.
File > Open > Select Q:\Learn\Rust\basic
Best solution, I uninstalled that shitty extension. I think I can do without it. I was even hallucinating the folders I already deleted.
By the way, where can I find "rust_project.json" file? Especially on WSL 2?
I don't know how to close this topic, but thank you all. I was finally able to solve it. Mostly because of your help and then with hours of fussing around on settings, uninstalling and reinstalling the VS Code, I finally figured it out. Here's my solution to anyone facing the same problem in the future.
- It was just a learning project, so I deleted the older project, exited any open directories in VS Code, deleted all my previous project folder(this is not recommended for real projects).
- I opened the directory where I wanted to create my project and created a new project using cargo command.
- Then I opened the project directory from VS Code with file menu.
- On settings, I made a reset to previous setting for rust-analyzer extension, and then I restarted the editor and it finally worked.
Thank you, rustaceans. You guys are awesome.