Search code examples
visual-studio-coderustrust-cargotaurirust-analyzer

Rust-Analyzer VSCode-Plugin with Tauri


When working on a Tauri project in VSCode, I get the following error message from the rust-analyzer plugin.

rust-analyzer failed to discover workspace

I know that the cause of the problem is that I loaded the Tauri project as my workspace in VSCode which does not have a Cargo.toml in its project root, but in the Rust-related sub-directory src-tauri. Is there a way I can tell the plugin that it should refer to this sub-directory src-tauri for the Cargo.toml? The workaround is to switch the workspace to src-tauri every time I touch the Rust code, which is quite inconvenient.


Solution

  • You can use the rust-analyzer.linkedProjects setting in VSCode. It takes a list of paths pointing to Cargo.toml files.

    Try adding this to your settings.json:

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