Skip to main content

Module parser

Module parser 

Source
Expand description

Manifest parsers for .csproj/.fsproj/.vbproj, Directory.Packages.props, and packages.config, with byte-accurate LSP position tracking.

§Attribute byte spans

NuGet carries its values in XML attributes (Include="...", Version="..."), and quick-xml’s Attribute exposes no span API. This module uses the borrowed-slice offset instead of a text scan: Reader::from_str(content) + reader.read_event() (mirroring deps-maven’s reader setup exactly, crates/deps-maven/src/parser.rs:51,62) yields Event<'a> borrowed from content itself, so an attribute’s raw Cow<'a, str> value is Cow::Borrowed pointing directly into content’s bytes. The byte offset is then simple pointer arithmetic:

let offset = value.as_ptr() as usize - content.as_ptr() as usize;

This is O(1) and immune to the false-match a text scan would hit on an MSBuild Condition attribute whose value happens to contain the literal text Version=" (see test_condition_attribute_with_literal_version_text below). Switching the reader to Reader::from_reader + read_event_into(&mut buf) would make attributes borrow from the scratch buffer instead of content, silently breaking this arithmetic — it would compile and produce garbage ranges. test_attribute_byte_range_matches_source_bytes guards against that regression.

Functions§

parse_directory_packages_props
Parses a Directory.Packages.props central package management file, extracting PackageVersion entries.
parse_packages_config
Parses a legacy packages.config file, extracting package entries.
parse_project_file
Parses a .csproj/.fsproj/.vbproj MSBuild project file, extracting PackageReference entries.