Skip to main content

Module recovery

Module recovery 

Source
Expand description

Error-recovering parser for LSP / IDE partial parsing. Gated by the recovery feature. Error-recovering YAML parser for LSP / IDE partial parsing.

The default from_str family returns Err at the first syntax violation. Language Server Protocol implementations need the opposite contract: keep going past errors, build a best-effort partial tree, and collect every error encountered so the editor can show a complete diagnostics list and offer autocomplete on the recoverable subtrees.

parse_lenient is that contract:

  • Top-level --- document boundaries are scanned first; each document is parsed independently so one broken document never prevents the others from being recovered.
  • Within a single document, if the strict pass fails, the recoverer retries with DuplicateKeyPolicy::Last — the most common LSP-time error mode (a user typing a new key while an old one is still on screen). Successful recovery yields the post-retry value plus the original error in the error list, so the editor still flags the duplicate.
  • If that retry also fails, the recoverer performs line truncation recovery: drop trailing lines one by one and re-parse until either a parse succeeds or the input is exhausted. The successful prefix becomes the recovered value; everything past the truncation point is summarised as a synthetic Value::Null.
  • A configurable error cap (LenientConfig::max_errors) stops further recovery once enough diagnostics have been collected — useful when the document is so malformed that every line errors.

Gated behind the recovery Cargo feature.

§Output shape

For multi-document input the result’s ParseResult::value is a Value::Sequence of per-document values (recovered or Null) — this matches what an LSP would walk to label per-document diagnostics. For single-document input the result’s value is the recovered document directly (not wrapped in a sequence).

§Example

let yaml = "a: 1\nb: [unclosed\nc: 3\n";
let result = noyalib::recovery::parse_lenient(yaml);
assert!(!result.is_complete);
assert!(!result.errors.is_empty());
// `value` is the best-effort tree the recoverer salvaged.

Structs§

LenientConfig
Knobs for the recovery passes.
ParseResult
Result of an error-recovering parse pass.

Functions§

parse_lenient
Parse input with full error recovery.
parse_lenient_with
Parse input with caller-supplied recovery knobs.