hasContentChangesFor method

bool hasContentChangesFor(
  1. GeneratedTreeSitterNode node
)

Whether an edit touched bytes inside the node's visible source extent.

Native changed-range comparison distinguishes a token that was shifted by trivia inserted at its leading boundary from a token whose text was edited. Both can carry has_changes for reuse/lookahead purposes, but only the latter represents a structural changed range.

Implementation

bool hasContentChangesFor(GeneratedTreeSitterNode node) {
  if (node.hasChanges) return true;
  var startByte = node.startByte;
  var endByte = node.endByte;
  for (final edit in appliedEdits) {
    final isInsertion = edit.startByte == edit.oldEndByte;
    final intersectsContent = isInsertion
        ? edit.startByte > startByte && edit.startByte < endByte
        : edit.startByte < endByte && edit.oldEndByte > startByte;
    if (intersectsContent) return true;
    startByte = _transformByte(startByte, edit, affinityAfter: true);
    endByte = _transformByte(endByte, edit, affinityAfter: false);
  }
  return false;
}