-
Notifications
You must be signed in to change notification settings - Fork 1.6k
/
Copy pathlsp_ext.ts
308 lines (282 loc) · 9.44 KB
/
lsp_ext.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
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
/**
* This file mirrors `crates/rust-analyzer/src/lsp_ext.rs` declarations.
*/
import * as lc from "vscode-languageclient";
// rust-analyzer overrides
export const hover = new lc.RequestType<
HoverParams,
(lc.Hover & { actions: CommandLinkGroup[] }) | null,
void
>(lc.HoverRequest.method);
export type HoverParams = { position: lc.Position | lc.Range } & Omit<lc.HoverParams, "position">;
export type CommandLink = {
/**
* A tooltip for the command, when represented in the UI.
*/
tooltip?: string;
} & lc.Command;
export type CommandLinkGroup = {
title?: string;
commands: CommandLink[];
};
// rust-analyzer extensions
export const analyzerStatus = new lc.RequestType<AnalyzerStatusParams, string, void>(
"rust-analyzer/analyzerStatus",
);
export const cancelFlycheck = new lc.NotificationType0("rust-analyzer/cancelFlycheck");
export const clearFlycheck = new lc.NotificationType0("rust-analyzer/clearFlycheck");
export const expandMacro = new lc.RequestType<ExpandMacroParams, ExpandedMacro | null, void>(
"rust-analyzer/expandMacro",
);
export const memoryUsage = new lc.RequestType0<string, void>("rust-analyzer/memoryUsage");
export const openServerLogs = new lc.NotificationType0("rust-analyzer/openServerLogs");
export const relatedTests = new lc.RequestType<lc.TextDocumentPositionParams, TestInfo[], void>(
"rust-analyzer/relatedTests",
);
export const reloadWorkspace = new lc.RequestType0<null, void>("rust-analyzer/reloadWorkspace");
export const rebuildProcMacros = new lc.RequestType0<null, void>("rust-analyzer/rebuildProcMacros");
export const runFlycheck = new lc.NotificationType<{
textDocument: lc.TextDocumentIdentifier | null;
}>("rust-analyzer/runFlycheck");
export const syntaxTree = new lc.RequestType<SyntaxTreeParams, string, void>(
"rust-analyzer/syntaxTree",
);
export const viewSyntaxTree = new lc.RequestType<ViewSyntaxTreeParams, string, void>(
"rust-analyzer/viewSyntaxTree",
);
export const viewCrateGraph = new lc.RequestType<ViewCrateGraphParams, string, void>(
"rust-analyzer/viewCrateGraph",
);
export const viewFileText = new lc.RequestType<lc.TextDocumentIdentifier, string, void>(
"rust-analyzer/viewFileText",
);
export const viewHir = new lc.RequestType<lc.TextDocumentPositionParams, string, void>(
"rust-analyzer/viewHir",
);
export const viewMir = new lc.RequestType<lc.TextDocumentPositionParams, string, void>(
"rust-analyzer/viewMir",
);
export const interpretFunction = new lc.RequestType<lc.TextDocumentPositionParams, string, void>(
"rust-analyzer/interpretFunction",
);
export const viewItemTree = new lc.RequestType<ViewItemTreeParams, string, void>(
"rust-analyzer/viewItemTree",
);
export type DiscoverTestParams = { testId?: string | undefined };
export type RunTestParams = {
include?: string[] | undefined;
exclude?: string[] | undefined;
};
export type TestItem = {
id: string;
label: string;
kind: "package" | "module" | "test";
canResolveChildren: boolean;
parent?: string | undefined;
textDocument?: lc.TextDocumentIdentifier | undefined;
range?: lc.Range | undefined;
runnable?: Runnable | undefined;
};
export type DiscoverTestResults = {
tests: TestItem[];
scope: string[] | undefined;
scopeFile: lc.TextDocumentIdentifier[] | undefined;
};
export type TestState =
| { tag: "failed"; message: string }
| { tag: "passed" }
| { tag: "started" }
| { tag: "enqueued" }
| { tag: "skipped" };
export type ChangeTestStateParams = { testId: string; state: TestState };
export const discoverTest = new lc.RequestType<DiscoverTestParams, DiscoverTestResults, void>(
"experimental/discoverTest",
);
export const discoveredTests = new lc.NotificationType<DiscoverTestResults>(
"experimental/discoveredTests",
);
export const runTest = new lc.RequestType<RunTestParams, void, void>("experimental/runTest");
export const abortRunTest = new lc.NotificationType0("experimental/abortRunTest");
export const endRunTest = new lc.NotificationType0("experimental/endRunTest");
export const appendOutputToRunTest = new lc.NotificationType<string>(
"experimental/appendOutputToRunTest",
);
export const changeTestState = new lc.NotificationType<ChangeTestStateParams>(
"experimental/changeTestState",
);
export type AnalyzerStatusParams = { textDocument?: lc.TextDocumentIdentifier };
export interface FetchDependencyListParams {}
export interface FetchDependencyListResult {
crates: {
name?: string;
version?: string;
path: string;
}[];
}
export const fetchDependencyList = new lc.RequestType<
FetchDependencyListParams,
FetchDependencyListResult,
void
>("rust-analyzer/fetchDependencyList");
export interface FetchDependencyGraphParams {}
export interface FetchDependencyGraphResult {
crates: {
name: string;
version: string;
path: string;
}[];
}
export const fetchDependencyGraph = new lc.RequestType<
FetchDependencyGraphParams,
FetchDependencyGraphResult,
void
>("rust-analyzer/fetchDependencyGraph");
export type ExpandMacroParams = {
textDocument: lc.TextDocumentIdentifier;
position: lc.Position;
};
export type ExpandedMacro = {
name: string;
expansion: string;
};
export type TestInfo = { runnable: Runnable };
export type SyntaxTreeParams = {
textDocument: lc.TextDocumentIdentifier;
range: lc.Range | null;
};
export type ViewSyntaxTreeParams = { textDocument: lc.TextDocumentIdentifier };
export type ViewCrateGraphParams = { full: boolean };
export type ViewItemTreeParams = { textDocument: lc.TextDocumentIdentifier };
// experimental extensions
export const joinLines = new lc.RequestType<JoinLinesParams, lc.TextEdit[], void>(
"experimental/joinLines",
);
export const matchingBrace = new lc.RequestType<MatchingBraceParams, lc.Position[], void>(
"experimental/matchingBrace",
);
export const moveItem = new lc.RequestType<MoveItemParams, lc.TextEdit[], void>(
"experimental/moveItem",
);
export const onEnter = new lc.RequestType<lc.TextDocumentPositionParams, lc.TextEdit[], void>(
"experimental/onEnter",
);
export const openCargoToml = new lc.RequestType<OpenCargoTomlParams, lc.Location, void>(
"experimental/openCargoToml",
);
export interface DocsUrls {
local?: string;
web?: string;
}
export const openDocs = new lc.RequestType<lc.TextDocumentPositionParams, DocsUrls, void>(
"experimental/externalDocs",
);
export const parentModule = new lc.RequestType<
lc.TextDocumentPositionParams,
lc.LocationLink[] | null,
void
>("experimental/parentModule");
export const runnables = new lc.RequestType<RunnablesParams, Runnable[], void>(
"experimental/runnables",
);
export const serverStatus = new lc.NotificationType<ServerStatusParams>(
"experimental/serverStatus",
);
export const ssr = new lc.RequestType<SsrParams, lc.WorkspaceEdit, void>("experimental/ssr");
export const viewRecursiveMemoryLayout = new lc.RequestType<
lc.TextDocumentPositionParams,
RecursiveMemoryLayout | null,
void
>("rust-analyzer/viewRecursiveMemoryLayout");
export type JoinLinesParams = {
textDocument: lc.TextDocumentIdentifier;
ranges: lc.Range[];
};
export type MatchingBraceParams = {
textDocument: lc.TextDocumentIdentifier;
positions: lc.Position[];
};
export type MoveItemParams = {
textDocument: lc.TextDocumentIdentifier;
range: lc.Range;
direction: Direction;
};
export type Direction = "Up" | "Down";
export type OpenCargoTomlParams = {
textDocument: lc.TextDocumentIdentifier;
};
export type Runnable = {
label: string;
location?: lc.LocationLink;
} & (RunnableCargo | RunnableShell);
type RunnableCargo = {
kind: "cargo";
args: CargoRunnableArgs;
};
type RunnableShell = {
kind: "shell";
args: ShellRunnableArgs;
};
export type CommonRunnableArgs = {
/**
* Environment variables to set before running the command.
*/
environment?: Record<string, string>;
/**
* The working directory to run the command in.
*/
cwd: string;
};
export type ShellRunnableArgs = {
kind: string;
program: string;
args: string[];
} & CommonRunnableArgs;
export type CargoRunnableArgs = {
/**
* The workspace root directory of the cargo project.
*/
workspaceRoot?: string;
/**
* Arguments to pass to the executable, these will be passed to the command after a `--` argument.
*/
executableArgs: string[];
/**
* Arguments to pass to cargo.
*/
cargoArgs: string[];
/**
* Command to execute instead of `cargo`.
*/
// This is supplied by the user via config. We could pull this through the client config in the
// extension directly, but that would prevent us from honoring the rust-analyzer.toml for it.
overrideCargo?: string;
} & CommonRunnableArgs;
export type RunnablesParams = {
textDocument: lc.TextDocumentIdentifier;
position: lc.Position | null;
};
export type ServerStatusParams = {
health: "ok" | "warning" | "error";
quiescent: boolean;
message?: string;
};
export type SsrParams = {
query: string;
parseOnly: boolean;
textDocument: lc.TextDocumentIdentifier;
position: lc.Position;
selections: readonly lc.Range[];
};
export type RecursiveMemoryLayoutNode = {
item_name: string;
typename: string;
size: number;
alignment: number;
offset: number;
parent_idx: number;
children_start: number;
children_len: number;
};
export type RecursiveMemoryLayout = {
nodes: RecursiveMemoryLayoutNode[];
};