aboutsummaryrefslogtreecommitdiff
path: root/editors/code/src/commands/join_lines.ts
blob: 7b08c32550399e2978e8c5bb3505d93696d78762 (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
import * as lc from 'vscode-languageclient';

import { Ctx, Cmd } from '../ctx';
import { applySourceChange, SourceChange } from '../source_change';

export function joinLines(ctx: Ctx): Cmd {
    return async () => {
        const editor = ctx.activeRustEditor;
        const client = ctx.client;
        if (!editor || !client) return;

        const request: JoinLinesParams = {
            range: client.code2ProtocolConverter.asRange(editor.selection),
            textDocument: { uri: editor.document.uri.toString() },
        };
        const change = await client.sendRequest<SourceChange>(
            'rust-analyzer/joinLines',
            request,
        );
        await applySourceChange(ctx, change);
    };
}

interface JoinLinesParams {
    textDocument: lc.TextDocumentIdentifier;
    range: lc.Range;
}