Files
rust/editors/code/src/commands/on_enter.ts

34 lines
957 B
TypeScript
Raw Normal View History

import * as vscode from 'vscode';
import * as lc from 'vscode-languageclient';
import { Server } from '../server';
import {
handle as applySourceChange,
2019-12-09 20:57:55 +02:00
SourceChange,
} from './apply_source_change';
export async function handle(event: { text: string }): Promise<boolean> {
const editor = vscode.window.activeTextEditor;
if (
editor == null ||
editor.document.languageId !== 'rust' ||
event.text !== '\n'
) {
return false;
}
const request: lc.TextDocumentPositionParams = {
textDocument: { uri: editor.document.uri.toString() },
position: Server.client.code2ProtocolConverter.asPosition(
2019-12-09 20:57:55 +02:00
editor.selection.active,
),
};
const change = await Server.client.sendRequest<undefined | SourceChange>(
2019-01-28 14:43:07 +03:00
'rust-analyzer/onEnter',
2019-12-09 20:57:55 +02:00
request,
);
if (!change) {
return false;
}
await applySourceChange(change);
return true;
}