Skip to content

Commit 11dff61

Browse files
Use simple syntax node for mutable query captures (#1732)
Fixes #1725 ## Checklist - [/] I have added [tests](https://www.cursorless.org/docs/contributing/test-case-recorder/) - [/] I have updated the [docs](https://github.com/cursorless-dev/cursorless/tree/main/docs) and [cheatsheet](https://github.com/cursorless-dev/cursorless/tree/main/cursorless-talon/src/cheatsheet) - [/] I have not broken the cheatsheet
1 parent 128829a commit 11dff61

File tree

1 file changed

+17
-5
lines changed

1 file changed

+17
-5
lines changed

packages/cursorless-engine/src/languages/TreeSitterQuery/QueryCapture.ts

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,19 @@
11
import { Range } from "@cursorless/common";
2-
import { SyntaxNode } from "web-tree-sitter";
2+
import { Point } from "web-tree-sitter";
3+
4+
/**
5+
* Simple representation of the tree sitter syntax node. Used by
6+
* {@link MutableQueryCapture} to avoid using range/text and other mutable
7+
* parameters directly from the node.
8+
*/
9+
export interface SimpleSyntaxNode {
10+
readonly id: number;
11+
readonly type: string;
12+
readonly startPosition: Point;
13+
readonly endPosition: Point;
14+
readonly parent: SimpleSyntaxNode | null;
15+
readonly children: Array<SimpleSyntaxNode>;
16+
}
317

418
/**
519
* A capture of a query pattern against a syntax tree. Often corresponds to a
@@ -39,11 +53,9 @@ export interface QueryMatch {
3953
*/
4054
export interface MutableQueryCapture extends QueryCapture {
4155
/**
42-
* The tree-sitter node that was captured. Note that the range may have already
43-
* been altered by a prior operator, so please use {@link range} instead of
44-
* trying to retrieve the range from the node.
56+
* The tree-sitter node that was captured.
4557
*/
46-
readonly node: SyntaxNode;
58+
readonly node: Omit<SimpleSyntaxNode, "startPosition" | "endPosition">;
4759

4860
range: Range;
4961
allowMultiple: boolean;

0 commit comments

Comments
 (0)