TokenizedDocument class final

A document whose lines stay tokenized as its text changes.

update finds the unchanged lines at the start and end of the new text and re-tokenizes the lines between them, stopping once the tokenizer state matches the state cached for an old line. Typing in a large file therefore re-tokenizes a few lines. An edit that changes how the rest is read, such as opening a block comment, re-tokenizes up to the end of the affected region.

With a time budget, update stops when the budget is spent and tokenize continues later, so a large text can be tokenized a slice at a time without blocking a UI thread. lines grows from the top as it goes.

Unchanged lines keep their DocumentLine objects across updates, so a renderer can cache its own output per line.

final document = TokenizedDocument(highlighter.grammar('dart'));
document.update(source);
final ranges = document.ranges(githubDarkTheme);

Constructors

TokenizedDocument(Grammar _grammar)
An empty document for grammar. Call update with its text.

Properties

grammar ↔ Grammar
The grammar lines are tokenized with. Setting a different grammar drops every cached line, since states from another grammar can't be reused.
getter/setter pair
hashCode → int
The hash code for this object.
no setterinherited
isComplete → bool
Whether every line of the text last passed to update is tokenized.
no setter
lines → List<DocumentLine>
The tokenized lines of the text last passed to update, split on \n: all of them once isComplete, otherwise the first ones.
no setter
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited

Methods

noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
ranges(SyntaxTheme theme) → List<StyledRange>
Every token of the document as a StyledRange under theme.
tokenize({Duration? budget}) → bool
Continues an update that ran out of budget, for at most budget, and returns isComplete.
toString() → String
A string representation of this object.
inherited
update(String text, {Duration? budget}) → bool
Brings lines up to date with text, and returns isComplete.

Operators

operator ==(Object other) → bool
The equality operator.
inherited