mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-30 05:45:12 +00:00
25 lines
861 B
TypeScript
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;
|
|
};
|
|
}
|