aboutsummaryrefslogtreecommitdiff
path: root/editors/code/src/commands/parent_module.ts
blob: 4bb92eb96a703d10ae1d79a568c0799727c5b88e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import * as vscode from 'vscode';

import { Location, TextDocumentIdentifier } from 'vscode-languageclient';
import { Server } from '../server';

export async function handle() {
    const editor = vscode.window.activeTextEditor;
    if (editor == null || editor.document.languageId !== 'rust') {
        return;
    }
    const request: TextDocumentIdentifier = {
        uri: editor.document.uri.toString()
    };
    const response = await Server.client.sendRequest<Location[]>(
        'm/parentModule',
        request
    );
    const loc = response[0];
    if (loc == null) {
        return;
    }
    const uri = Server.client.protocol2CodeConverter.asUri(loc.uri);
    const range = Server.client.protocol2CodeConverter.asRange(loc.range);

    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);
}