aboutsummaryrefslogtreecommitdiff
path: root/editors/code/src/commands/join_lines.ts
blob: f4f902cf96e89420f7575f0f3ae1377d8c5d5ec6 (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
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;
        if (!editor) return;

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

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