1 import * as vscode from 'vscode';
2 import * as lc from 'vscode-languageclient';
4 import { applySourceChange, SourceChange } from '../source_change';
5 import { Cmd, Ctx } from '../ctx';
7 async function handleKeypress(ctx: Ctx) {
8 const editor = ctx.activeRustEditor;
9 const client = ctx.client;
10 if (!editor) return false;
11 if (!client) return false;
13 const request: lc.TextDocumentPositionParams = {
14 textDocument: { uri: editor.document.uri.toString() },
15 position: client.code2ProtocolConverter.asPosition(
16 editor.selection.active,
19 const change = await client.sendRequest<undefined | SourceChange>(
20 'rust-analyzer/onEnter',
23 if (!change) return false;
25 await applySourceChange(ctx, change);
29 export function onEnter(ctx: Ctx): Cmd {
31 if (await handleKeypress(ctx)) return;
33 await vscode.commands.executeCommand('default:type', { text: '\n' });