aboutsummaryrefslogtreecommitdiff
path: root/editors/code/src/commands/on_enter.ts
blob: bb376e3cb41a02c7e51875cf25a4d8da5df34573 (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
30
31
32
33
import * as vscode from 'vscode';
import * as lc from 'vscode-languageclient';
import { Server } from '../server';
import {
    handle as applySourceChange,
    SourceChange
} from './apply_source_change';

export async function handle(event: { text: string }): Promise<boolean> {
    const editor = vscode.window.activeTextEditor;
    if (
        editor == null ||
        editor.document.languageId !== 'rust' ||
        event.text !== '\n'
    ) {
        return false;
    }
    const request: lc.TextDocumentPositionParams = {
        textDocument: { uri: editor.document.uri.toString() },
        position: Server.client.code2ProtocolConverter.asPosition(
            editor.selection.active
        )
    };
    const change = await Server.client.sendRequest<undefined | SourceChange>(
        'm/onEnter',
        request
    );
    if (!change) {
        return false;
    }
    await applySourceChange(change);
    return true;
}