edit method
Applies native Tree-sitter's endpoint transform to included ranges.
Implementation
void edit(TreeSitterInputEdit edit) {
_checkNotDisposed();
// Materialize the lazy public tree before mutating node handles. This is
// required because an edit applies to every node that can subsequently be
// reached from this tree, including nodes the caller has not visited yet.
final nodes = rootNode.walk().toList(growable: false);
for (final node in nodes) {
node.edit(edit);
}
// The generated runtime always stores UTF-8 coordinates. Translate a
// self-contained UTF-16 edit before applying it to that reuse tree. If a
// caller supplies only native TSInputEdit fields for inserted UTF-16 text,
// its UTF-8 width is unknowable until the replacement source arrives; in
// that case retain the original generated tree so the next parse can
// derive one exact UTF-8 replacement from the old and new sources.
if (_inputEncoding == TreeSitterInputEncoding.utf8) {
_comparisonGeneratedTree = _comparisonGeneratedTree?.edit(edit);
} else if (_inputEncoding == TreeSitterInputEncoding.utf16LittleEndian ||
_inputEncoding == TreeSitterInputEncoding.utf16BigEndian) {
_editUtf16ComparisonTree(edit);
} else {
_comparisonGeneratedTree = generatedTree;
_comparisonSource = source;
_comparisonEncodingEditsExact = false;
}
_includedRanges = List.unmodifiable([
for (final range in _includedRanges)
TreeSitterRange(
startByte: _editedByte(range.startByte, edit),
endByte: _editedByte(range.endByte, edit),
startPoint: _editedPoint(range.startPoint, edit),
endPoint: _editedPoint(range.endPoint, edit),
),
]);
}