Skip to content

Commit 1575d55

Browse files
committed
Auto merge of rust-lang#14009 - Veykril:ts-client, r=Veykril
🧹 lsp_ext.ts
2 parents db0d598 + 6411071 commit 1575d55

File tree

3 files changed

+130
-158
lines changed

3 files changed

+130
-158
lines changed

editors/code/src/client.ts

+21-22
Original file line numberDiff line numberDiff line change
@@ -172,12 +172,10 @@ export async function createClient(
172172
)
173173
.then(
174174
(result) => {
175+
if (!result) return null;
175176
const hover = client.protocol2CodeConverter.asHover(result);
176-
if (hover) {
177-
const actions = (<any>result).actions;
178-
if (actions) {
179-
hover.contents.push(renderHoverActions(actions));
180-
}
177+
if (!!result.actions) {
178+
hover.contents.push(renderHoverActions(result.actions));
181179
}
182180
return hover;
183181
},
@@ -310,26 +308,27 @@ class ExperimentalFeatures implements lc.StaticFeature {
310308
return { kind: "static" };
311309
}
312310
fillClientCapabilities(capabilities: lc.ClientCapabilities): void {
313-
const caps: any = capabilities.experimental ?? {};
314-
caps.snippetTextEdit = true;
315-
caps.codeActionGroup = true;
316-
caps.hoverActions = true;
317-
caps.serverStatusNotification = true;
318-
caps.colorDiagnosticOutput = true;
319-
caps.openServerLogs = true;
320-
caps.commands = {
321-
commands: [
322-
"rust-analyzer.runSingle",
323-
"rust-analyzer.debugSingle",
324-
"rust-analyzer.showReferences",
325-
"rust-analyzer.gotoLocation",
326-
"editor.action.triggerParameterHints",
327-
],
311+
capabilities.experimental = {
312+
snippetTextEdit: true,
313+
codeActionGroup: true,
314+
hoverActions: true,
315+
serverStatusNotification: true,
316+
colorDiagnosticOutput: true,
317+
openServerLogs: true,
318+
commands: {
319+
commands: [
320+
"rust-analyzer.runSingle",
321+
"rust-analyzer.debugSingle",
322+
"rust-analyzer.showReferences",
323+
"rust-analyzer.gotoLocation",
324+
"editor.action.triggerParameterHints",
325+
],
326+
},
327+
...capabilities.experimental,
328328
};
329-
capabilities.experimental = caps;
330329
}
331330
initialize(
332-
_capabilities: lc.ServerCapabilities<any>,
331+
_capabilities: lc.ServerCapabilities,
333332
_documentSelector: lc.DocumentSelector | undefined
334333
): void {}
335334
dispose(): void {}

editors/code/src/commands.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -130,11 +130,11 @@ export function joinLines(ctx: CtxInit): Cmd {
130130
}
131131

132132
export function moveItemUp(ctx: CtxInit): Cmd {
133-
return moveItem(ctx, ra.Direction.Up);
133+
return moveItem(ctx, "Up");
134134
}
135135

136136
export function moveItemDown(ctx: CtxInit): Cmd {
137-
return moveItem(ctx, ra.Direction.Down);
137+
return moveItem(ctx, "Down");
138138
}
139139

140140
export function moveItem(ctx: CtxInit, direction: ra.Direction): Cmd {

editors/code/src/lsp_ext.ts

+107-134
Original file line numberDiff line numberDiff line change
@@ -4,131 +4,134 @@
44

55
import * as lc from "vscode-languageclient";
66

7-
export interface AnalyzerStatusParams {
8-
textDocument?: lc.TextDocumentIdentifier;
9-
}
7+
// rust-analyzer overrides
8+
9+
export const hover = new lc.RequestType<
10+
HoverParams,
11+
(lc.Hover & { actions: CommandLinkGroup[] }) | null,
12+
void
13+
>("textDocument/hover");
14+
export type HoverParams = { position: lc.Position | lc.Range } & Omit<
15+
lc.TextDocumentPositionParams,
16+
"position"
17+
> &
18+
lc.WorkDoneProgressParams;
19+
export type CommandLink = {
20+
/**
21+
* A tooltip for the command, when represented in the UI.
22+
*/
23+
tooltip?: string;
24+
} & lc.Command;
25+
export type CommandLinkGroup = {
26+
title?: string;
27+
commands: CommandLink[];
28+
};
29+
30+
// rust-analyzer extensions
31+
1032
export const analyzerStatus = new lc.RequestType<AnalyzerStatusParams, string, void>(
1133
"rust-analyzer/analyzerStatus"
1234
);
13-
export const memoryUsage = new lc.RequestType0<string, void>("rust-analyzer/memoryUsage");
14-
export const shuffleCrateGraph = new lc.RequestType0<null, void>("rust-analyzer/shuffleCrateGraph");
15-
16-
export interface ServerStatusParams {
17-
health: "ok" | "warning" | "error";
18-
quiescent: boolean;
19-
message?: string;
20-
}
21-
export const serverStatus = new lc.NotificationType<ServerStatusParams>(
22-
"experimental/serverStatus"
35+
export const cancelFlycheck = new lc.NotificationType0("rust-analyzer/cancelFlycheck");
36+
export const clearFlycheck = new lc.NotificationType0("rust-analyzer/clearFlycheck");
37+
export const expandMacro = new lc.RequestType<ExpandMacroParams, ExpandedMacro | null, void>(
38+
"rust-analyzer/expandMacro"
2339
);
40+
export const memoryUsage = new lc.RequestType0<string, void>("rust-analyzer/memoryUsage");
2441
export const openServerLogs = new lc.NotificationType0("rust-analyzer/openServerLogs");
25-
42+
export const relatedTests = new lc.RequestType<lc.TextDocumentPositionParams, TestInfo[], void>(
43+
"rust-analyzer/relatedTests"
44+
);
2645
export const reloadWorkspace = new lc.RequestType0<null, void>("rust-analyzer/reloadWorkspace");
27-
28-
export const hover = new lc.RequestType<HoverParams, lc.Hover | null, void>("textDocument/hover");
29-
30-
export interface HoverParams extends lc.WorkDoneProgressParams {
31-
textDocument: lc.TextDocumentIdentifier;
32-
position: lc.Range | lc.Position;
33-
}
34-
35-
export interface SyntaxTreeParams {
36-
textDocument: lc.TextDocumentIdentifier;
37-
range: lc.Range | null;
38-
}
46+
export const runFlycheck = new lc.NotificationType<{
47+
textDocument: lc.TextDocumentIdentifier | null;
48+
}>("rust-analyzer/runFlycheck");
49+
export const shuffleCrateGraph = new lc.RequestType0<null, void>("rust-analyzer/shuffleCrateGraph");
3950
export const syntaxTree = new lc.RequestType<SyntaxTreeParams, string, void>(
4051
"rust-analyzer/syntaxTree"
4152
);
42-
43-
export const viewHir = new lc.RequestType<lc.TextDocumentPositionParams, string, void>(
44-
"rust-analyzer/viewHir"
53+
export const viewCrateGraph = new lc.RequestType<ViewCrateGraphParams, string, void>(
54+
"rust-analyzer/viewCrateGraph"
4555
);
46-
4756
export const viewFileText = new lc.RequestType<lc.TextDocumentIdentifier, string, void>(
4857
"rust-analyzer/viewFileText"
4958
);
50-
51-
export interface ViewItemTreeParams {
52-
textDocument: lc.TextDocumentIdentifier;
53-
}
54-
59+
export const viewHir = new lc.RequestType<lc.TextDocumentPositionParams, string, void>(
60+
"rust-analyzer/viewHir"
61+
);
5562
export const viewItemTree = new lc.RequestType<ViewItemTreeParams, string, void>(
5663
"rust-analyzer/viewItemTree"
5764
);
5865

59-
export interface ViewCrateGraphParams {
60-
full: boolean;
61-
}
62-
63-
export const viewCrateGraph = new lc.RequestType<ViewCrateGraphParams, string, void>(
64-
"rust-analyzer/viewCrateGraph"
65-
);
66+
export type AnalyzerStatusParams = { textDocument?: lc.TextDocumentIdentifier };
6667

67-
export interface ExpandMacroParams {
68+
export type ExpandMacroParams = {
6869
textDocument: lc.TextDocumentIdentifier;
6970
position: lc.Position;
70-
}
71-
export interface ExpandedMacro {
71+
};
72+
export type ExpandedMacro = {
7273
name: string;
7374
expansion: string;
74-
}
75-
export const expandMacro = new lc.RequestType<ExpandMacroParams, ExpandedMacro | null, void>(
76-
"rust-analyzer/expandMacro"
77-
);
78-
79-
export const relatedTests = new lc.RequestType<lc.TextDocumentPositionParams, TestInfo[], void>(
80-
"rust-analyzer/relatedTests"
81-
);
82-
83-
export const cancelFlycheck = new lc.NotificationType0("rust-analyzer/cancelFlycheck");
84-
export const clearFlycheck = new lc.NotificationType0("rust-analyzer/clearFlycheck");
85-
export const runFlycheck = new lc.NotificationType<{
86-
textDocument: lc.TextDocumentIdentifier | null;
87-
}>("rust-analyzer/runFlycheck");
88-
89-
// Experimental extensions
90-
91-
export interface SsrParams {
92-
query: string;
93-
parseOnly: boolean;
75+
};
76+
export type TestInfo = { runnable: Runnable };
77+
export type SyntaxTreeParams = {
9478
textDocument: lc.TextDocumentIdentifier;
95-
position: lc.Position;
96-
selections: readonly lc.Range[];
97-
}
98-
export const ssr = new lc.RequestType<SsrParams, lc.WorkspaceEdit, void>("experimental/ssr");
79+
range: lc.Range | null;
80+
};
81+
export type ViewCrateGraphParams = { full: boolean };
82+
export type ViewItemTreeParams = { textDocument: lc.TextDocumentIdentifier };
9983

100-
export interface MatchingBraceParams {
101-
textDocument: lc.TextDocumentIdentifier;
102-
positions: lc.Position[];
103-
}
84+
// experimental extensions
85+
86+
export const joinLines = new lc.RequestType<JoinLinesParams, lc.TextEdit[], void>(
87+
"experimental/joinLines"
88+
);
10489
export const matchingBrace = new lc.RequestType<MatchingBraceParams, lc.Position[], void>(
10590
"experimental/matchingBrace"
10691
);
107-
92+
export const moveItem = new lc.RequestType<MoveItemParams, lc.TextEdit[], void>(
93+
"experimental/moveItem"
94+
);
95+
export const onEnter = new lc.RequestType<lc.TextDocumentPositionParams, lc.TextEdit[], void>(
96+
"experimental/onEnter"
97+
);
98+
export const openCargoToml = new lc.RequestType<OpenCargoTomlParams, lc.Location, void>(
99+
"experimental/openCargoToml"
100+
);
101+
export const openDocs = new lc.RequestType<lc.TextDocumentPositionParams, string | void, void>(
102+
"experimental/externalDocs"
103+
);
108104
export const parentModule = new lc.RequestType<
109105
lc.TextDocumentPositionParams,
110106
lc.LocationLink[] | null,
111107
void
112108
>("experimental/parentModule");
113-
114-
export interface JoinLinesParams {
115-
textDocument: lc.TextDocumentIdentifier;
116-
ranges: lc.Range[];
117-
}
118-
export const joinLines = new lc.RequestType<JoinLinesParams, lc.TextEdit[], void>(
119-
"experimental/joinLines"
109+
export const runnables = new lc.RequestType<RunnablesParams, Runnable[], void>(
110+
"experimental/runnables"
120111
);
121-
122-
export const onEnter = new lc.RequestType<lc.TextDocumentPositionParams, lc.TextEdit[], void>(
123-
"experimental/onEnter"
112+
export const serverStatus = new lc.NotificationType<ServerStatusParams>(
113+
"experimental/serverStatus"
124114
);
115+
export const ssr = new lc.RequestType<SsrParams, lc.WorkspaceEdit, void>("experimental/ssr");
125116

126-
export interface RunnablesParams {
117+
export type JoinLinesParams = {
127118
textDocument: lc.TextDocumentIdentifier;
128-
position: lc.Position | null;
129-
}
130-
131-
export interface Runnable {
119+
ranges: lc.Range[];
120+
};
121+
export type MatchingBraceParams = {
122+
textDocument: lc.TextDocumentIdentifier;
123+
positions: lc.Position[];
124+
};
125+
export type MoveItemParams = {
126+
textDocument: lc.TextDocumentIdentifier;
127+
range: lc.Range;
128+
direction: Direction;
129+
};
130+
export type Direction = "Up" | "Down";
131+
export type OpenCargoTomlParams = {
132+
textDocument: lc.TextDocumentIdentifier;
133+
};
134+
export type Runnable = {
132135
label: string;
133136
location?: lc.LocationLink;
134137
kind: "cargo";
@@ -140,50 +143,20 @@ export interface Runnable {
140143
expectTest?: boolean;
141144
overrideCargo?: string;
142145
};
143-
}
144-
export const runnables = new lc.RequestType<RunnablesParams, Runnable[], void>(
145-
"experimental/runnables"
146-
);
147-
148-
export interface TestInfo {
149-
runnable: Runnable;
150-
}
151-
152-
export interface CommandLink extends lc.Command {
153-
/**
154-
* A tooltip for the command, when represented in the UI.
155-
*/
156-
tooltip?: string;
157-
}
158-
159-
export interface CommandLinkGroup {
160-
title?: string;
161-
commands: CommandLink[];
162-
}
163-
164-
export const openDocs = new lc.RequestType<lc.TextDocumentPositionParams, string | void, void>(
165-
"experimental/externalDocs"
166-
);
167-
168-
export const openCargoToml = new lc.RequestType<OpenCargoTomlParams, lc.Location, void>(
169-
"experimental/openCargoToml"
170-
);
171-
172-
export interface OpenCargoTomlParams {
146+
};
147+
export type RunnablesParams = {
173148
textDocument: lc.TextDocumentIdentifier;
174-
}
175-
176-
export const moveItem = new lc.RequestType<MoveItemParams, lc.TextEdit[], void>(
177-
"experimental/moveItem"
178-
);
179-
180-
export interface MoveItemParams {
149+
position: lc.Position | null;
150+
};
151+
export type ServerStatusParams = {
152+
health: "ok" | "warning" | "error";
153+
quiescent: boolean;
154+
message?: string;
155+
};
156+
export type SsrParams = {
157+
query: string;
158+
parseOnly: boolean;
181159
textDocument: lc.TextDocumentIdentifier;
182-
range: lc.Range;
183-
direction: Direction;
184-
}
185-
186-
export const enum Direction {
187-
Up = "Up",
188-
Down = "Down",
189-
}
160+
position: lc.Position;
161+
selections: readonly lc.Range[];
162+
};

0 commit comments

Comments
 (0)