Skip to content

codemirror/incremental-parse-state-field

A StateField holding a Lezer syntax tree of the whole document, parsed again incrementally on every change.

Each change maps the previous parse’s TreeFragments through the changed ranges and hands them to the parser, which reuses every fragment the change did not touch. The parse is synchronous and runs to the end of the document, so it suits a grammar a plugin owns (a markup extension, a small DSL) rather than a full language on a large document, where @codemirror/language’s time-sliced parser is the better tool.

@lezer/common is in the module map Obsidian hands to plugins, so this costs a consuming plugin no bundle.

Interface Description
IncrementalParse The value of an incremental parse state field.
Function Description
createIncrementalParseStateField Creates a state field that parses the document with the given parser when the state is created, and parses it again incrementally on every document change, reusing the fragments the change left intact.