mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-30 13:51:31 +00:00
Refactor applySourceChange
This commit is contained in:
parent
83d2527880
commit
5aebf1081d
7 changed files with 68 additions and 89 deletions
|
@ -1,33 +1,28 @@
|
|||
import * as vscode from 'vscode';
|
||||
import * as lc from 'vscode-languageclient';
|
||||
import { Server } from '../server';
|
||||
import {
|
||||
handle as applySourceChange,
|
||||
applySourceChange,
|
||||
SourceChange,
|
||||
} from './apply_source_change';
|
||||
} from '../source_change';
|
||||
import { Cmd, Ctx } from '../ctx';
|
||||
|
||||
export async function handle(event: { text: string }): Promise<boolean> {
|
||||
const editor = vscode.window.activeTextEditor;
|
||||
if (
|
||||
editor == null ||
|
||||
editor.document.languageId !== 'rust' ||
|
||||
event.text !== '\n'
|
||||
) {
|
||||
return false;
|
||||
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;
|
||||
}
|
||||
const request: lc.TextDocumentPositionParams = {
|
||||
textDocument: { uri: editor.document.uri.toString() },
|
||||
position: Server.client.code2ProtocolConverter.asPosition(
|
||||
editor.selection.active,
|
||||
),
|
||||
};
|
||||
const change = await Server.client.sendRequest<undefined | SourceChange>(
|
||||
'rust-analyzer/onEnter',
|
||||
request,
|
||||
);
|
||||
if (!change) {
|
||||
return false;
|
||||
}
|
||||
await applySourceChange(change);
|
||||
return true;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue