Skip to main content

Module recovery

Module recovery 

Source
Expand description

Error-recovering parser — parses valid statements even when some are broken.

Splits the source into statement chunks by scanning for ; tokens, then parses each chunk independently. Returns partial results (successful ASTs) alongside diagnostics for failed chunks.

This is essential for LSP — the document is always invalid while typing, but the LSP needs to provide completions/hover for the valid parts.

§Example

let (stmts, diags) = surql_parser::parse_with_recovery(
    "SELECT * FROM user; SELEC broken; DEFINE TABLE post SCHEMAFULL"
);
assert_eq!(stmts.len(), 2); // first and third succeeded
assert_eq!(diags.len(), 1); // second failed

Functions§

parse_with_recovery
Parse a SurrealQL document with error recovery.