0019: Static Cargo discovery, one rust-analyzer per Cargo workspace, artifacts from Cargo
- Status: Proposed (implemented in Phase 2, task 012)
- Date: 2026-12-05
Context
Rust is the first language to get the full slice: projects, toolchain status, tasks with structured results, semantic features and a debug launch plan. Each piece can run project code if done carelessly. cargo metadata resolves dependencies, may touch the network and may rewrite Cargo.lock. A language server rooted at the wrong folder gives wrong answers, and one rooted per file wastes memory. A debugger pointed at a guessed target/debug/<name> path can start the wrong program.
Decision
- Discovery is static. The Rust project provider reads
Cargo.tomlfiles (at most 256 KiB each) from the bounded workspace snapshot. It groups packages into Cargo workspaces usingmembersandexclude(*matches one path component), and names targets from[lib],[[bin]],[[test]],[[example]]and Cargo's conventional files (src/lib.rs,src/main.rs,src/bin,tests,examples), honouringautobins,autotestsandautoexamples.cargo metadatais not run. - One project per Cargo workspace. A standalone package is a workspace of one. Members are the project's targets, each tagged with its package.
- Language servers are rooted per project. A document's server root is the deepest discovered project of its language that contains it, else the workspace root. Documents wait for discovery before attaching, so they never start a second server for the same root. Lazy start is unchanged: a server starts when the first document of its language opens.
- Cargo tasks are typed argv.
cargo build|check|test --message-format=json,cargo run -p <pkg> --bin <bin>,cargo test -p <pkg> --test <test>andcargo fetch. Tasks setRUSTUP_AUTO_INSTALL=0, so arust-toolchain.tomlthat names a missing toolchain fails with guidance instead of downloading it. - Results come from Cargo's JSON and libtest's lines. Compiler messages become problems;
compiler-artifactmessages give executable paths;test … ok|FAILED|ignoredlines and the failure report give test outcomes with locations. - Debugging uses only reported artifacts.
Ide::debug_launch_plantakes an executable from a run's artifact list. The Rust debug provider checks that it exists and looks for a user-installedlldb-dap(orlldb-vscode) onPATH. The adapter protocol is implemented in task 015.
Alternatives considered
cargo metadata --no-deps. Exact, including target names from build scripts and renamed packages. It still runs Cargo, which reads config, may runrustupand needs trust. It stays an option for trusted, explicitly requested refresh. Static discovery is the default because it works before trust is given.- One rust-analyzer per workspace folder. The previous behaviour. It is correct only when the folder is the Cargo workspace root. Nested or side-by-side Cargo workspaces got no analysis.
- Guess
target/debug/<bin>. Wrong withCARGO_TARGET_DIR, custom profiles, cross targets or Windows suffixes. Rejected.
Consequences
- Targets that only
cargo metadataknows (generated by build scripts, or from[package] autobinsedge cases in old editions) are missed. Glob patterns other than*inmembersare not matched. - Opening a Rust file in a workspace that has not been scanned starts discovery first, which delays the server by the scan time (milliseconds for typical folders).
- Provider contract version 2 is now used by the bundled Rust extension.