parseUtf8BytesWithOptions method

TreeSitterTree? parseUtf8BytesWithOptions(
  1. Uint8List bytes,
  2. TreeSitterParseOptions options, {
  3. TreeSitterTree? oldTree,
  4. Iterable<TreeSitterInputEdit> edits = const [],
  5. bool annotateLocals = true,
})

Byte-native counterpart of parseWithOptions.

This preserves malformed UTF-8 and all physical byte offsets while exposing Tree-sitter's opt-in progress/cancellation callback. Editor typing does not use this API; normal worker parses remain uninterrupted.

Implementation

TreeSitterTree? parseUtf8BytesWithOptions(
  Uint8List bytes,
  TreeSitterParseOptions options, {
  TreeSitterTree? oldTree,
  Iterable<TreeSitterInputEdit> edits = const [],
  bool annotateLocals = true,
}) {
  final hooks = TreeSitterParserRuntimeHooks(
    cancellationToken: _cancellationToken,
    timeout: _timeout,
    logger: _logger,
    debugGraphSink: _debugGraphSink,
    parseOptions: options,
    internalTrace: runtimeHooks?.internalTrace,
  );
  try {
    final result = _parseSource(
      utf8.decode(bytes, allowMalformed: true),
      Uint8List.fromList(bytes),
      oldTree: oldTree,
      edits: edits,
      annotateLocals: annotateLocals,
      runtimeHooksOverride: hooks,
    );
    _hasOutstandingParse = false;
    return result;
  } on GeneratedTreeSitterParseHalted {
    _hasOutstandingParse = true;
    return null;
  }
}