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

35 lines
1 KiB
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';
interface ExtendSelectionParams {
textDocument: TextDocumentIdentifier;
selections: Range[];
}
interface ExtendSelectionResult {
selections: 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: ExtendSelectionParams = {
2018-10-08 23:38:33 +02:00
selections: editor.selections.map(s => {
2018-10-07 22:59:02 +02:00
return Server.client.code2ProtocolConverter.asRange(s);
}),
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 response = await Server.client.sendRequest<ExtendSelectionResult>(
'm/extendSelection',
request
);
2018-10-07 22:44:25 +02:00
editor.selections = response.selections.map((range: Range) => {
2018-10-07 22:59:02 +02:00
const r = Server.client.protocol2CodeConverter.asRange(range);
return new vscode.Selection(r.start, r.end);
});
2018-10-07 22:44:25 +02:00
}