aboutsummaryrefslogtreecommitdiff
path: root/editors/code/src/commands
diff options
context:
space:
mode:
Diffstat (limited to 'editors/code/src/commands')
-rw-r--r--editors/code/src/commands/analyzer_status.ts5
-rw-r--r--editors/code/src/commands/expand_macro.ts5
-rw-r--r--editors/code/src/commands/index.ts25
-rw-r--r--editors/code/src/commands/join_lines.ts7
4 files changed, 28 insertions, 14 deletions
diff --git a/editors/code/src/commands/analyzer_status.ts b/editors/code/src/commands/analyzer_status.ts
index 2c8362286..cf37dc6f0 100644
--- a/editors/code/src/commands/analyzer_status.ts
+++ b/editors/code/src/commands/analyzer_status.ts
@@ -49,9 +49,10 @@ class TextDocumentContentProvider
49 _uri: vscode.Uri, 49 _uri: vscode.Uri,
50 ): vscode.ProviderResult<string> { 50 ): vscode.ProviderResult<string> {
51 const editor = vscode.window.activeTextEditor; 51 const editor = vscode.window.activeTextEditor;
52 if (editor == null) return ''; 52 const client = this.ctx.client
53 if (!editor || !client) return '';
53 54
54 return this.ctx.client.sendRequest<string>( 55 return client.sendRequest<string>(
55 'rust-analyzer/analyzerStatus', 56 'rust-analyzer/analyzerStatus',
56 null, 57 null,
57 ); 58 );
diff --git a/editors/code/src/commands/expand_macro.ts b/editors/code/src/commands/expand_macro.ts
index da208257a..472f43b8d 100644
--- a/editors/code/src/commands/expand_macro.ts
+++ b/editors/code/src/commands/expand_macro.ts
@@ -52,14 +52,15 @@ class TextDocumentContentProvider
52 52
53 async provideTextDocumentContent(_uri: vscode.Uri): Promise<string> { 53 async provideTextDocumentContent(_uri: vscode.Uri): Promise<string> {
54 const editor = vscode.window.activeTextEditor; 54 const editor = vscode.window.activeTextEditor;
55 if (editor == null) return ''; 55 const client = this.ctx.client
56 if (!editor || !client) return '';
56 57
57 const position = editor.selection.active; 58 const position = editor.selection.active;
58 const request: lc.TextDocumentPositionParams = { 59 const request: lc.TextDocumentPositionParams = {
59 textDocument: { uri: editor.document.uri.toString() }, 60 textDocument: { uri: editor.document.uri.toString() },
60 position, 61 position,
61 }; 62 };
62 const expanded = await this.ctx.client.sendRequest<ExpandedMacro>( 63 const expanded = await client.sendRequest<ExpandedMacro>(
63 'rust-analyzer/expandMacro', 64 'rust-analyzer/expandMacro',
64 request, 65 request,
65 ); 66 );
diff --git a/editors/code/src/commands/index.ts b/editors/code/src/commands/index.ts
index c28709c8a..4431fdcf6 100644
--- a/editors/code/src/commands/index.ts
+++ b/editors/code/src/commands/index.ts
@@ -15,18 +15,21 @@ import { run, runSingle } from './runnables';
15 15
16function collectGarbage(ctx: Ctx): Cmd { 16function collectGarbage(ctx: Ctx): Cmd {
17 return async () => { 17 return async () => {
18 ctx.client.sendRequest<null>('rust-analyzer/collectGarbage', null); 18 ctx.client?.sendRequest<null>('rust-analyzer/collectGarbage', null);
19 }; 19 };
20} 20}
21 21
22function showReferences(ctx: Ctx): Cmd { 22function showReferences(ctx: Ctx): Cmd {
23 return (uri: string, position: lc.Position, locations: lc.Location[]) => { 23 return (uri: string, position: lc.Position, locations: lc.Location[]) => {
24 vscode.commands.executeCommand( 24 let client = ctx.client;
25 'editor.action.showReferences', 25 if (client) {
26 vscode.Uri.parse(uri), 26 vscode.commands.executeCommand(
27 ctx.client.protocol2CodeConverter.asPosition(position), 27 'editor.action.showReferences',
28 locations.map(ctx.client.protocol2CodeConverter.asLocation), 28 vscode.Uri.parse(uri),
29 ); 29 client.protocol2CodeConverter.asPosition(position),
30 locations.map(client.protocol2CodeConverter.asLocation),
31 );
32 }
30 }; 33 };
31} 34}
32 35
@@ -36,6 +39,13 @@ function applySourceChange(ctx: Ctx): Cmd {
36 } 39 }
37} 40}
38 41
42function reload(ctx: Ctx): Cmd {
43 return async () => {
44 vscode.window.showInformationMessage('Reloading rust-analyzer...');
45 await ctx.restartServer();
46 }
47}
48
39export { 49export {
40 analyzerStatus, 50 analyzerStatus,
41 expandMacro, 51 expandMacro,
@@ -49,4 +59,5 @@ export {
49 runSingle, 59 runSingle,
50 showReferences, 60 showReferences,
51 applySourceChange, 61 applySourceChange,
62 reload
52}; 63};
diff --git a/editors/code/src/commands/join_lines.ts b/editors/code/src/commands/join_lines.ts
index f4f902cf9..7b08c3255 100644
--- a/editors/code/src/commands/join_lines.ts
+++ b/editors/code/src/commands/join_lines.ts
@@ -6,13 +6,14 @@ import { applySourceChange, SourceChange } from '../source_change';
6export function joinLines(ctx: Ctx): Cmd { 6export function joinLines(ctx: Ctx): Cmd {
7 return async () => { 7 return async () => {
8 const editor = ctx.activeRustEditor; 8 const editor = ctx.activeRustEditor;
9 if (!editor) return; 9 const client = ctx.client;
10 if (!editor || !client) return;
10 11
11 const request: JoinLinesParams = { 12 const request: JoinLinesParams = {
12 range: ctx.client.code2ProtocolConverter.asRange(editor.selection), 13 range: client.code2ProtocolConverter.asRange(editor.selection),
13 textDocument: { uri: editor.document.uri.toString() }, 14 textDocument: { uri: editor.document.uri.toString() },
14 }; 15 };
15 const change = await ctx.client.sendRequest<SourceChange>( 16 const change = await client.sendRequest<SourceChange>(
16 'rust-analyzer/joinLines', 17 'rust-analyzer/joinLines',
17 request, 18 request,
18 ); 19 );