1 import * as vscode from 'vscode';
2 import * as ra from '../rust-analyzer-api';
4 import { applySourceChange } 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;
11 if (!editor || !client) return false;
13 const change = await client.sendRequest(ra.onEnter, {
14 textDocument: { uri: editor.document.uri.toString() },
15 position: client.code2ProtocolConverter.asPosition(
16 editor.selection.active,
19 // client.logFailedRequest(OnEnterRequest.type, error);
22 if (!change) return false;
24 await applySourceChange(ctx, change);
28 export function onEnter(ctx: Ctx): Cmd {
30 if (await handleKeypress(ctx)) return;
32 await vscode.commands.executeCommand('default:type', { text: '\n' });