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.ts55
1 files changed, 28 insertions, 27 deletions
diff --git a/editors/code/src/commands/parent_module.ts b/editors/code/src/commands/parent_module.ts
index ad49e1bdb..bf40b4021 100644
--- a/editors/code/src/commands/parent_module.ts
+++ b/editors/code/src/commands/parent_module.ts
@@ -1,32 +1,33 @@
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 const client = ctx.client;
12 textDocument: { uri: editor.document.uri.toString() }, 10 if (!editor || !client) return;
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 11
28 const doc = await vscode.workspace.openTextDocument(uri); 12 const request: lc.TextDocumentPositionParams = {
29 const e = await vscode.window.showTextDocument(doc); 13 textDocument: { uri: editor.document.uri.toString() },
30 e.selection = new vscode.Selection(range.start, range.start); 14 position: client.code2ProtocolConverter.asPosition(
31 e.revealRange(range, vscode.TextEditorRevealType.InCenter); 15 editor.selection.active,
16 ),
17 };
18 const response = await client.sendRequest<lc.Location[]>(
19 'rust-analyzer/parentModule',
20 request,
21 );
22 const loc = response[0];
23 if (loc == null) return;
24
25 const uri = client.protocol2CodeConverter.asUri(loc.uri);
26 const range = client.protocol2CodeConverter.asRange(loc.range);
27
28 const doc = await vscode.workspace.openTextDocument(uri);
29 const e = await vscode.window.showTextDocument(doc);
30 e.selection = new vscode.Selection(range.start, range.start);
31 e.revealRange(range, vscode.TextEditorRevealType.InCenter);
32 };
32} 33}