Skip to main content

resolve_workspace_root

Function resolve_workspace_root 

Source
pub fn resolve_workspace_root(start_dir: &Path, markers: &[String]) -> PathBuf
Expand description

Walk up from start_dir looking for any of markers. Returns the resolved workspace root, applying language-specific “outermost wins” semantics where appropriate. Falls back to start_dir when no marker matches – the LSP spec allows passing the buffer’s directory as a degenerate workspace.

Cargo-workspace awareness. Rust’s Cargo allows nested Cargo.toml files (member crate’s [package]-only Cargo.toml inside the workspace’s [workspace] Cargo.toml). rust-analyzer must be anchored at the workspace root for cross-crate goto-definition + external-dependency indexing to work. This resolver therefore walks the entire ancestor chain when Cargo.toml is among the markers and prefers the outermost Cargo.toml that declares [workspace]. For all other markers (and for standalone-crate Rust projects with no enclosing workspace) the nearest match still wins – the historical behaviour and what every other language wants.