switch to official extend selection API

This commit is contained in:
Aleksey Kladov 2019-04-21 12:13:48 +03:00
parent 31b7697cf6
commit fa12ed2b8f
13 changed files with 89 additions and 63 deletions

View file

@ -1,34 +0,0 @@
import * as vscode from 'vscode';
import { Range, TextDocumentIdentifier } from 'vscode-languageclient';
import { Server } from '../server';
interface ExtendSelectionParams {
textDocument: TextDocumentIdentifier;
selections: Range[];
}
interface ExtendSelectionResult {
selections: Range[];
}
export async function handle() {
const editor = vscode.window.activeTextEditor;
if (editor == null || editor.document.languageId !== 'rust') {
return;
}
const request: ExtendSelectionParams = {
selections: editor.selections.map(s =>
Server.client.code2ProtocolConverter.asRange(s)
),
textDocument: { uri: editor.document.uri.toString() }
};
const response = await Server.client.sendRequest<ExtendSelectionResult>(
'rust-analyzer/extendSelection',
request
);
editor.selections = response.selections.map((range: Range) => {
const r = Server.client.protocol2CodeConverter.asRange(range);
return new vscode.Selection(r.start, r.end);
});
}

View file

@ -1,6 +1,5 @@
import * as analyzerStatus from './analyzer_status';
import * as applySourceChange from './apply_source_change';
import * as extendSelection from './extend_selection';
import * as joinLines from './join_lines';
import * as matchingBrace from './matching_brace';
import * as onEnter from './on_enter';
@ -11,7 +10,6 @@ import * as syntaxTree from './syntaxTree';
export {
analyzerStatus,
applySourceChange,
extendSelection,
joinLines,
matchingBrace,
parentModule,

View file

@ -57,10 +57,6 @@ export function activate(context: vscode.ExtensionContext) {
registerCommand('rust-analyzer.collectGarbage', () =>
Server.client.sendRequest<null>('rust-analyzer/collectGarbage', null)
);
registerCommand(
'rust-analyzer.extendSelection',
commands.extendSelection.handle
);
registerCommand(
'rust-analyzer.matchingBrace',
commands.matchingBrace.handle

View file

@ -74,6 +74,7 @@ export class Server {
}
}
};
Server.client.registerProposedFeatures();
Server.client.onReady().then(() => {
for (const [type, handler] of notificationHandlers) {
Server.client.onNotification(type, handler);