rust-analyzer failed to discover workspace in vscode

Viewed 10416

I'm starting to learn the Rust language and I have an issue with rust-analyzer vscode extension.

This picture doesn't provide me with any additional info about root of the problem. I tried to find articles related to my error, but failed. Please help!

UPD1.

Screenshot of directory:

enter image description here

Screenshot of Cargo.toml contents:

enter image description here

guessing_game directory was created with cargo new guessing_game command

2 Answers

I guess you don't have a Cargo.toml file in your project? The rust-analyzer needs a Cargo.toml to detect the workspace.

You could create a new rust project with cargo:

cargo new your-project

cargo will help you create a Cargo.toml file automatically, or you could manually create a Cargo.toml for your existing project.

If this issue keep popping up, perhaps you could check this Github issue for help.

Edit:

You should open your project like this, instead of opening the parent directory of guessing_game. Just try the following steps:

  1. cargo new guessing_game_v2;
  2. then in VSCode, Choose "File" -> "Open Folder.." -> Choose the new guessing_game_v2 folder
  3. and check if it works?

enter image description here

You should make sure that your Cargo.toml is in the root of workspace.

Sorry if this is going to sound vague, but it is only because it happened quickly. I was looking at the bottom pane of vscode.

And think because I have Prettier as well, a dialog popped up saying it doesn't support .rs, Anyway I am not sure how what happened next happened, but the command-palette popped open and it prompted:

me make this file type the default for rust-analyzer

and then boom rustfmt started working.

So then I said hmmm, let's check settings.json

And to my glee I found this...

 "[rust]": {
    "editor.defaultFormatter": "rust-lang.rust-analyzer"
  }

Really hopes this helps anyone trying to become a rustacean!

Related