-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathapi.d.ts
164 lines (163 loc) · 6.1 KB
/
api.d.ts
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
import * as vscode from "vscode";
import TreeSitter, { Query, SyntaxNode, Tree } from "web-tree-sitter";
export { Query, type SyntaxNode, type Tree, TreeSitter };
/**
* A supported language.
*/
export declare enum Language {
C = "c",
Cpp = "cpp",
Go = "go",
Html = "html",
JavaScript = "javascript",
JavaScriptReact = "javascript",
Python = "python",
Rust = "rust",
TypeScript = "typescript",
TypeScriptReact = "tsx"
}
/**
* Ensures that Tree Sitter is loaded.
*/
export declare function ensureLoaded(): Promise<void>;
/**
* Ensures that the specified language is loaded.
*/
export declare function ensureLoaded(input: HasLanguage): Promise<void>;
/**
* Type from which a {@link Language} can be determined.
*/
export type HasLanguage = Language | string | vscode.Uri | vscode.TextDocument;
/**
* Returns the {@link Language} of the file at the given value if it can be
* reliably determined. Otherwise, returns `undefined`.
*/
export declare function determineLanguage(input: HasLanguage): Language | undefined;
/**
* Same as {@link determineLanguage()}, but throws an error on failure instead
* of returning `undefined`.
*/
export declare function determineLanguageOrFail(input: HasLanguage): Language;
/**
* A cache for trees returned by {@link documentTree()} and
* {@link documentTreeSync()}.
*/
export declare class Cache {
constructor();
}
/**
* Options given to {@link documentTree()} and {@link documentTreeSync()}.
*/
export interface DocumentTreeOptions {
/**
* The language to use; if unspecified, it will be determined using
* {@link determineLanguage()}.
*/
readonly language?: Language;
/**
* The cache used to resolve the tree, or `undefined` if no cache should be
* used.
*/
readonly cache?: Cache;
/**
* The timeout in milliseconds of the operation.
*/
readonly timeoutMs?: number;
}
/**
* Returns the document tree for the specified document,
* {@link ensureLoaded loading} the necessary code first if necessary.
*/
export declare function documentTree(document: vscode.TextDocument, options?: DocumentTreeOptions): Promise<Tree>;
/**
* Returns the document tree for the specified document, failing if the
* relevant language is not already {@link ensureLoaded loaded}.
*/
export declare function documentTreeSync(document: vscode.TextDocument, options?: DocumentTreeOptions): Tree;
/**
* Compiles the given string into a {@link Query} object which can be used to
* perform queries on nodes of the given language.
*
* @see {@link https://tree-sitter.github.io/tree-sitter/using-parsers#query-syntax}
*/
export declare function query(language: HasLanguage): (strings: TemplateStringsArray, ...args: any) => Promise<Query>;
export declare function query(language: HasLanguage, source: string): Promise<Query>;
/**
* Compiles the given string into a {@link Query} object which can be used to
* perform queries on nodes of the given language, failing if it is not already
* {@link ensureLoaded loaded}.
*/
export declare function querySync(language: HasLanguage): (strings: TemplateStringsArray, ...args: any) => Query;
export declare function querySync(language: HasLanguage, source: string): Query;
/**
* Executes the specified function with the result of {@link documentTree()},
* {@link Tree.delete() deleting} the tree after the end of the function.
*/
export declare const withDocumentTree: {
<T>(document: vscode.TextDocument, k: (tree: Tree) => T | PromiseLike<T>): Promise<T>;
<T_1>(document: vscode.TextDocument, options: DocumentTreeOptions | undefined, k: (tree: Tree) => T_1 | PromiseLike<T_1>): Promise<T_1>;
};
/**
* Executes the specified function with the result of {@link documentTreeSync()},
* {@link Tree.delete() deleting} the tree after the end of the function.
*/
export declare const withDocumentTreeSync: {
<T>(document: vscode.TextDocument, k: (tree: Tree) => T): T;
<T_1>(document: vscode.TextDocument, options: DocumentTreeOptions | undefined, k: (tree: Tree) => T_1): T_1;
};
/**
* Executes the specified function with the result of {@link query()},
* {@link Query.delete() deleting} the query after the end of the function.
*/
export declare const withQuery: <T>(language: HasLanguage, source: string, k: (query: Query) => T | PromiseLike<T>) => Promise<T>;
/**
* Executes the specified function with the result of {@link querySync()},
* {@link Query.delete() deleting} the query after the end of the function.
*/
export declare const withQuerySync: <T>(language: HasLanguage, source: string, k: (query: Query) => T) => T;
/**
* Executes the specified function with the given arguments, calling
* `arg.delete()` for each `arg` in `args` after the end of its execution.
*
* The function may return a `Promise`, in which case a promise will be
* returned as well.
*/
export declare function using<T, Args extends {
delete(): void;
}[]>(...args: [...Args, (...args: Args) => T]): T;
/**
* Returns the built-in {@link Query} for textobjects of the given language, or
* `undefined` if there is no such built-in query.
*
* This function automatically memoizes its results; callers should neither
* cache nor {@link Query.delete delete} the returned query.
*
* @see https://docs.helix-editor.com/guides/textobject.html
*/
export declare function textObjectQueryFor(input: HasLanguage): Promise<Omit<Query, "delete"> | undefined>;
/**
* A Tree Sitter point with UTF-16-based offsets.
*
* @see {@link TreeSitter.Point}
*/
export type Point = TreeSitter.Point;
/**
* Converts a Tree Sitter {@link Point} to a {@link vscode.Position}.
*/
export declare function toPosition(point: Point): vscode.Position;
/**
* Converts a {@link vscode.Position} into a Tree Sitter {@link Point}.
*/
export declare function fromPosition(position: vscode.Position): Point;
/**
* Returns the {@link vscode.Position} of a Tree Sitter syntax node.
*/
export declare function toRange(node: SyntaxNode): vscode.Range;
/**
* Returns the start and end Tree Sitter {@link Point} positions of a
* {@link vscode.Range}.
*/
export declare function fromRange(range: vscode.Range): {
startPosition: Point;
endPosition: Point;
};