diff options
author | Aleksey Kladov <[email protected]> | 2019-12-30 16:03:05 +0000 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2019-12-30 18:07:59 +0000 |
commit | 9bfeac708d33056b37d780b948cb1f117cac19af (patch) | |
tree | b8c6c457728fdf360cae10de9ef5b68ee2548f65 /editors/code/src/commands | |
parent | 5aebf1081dced95a71c674aba65fb5b3e40e6ff1 (diff) |
Move parentModule to the new Ctx
Diffstat (limited to 'editors/code/src/commands')
-rw-r--r-- | editors/code/src/commands/index.ts | 2 | ||||
-rw-r--r-- | editors/code/src/commands/parent_module.ts | 52 |
2 files changed, 27 insertions, 27 deletions
diff --git a/editors/code/src/commands/index.ts b/editors/code/src/commands/index.ts index 0a0a36e23..03ca58210 100644 --- a/editors/code/src/commands/index.ts +++ b/editors/code/src/commands/index.ts | |||
@@ -4,9 +4,9 @@ import { analyzerStatus } from './analyzer_status'; | |||
4 | import { matchingBrace } from './matching_brace'; | 4 | import { matchingBrace } from './matching_brace'; |
5 | import { joinLines } from './join_lines'; | 5 | import { joinLines } from './join_lines'; |
6 | import { onEnter } from './on_enter'; | 6 | import { onEnter } from './on_enter'; |
7 | import { parentModule } from './parent_module'; | ||
7 | import * as expandMacro from './expand_macro'; | 8 | import * as expandMacro from './expand_macro'; |
8 | import * as inlayHints from './inlay_hints'; | 9 | import * as inlayHints from './inlay_hints'; |
9 | import * as parentModule from './parent_module'; | ||
10 | import * as runnables from './runnables'; | 10 | import * as runnables from './runnables'; |
11 | import * as syntaxTree from './syntaxTree'; | 11 | import * as syntaxTree from './syntaxTree'; |
12 | 12 | ||
diff --git a/editors/code/src/commands/parent_module.ts b/editors/code/src/commands/parent_module.ts index ad49e1bdb..2f986009e 100644 --- a/editors/code/src/commands/parent_module.ts +++ b/editors/code/src/commands/parent_module.ts | |||
@@ -1,32 +1,32 @@ | |||
1 | import * as vscode from 'vscode'; | 1 | import * as vscode from 'vscode'; |
2 | 2 | ||
3 | import * as lc from 'vscode-languageclient'; | 3 | import * as lc from 'vscode-languageclient'; |
4 | import { Server } from '../server'; | 4 | import { Ctx, Cmd } from '../ctx'; |
5 | 5 | ||
6 | export async function handle() { | 6 | export function parentModule(ctx: Ctx): Cmd { |
7 | const editor = vscode.window.activeTextEditor; | 7 | return async () => { |
8 | if (editor == null || editor.document.languageId !== 'rust') { | 8 | const editor = ctx.activeRustEditor; |
9 | return; | 9 | if (!editor) return; |
10 | } | 10 | |
11 | const request: lc.TextDocumentPositionParams = { | 11 | const request: lc.TextDocumentPositionParams = { |
12 | textDocument: { uri: editor.document.uri.toString() }, | 12 | textDocument: { uri: editor.document.uri.toString() }, |
13 | position: Server.client.code2ProtocolConverter.asPosition( | 13 | position: ctx.client.code2ProtocolConverter.asPosition( |
14 | editor.selection.active, | 14 | editor.selection.active, |
15 | ), | 15 | ), |
16 | }; | 16 | }; |
17 | const response = await Server.client.sendRequest<lc.Location[]>( | 17 | const response = await ctx.client.sendRequest<lc.Location[]>( |
18 | 'rust-analyzer/parentModule', | 18 | 'rust-analyzer/parentModule', |
19 | request, | 19 | request, |
20 | ); | 20 | ); |
21 | const loc = response[0]; | 21 | const loc = response[0]; |
22 | if (loc == null) { | 22 | if (loc == null) return; |
23 | return; | ||
24 | } | ||
25 | const uri = Server.client.protocol2CodeConverter.asUri(loc.uri); | ||
26 | const range = Server.client.protocol2CodeConverter.asRange(loc.range); | ||
27 | 23 | ||
28 | const doc = await vscode.workspace.openTextDocument(uri); | 24 | const uri = ctx.client.protocol2CodeConverter.asUri(loc.uri); |
29 | const e = await vscode.window.showTextDocument(doc); | 25 | const range = ctx.client.protocol2CodeConverter.asRange(loc.range); |
30 | e.selection = new vscode.Selection(range.start, range.start); | 26 | |
31 | e.revealRange(range, vscode.TextEditorRevealType.InCenter); | 27 | const doc = await vscode.workspace.openTextDocument(uri); |
28 | const e = await vscode.window.showTextDocument(doc); | ||
29 | e.selection = new vscode.Selection(range.start, range.start); | ||
30 | e.revealRange(range, vscode.TextEditorRevealType.InCenter); | ||
31 | } | ||
32 | } | 32 | } |