rust-analyzer/editors/code/src/commands/on_enter.ts
2019-12-30 19:07:59 +01:00

25 lines
861 B
TypeScript

import * as lc from 'vscode-languageclient';
import { applySourceChange, SourceChange } from '../source_change';
import { Cmd, Ctx } from '../ctx';
export function onEnter(ctx: Ctx): Cmd {
return async (event: { text: string }) => {
const editor = ctx.activeRustEditor;
if (!editor || event.text !== '\n') return false;
const request: lc.TextDocumentPositionParams = {
textDocument: { uri: editor.document.uri.toString() },
position: ctx.client.code2ProtocolConverter.asPosition(
editor.selection.active,
),
};
const change = await ctx.client.sendRequest<undefined | SourceChange>(
'rust-analyzer/onEnter',
request,
);
if (!change) return false;
await applySourceChange(ctx, change);
return true;
};
}