aboutsummaryrefslogtreecommitdiff
path: root/editors/code/src/commands/join_lines.ts
blob: 0d4b12f4d856c86dc0343fa0297effd5975024e2 (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 { Range, TextDocumentIdentifier } from 'vscode-languageclient';
import { Server } from '../server';
import {
    handle as applySourceChange,
    SourceChange
} from './apply_source_change';

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

export async function handle() {
    const editor = vscode.window.activeTextEditor;
    if (editor == null || editor.document.languageId !== 'rust') {
        return;
    }
    const request: JoinLinesParams = {
        range: Server.client.code2ProtocolConverter.asRange(editor.selection),
        textDocument: { uri: editor.document.uri.toString() }
    };
    const change = await Server.client.sendRequest<SourceChange>(
        'rust-analyzer/joinLines',
        request
    );
    await applySourceChange(change);
}