aboutsummaryrefslogtreecommitdiff
path: root/editors/code/src/commands/extend_selection.ts
blob: b90828ba9bab88d0d24ed4e3343a0b8177f4eb5d (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 { TextDocumentIdentifier, Range } from "vscode-languageclient";
import { Server } from '../server';

interface ExtendSelectionParams {
    textDocument: TextDocumentIdentifier;
    selections: Range[];
}

interface ExtendSelectionResult {
    selections: Range[];
}

export async function handle() {
    let editor = vscode.window.activeTextEditor
    if (editor == null || editor.document.languageId != "rust") return
    let request: ExtendSelectionParams = {
        textDocument: { uri: editor.document.uri.toString() },
        selections: editor.selections.map((s) => {
            return Server.client.code2ProtocolConverter.asRange(s)
        })
    }
    let response = await Server.client.sendRequest<ExtendSelectionResult>("m/extendSelection", request)
    editor.selections = response.selections.map((range: Range) => {
        let r = Server.client.protocol2CodeConverter.asRange(range)
        return new vscode.Selection(r.start, r.end)
    })
}