Repository navigation
Expand file tree
/
Copy pathQueryCapture.ts
More file actions
68 lines (58 loc) · 2.02 KB
/
Copy pathQueryCapture.ts
File metadata and controls
68 lines (58 loc) · 2.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
import type { Range, TextDocument } from "@cursorless/common";
import type { Node } from "web-tree-sitter";
/**
* A capture of a query pattern against a syntax tree. Often corresponds to a
* node within the syntax tree, but can also be a range within a node or be modified
* by query predicate operators.
*/
export interface QueryCapture {
/**
* The name of the capture. Eg for a capture labeled `@foo`, the name is
* `foo`.
*/
readonly name: string;
/** The range of the capture. */
readonly range: Range;
/** Whether it is ok for the same capture to appear multiple times with the
* same domain. If set to `true`, then the scope handler should merge all
* captures with the same name and domain into a single scope with multiple
* content ranges. */
readonly allowMultiple: boolean;
/** The insertion delimiter to use if any */
readonly insertionDelimiter: string | undefined;
/** Returns true if this node or any of its ancestors has errors */
hasError(): boolean;
}
/**
* A match of a query pattern against a syntax tree.
*/
export interface QueryMatch {
/**
* The captures of the pattern that was matched.
*/
readonly captures: QueryCapture[];
}
/**
* A capture of a query pattern against a syntax tree. This type is used
* internally by the query engine to allow predicates to modify the capture.
*/
export interface MutableQueryCapture extends QueryCapture {
/**
* The tree-sitter node that was captured.
* This may be undefined if the range has been modified by a query predicate.
*/
node: Node | undefined;
readonly document: TextDocument;
range: Range;
allowMultiple: boolean;
insertionDelimiter: string | undefined;
}
/**
* A match of a query pattern against a syntax tree that can be mutated. This
* type is used internally by the query engine to allow predicates to modify the
* match.
*/
export interface MutableQueryMatch extends QueryMatch {
readonly captures: MutableQueryCapture[];
}
export type PatternPredicate = (match: MutableQueryMatch) => boolean;