rust/editors/code/src/commands/join_lines.ts

30 lines
836 B
TypeScript
Raw Normal View History

2018-10-07 22:44:25 +02:00
import * as vscode from 'vscode';
2018-10-07 22:59:02 +02:00
import { Range, TextDocumentIdentifier } from 'vscode-languageclient';
2018-10-07 22:44:25 +02:00
import { Server } from '../server';
2018-10-08 23:38:33 +02:00
import {
handle as applySourceChange,
SourceChange
} from './apply_source_change';
2018-10-07 22:44:25 +02:00
interface JoinLinesParams {
textDocument: TextDocumentIdentifier;
range: Range;
}
export async function handle() {
2018-10-07 22:59:02 +02:00
const editor = vscode.window.activeTextEditor;
2018-10-08 23:38:33 +02:00
if (editor == null || editor.document.languageId !== 'rust') {
return;
}
2018-10-07 22:59:02 +02:00
const request: JoinLinesParams = {
2018-10-07 22:44:25 +02:00
range: Server.client.code2ProtocolConverter.asRange(editor.selection),
2018-10-08 23:38:33 +02:00
textDocument: { uri: editor.document.uri.toString() }
2018-10-07 22:59:02 +02:00
};
2018-10-08 23:38:33 +02:00
const change = await Server.client.sendRequest<SourceChange>(
'm/joinLines',
request
);
2018-10-07 22:59:02 +02:00
await applySourceChange(change);
2018-10-07 22:44:25 +02:00
}