2018-10-09 16:00:20 +03:00
|
|
|
import * as lc from 'vscode-languageclient';
|
2018-10-09 22:56:15 +02:00
|
|
|
import {
|
2019-12-30 16:43:34 +01:00
|
|
|
applySourceChange,
|
2019-12-09 20:57:55 +02:00
|
|
|
SourceChange,
|
2019-12-30 16:43:34 +01:00
|
|
|
} from '../source_change';
|
|
|
|
|
import { Cmd, Ctx } from '../ctx';
|
2018-10-09 16:00:20 +03:00
|
|
|
|
2019-12-30 16:43:34 +01:00
|
|
|
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;
|
2018-10-09 16:00:20 +03:00
|
|
|
}
|
|
|
|
|
}
|