VSCode, Tauri, rust-analyzer: could not find Cargo.toml

Hi all, ignored this for a while, but now I would like to get rid of this:

I am doing a Tauri App with VSCode and rust-analyzer installed. Tauri installs the Rust code into a subdirectory of the workspace called src-tauri. rust-analyzer seems not to be searching in the subfolder.

I did already a little bit research and the solution seemed to be to place a file called 'settings.json' in my '.vscode' folder of the workspace folder. This looks for me like this:

    "rust-analyzer.linkedProjects": ["src-tauri/Cargo.toml",]

But I still get this error:

[ERROR flycheck] Flycheck failed to run the following command: "cargo" "check" "--workspace" "--message-format=json" "--all-targets"
[ERROR rust_analyzer::lsp_utils] cargo check failed

Cargo watcher failed, the command produced no valid metadata (exit code: ExitStatus(ExitStatus(101))):
error: could not find `Cargo.toml` in `c:\source\Rust\test-tauri-1.1` or any parent directory

Any idea what I am doing wrong?

This is a bug in rust-analyzer that should be fixed in the latest pre-release.

1 Like

You should be able to add a workspace Cargo.toml to your project's root directory which includes src-tauri as a member.

As a complete tangent - I've always found the default layout for Tauri apps really annoying. Normally, you'd want to have your app's frontend and backend in separate folders with useful names like frontend and backend. Nesting the backend inside the frontend folder and calling it src isn't terribly helpful, especially because the whole thing is a Tauri app and not just the backend.

1 Like

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.