Expand description
Cargo.toml parser with position tracking.
Parses Cargo.toml files using toml_edit to preserve formatting and extract precise LSP positions for every dependency field. Critical for features like hover, completion, and inlay hints.
§Key Features
- Position-preserving parsing via toml_edit spans
- Handles all dependency formats: inline, table, workspace inheritance
- Extracts dependencies from all sections: dependencies, dev-dependencies, build-dependencies
- Converts byte offsets to LSP Position (line, UTF-16 character)
§Examples
use deps_cargo::parse_cargo_toml;
use tower_lsp_server::ls_types::Uri;
let toml = r#"
[dependencies]
serde = "1.0"
"#;
let url = Uri::from_file_path("/test/Cargo.toml").unwrap();
let result = parse_cargo_toml(toml, &url).unwrap();
assert_eq!(result.dependencies.len(), 1);
assert_eq!(result.dependencies[0].name, "serde");Structs§
- Cargo
Parser - Parser for Cargo.toml manifests implementing the deps-core traits.
- Parse
Result - Result of parsing a Cargo.toml file.
Functions§
- parse_
cargo_ toml - Parses a Cargo.toml file and extracts all dependencies with positions.