Expand description
Tree-sitter-based YAML locator.
Given the source bytes of a workload YAML and a target
key path (e.g. ["scenarios", "test_oracles", "report", "cli_added"]), find the byte range of:
- the value of the deepest existing key in the path, for replacement-style edits, OR
- the insertion point for a missing key, for add-style edits, with the indentation level the new block must adopt.
The CST preserves comments and whitespace as first-class
nodes, so the byte ranges we return point at YAML data
exclusively — the splicer can do
original[..start] + emitted + original[end..] and
every comment / blank line outside the range survives.
§Why not just walk a serde tree?
serde_yaml discards comments + most whitespace and
re-emits content with its own formatter. Round-trips are
lossy. Tree-sitter’s CST keeps every token in a node
with start/end byte offsets — which is the exact tool
for “find this subtree’s bytes without serializing
anything we didn’t ask to change.”
Enums§
- Located
- Outcome of locating a path in the source.
Functions§
- locate_
path - Locate
pathin the parsed tree.pathis a sequence of mapping keys (the YAML form of a JSONPath); each segment names a child of the previous segment’s mapping. - parse
- Parse
sourcewith tree-sitter-yaml. Returns the parsed tree;sourcemust be kept alive alongside the tree because nodes hold byte offsets into it.