rust/editors/code/src/commands/parent_module.ts

30 lines
1,001 B
TypeScript
Raw Normal View History

2018-10-07 22:44:25 +02:00
import * as vscode from 'vscode';
2018-10-07 22:59:02 +02:00
import { Location, TextDocumentIdentifier } from 'vscode-languageclient';
2018-10-07 22:44:25 +02:00
import { Server } from '../server';
export async function handle() {
2018-10-07 22:59:02 +02:00
const editor = vscode.window.activeTextEditor;
2018-10-08 23:38:33 +02:00
if (editor == null || editor.document.languageId !== 'rust') {
return;
}
2018-10-07 22:59:02 +02:00
const request: TextDocumentIdentifier = {
2018-10-08 23:38:33 +02:00
uri: editor.document.uri.toString()
2018-10-07 22:59:02 +02:00
};
2018-10-08 23:38:33 +02:00
const response = await Server.client.sendRequest<Location[]>(
'm/parentModule',
request
);
2018-10-07 22:59:02 +02:00
const loc = response[0];
2018-10-08 23:38:33 +02:00
if (loc == null) {
return;
}
2018-10-07 22:59:02 +02:00
const uri = Server.client.protocol2CodeConverter.asUri(loc.uri);
const range = Server.client.protocol2CodeConverter.asRange(loc.range);
2018-10-07 22:44:25 +02:00
2018-10-07 22:59:02 +02:00
const doc = await vscode.workspace.openTextDocument(uri);
const e = await vscode.window.showTextDocument(doc);
e.selection = new vscode.Selection(range.start, range.start);
e.revealRange(range, vscode.TextEditorRevealType.InCenter);
2018-10-07 22:44:25 +02:00
}