aboutsummaryrefslogtreecommitdiff
path: root/editors/code/src/commands/parent_module.ts
diff options
context:
space:
mode:
Diffstat (limited to 'editors/code/src/commands/parent_module.ts')
-rw-r--r--editors/code/src/commands/parent_module.ts54
1 files changed, 27 insertions, 27 deletions
diff --git a/editors/code/src/commands/parent_module.ts b/editors/code/src/commands/parent_module.ts
index ad49e1bdb..258b61b21 100644
--- a/editors/code/src/commands/parent_module.ts
+++ b/editors/code/src/commands/parent_module.ts
@@ -1,32 +1,32 @@
1import * as vscode from 'vscode'; 1import * as vscode from 'vscode';
2
3import * as lc from 'vscode-languageclient'; 2import * as lc from 'vscode-languageclient';
4import { Server } from '../server';
5 3
6export async function handle() { 4import { Ctx, Cmd } from '../ctx';
7 const editor = vscode.window.activeTextEditor; 5
8 if (editor == null || editor.document.languageId !== 'rust') { 6export function parentModule(ctx: Ctx): Cmd {
9 return; 7 return async () => {
10 } 8 const editor = ctx.activeRustEditor;
11 const request: lc.TextDocumentPositionParams = { 9 if (!editor) return;
12 textDocument: { uri: editor.document.uri.toString() },
13 position: Server.client.code2ProtocolConverter.asPosition(
14 editor.selection.active,
15 ),
16 };
17 const response = await Server.client.sendRequest<lc.Location[]>(
18 'rust-analyzer/parentModule',
19 request,
20 );
21 const loc = response[0];
22 if (loc == null) {
23 return;
24 }
25 const uri = Server.client.protocol2CodeConverter.asUri(loc.uri);
26 const range = Server.client.protocol2CodeConverter.asRange(loc.range);
27 10
28 const doc = await vscode.workspace.openTextDocument(uri); 11 const request: lc.TextDocumentPositionParams = {
29 const e = await vscode.window.showTextDocument(doc); 12 textDocument: { uri: editor.document.uri.toString() },
30 e.selection = new vscode.Selection(range.start, range.start); 13 position: ctx.client.code2ProtocolConverter.asPosition(
31 e.revealRange(range, vscode.TextEditorRevealType.InCenter); 14 editor.selection.active,
15 ),
16 };
17 const response = await ctx.client.sendRequest<lc.Location[]>(
18 'rust-analyzer/parentModule',
19 request,
20 );
21 const loc = response[0];
22 if (loc == null) return;
23
24 const uri = ctx.client.protocol2CodeConverter.asUri(loc.uri);
25 const range = ctx.client.protocol2CodeConverter.asRange(loc.range);
26
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}