diff options
Diffstat (limited to 'editors/code/src/commands/parent_module.ts')
-rw-r--r-- | editors/code/src/commands/parent_module.ts | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/editors/code/src/commands/parent_module.ts b/editors/code/src/commands/parent_module.ts new file mode 100644 index 000000000..d66fb3026 --- /dev/null +++ b/editors/code/src/commands/parent_module.ts | |||
@@ -0,0 +1,22 @@ | |||
1 | import * as vscode from 'vscode'; | ||
2 | |||
3 | import { Location, TextDocumentIdentifier } from 'vscode-languageclient'; | ||
4 | import { Server } from '../server'; | ||
5 | |||
6 | export async function handle() { | ||
7 | const editor = vscode.window.activeTextEditor; | ||
8 | if (editor == null || editor.document.languageId !== 'rust') { return; } | ||
9 | const request: TextDocumentIdentifier = { | ||
10 | uri: editor.document.uri.toString(), | ||
11 | }; | ||
12 | const response = await Server.client.sendRequest<Location[]>('m/parentModule', request); | ||
13 | const loc = response[0]; | ||
14 | if (loc == null) { return; } | ||
15 | const uri = Server.client.protocol2CodeConverter.asUri(loc.uri); | ||
16 | const range = Server.client.protocol2CodeConverter.asRange(loc.range); | ||
17 | |||
18 | const doc = await vscode.workspace.openTextDocument(uri); | ||
19 | const e = await vscode.window.showTextDocument(doc); | ||
20 | e.selection = new vscode.Selection(range.start, range.start); | ||
21 | e.revealRange(range, vscode.TextEditorRevealType.InCenter); | ||
22 | } | ||