mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-10 20:36:23 +00:00
vscode: migrate on_enter to rust-analyzer-api.ts
This commit is contained in:
parent
56d1ff6532
commit
8c6581dcc3
1 changed files with 7 additions and 14 deletions
|
@ -1,7 +1,7 @@
|
||||||
import * as vscode from 'vscode';
|
import * as vscode from 'vscode';
|
||||||
import * as lc from 'vscode-languageclient';
|
import * as ra from '../rust-analyzer-api';
|
||||||
|
|
||||||
import { applySourceChange, SourceChange } from '../source_change';
|
import { applySourceChange } from '../source_change';
|
||||||
import { Cmd, Ctx } from '../ctx';
|
import { Cmd, Ctx } from '../ctx';
|
||||||
|
|
||||||
async function handleKeypress(ctx: Ctx) {
|
async function handleKeypress(ctx: Ctx) {
|
||||||
|
@ -10,22 +10,15 @@ async function handleKeypress(ctx: Ctx) {
|
||||||
|
|
||||||
if (!editor || !client) return false;
|
if (!editor || !client) return false;
|
||||||
|
|
||||||
const request: lc.TextDocumentPositionParams = {
|
const change = await client.sendRequest(ra.onEnter, {
|
||||||
textDocument: { uri: editor.document.uri.toString() },
|
textDocument: { uri: editor.document.uri.toString() },
|
||||||
position: client.code2ProtocolConverter.asPosition(
|
position: client.code2ProtocolConverter.asPosition(
|
||||||
editor.selection.active,
|
editor.selection.active,
|
||||||
),
|
),
|
||||||
};
|
}).catch(_error => {
|
||||||
const change = await client.sendRequest<undefined | SourceChange>(
|
|
||||||
'rust-analyzer/onEnter',
|
|
||||||
request,
|
|
||||||
).catch(
|
|
||||||
(_error: any) => {
|
|
||||||
// FIXME: switch to the more modern (?) typed request infrastructure
|
|
||||||
// client.logFailedRequest(OnEnterRequest.type, error);
|
// client.logFailedRequest(OnEnterRequest.type, error);
|
||||||
return Promise.resolve(null);
|
return null;
|
||||||
}
|
});
|
||||||
);
|
|
||||||
if (!change) return false;
|
if (!change) return false;
|
||||||
|
|
||||||
await applySourceChange(ctx, change);
|
await applySourceChange(ctx, change);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue