diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2019-12-31 17:38:55 +0000 |
---|---|---|
committer | GitHub <[email protected]> | 2019-12-31 17:38:55 +0000 |
commit | 6d23140ba03c77b28d94e042c94155899baba9da (patch) | |
tree | 3efa5daf54fe08cd1b310fa42c2ef469503fcedd /editors/code/src/commands | |
parent | 1327aed7f6289043091aa9179282030c6f13ddbe (diff) | |
parent | 6368b40dd98b208da3758d4d1eed34cf276e3b09 (diff) |
Merge #2709
2709: Work around synchrnonisation issue r=matklad a=matklad
Co-authored-by: Aleksey Kladov <[email protected]>
Diffstat (limited to 'editors/code/src/commands')
-rw-r--r-- | editors/code/src/commands/analyzer_status.ts | 5 | ||||
-rw-r--r-- | editors/code/src/commands/expand_macro.ts | 5 | ||||
-rw-r--r-- | editors/code/src/commands/index.ts | 25 | ||||
-rw-r--r-- | editors/code/src/commands/join_lines.ts | 7 |
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 | ||
16 | function collectGarbage(ctx: Ctx): Cmd { | 16 | function 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 | ||
22 | function showReferences(ctx: Ctx): Cmd { | 22 | function 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 | ||
42 | function reload(ctx: Ctx): Cmd { | ||
43 | return async () => { | ||
44 | vscode.window.showInformationMessage('Reloading rust-analyzer...'); | ||
45 | await ctx.restartServer(); | ||
46 | } | ||
47 | } | ||
48 | |||
39 | export { | 49 | export { |
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'; | |||
6 | export function joinLines(ctx: Ctx): Cmd { | 6 | export 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 | ); |