mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-08-22 11:24:24 +00:00
Less rust-analyzer specific onEnter
This commit is contained in:
parent
e4f91bfa57
commit
76e170c3d0
11 changed files with 105 additions and 55 deletions
|
@ -3,7 +3,7 @@ import * as lc from 'vscode-languageclient';
|
|||
import * as ra from './rust-analyzer-api';
|
||||
|
||||
import { Ctx, Cmd } from './ctx';
|
||||
import { applySnippetWorkspaceEdit } from './snippets';
|
||||
import { applySnippetWorkspaceEdit, applySnippetTextEdits } from './snippets';
|
||||
import { spawnSync } from 'child_process';
|
||||
import { RunnableQuickPick, selectRunnable, createTask } from './run';
|
||||
import { AstInspector } from './ast_inspector';
|
||||
|
@ -102,7 +102,7 @@ export function onEnter(ctx: Ctx): Cmd {
|
|||
|
||||
if (!editor || !client) return false;
|
||||
|
||||
const change = await client.sendRequest(ra.onEnter, {
|
||||
const lcEdits = await client.sendRequest(ra.onEnter, {
|
||||
textDocument: { uri: editor.document.uri.toString() },
|
||||
position: client.code2ProtocolConverter.asPosition(
|
||||
editor.selection.active,
|
||||
|
@ -111,10 +111,10 @@ export function onEnter(ctx: Ctx): Cmd {
|
|||
// client.logFailedRequest(OnEnterRequest.type, error);
|
||||
return null;
|
||||
});
|
||||
if (!change) return false;
|
||||
if (!lcEdits) return false;
|
||||
|
||||
const workspaceEdit = client.protocol2CodeConverter.asWorkspaceEdit(change);
|
||||
await applySnippetWorkspaceEdit(workspaceEdit);
|
||||
const edits = client.protocol2CodeConverter.asTextEdits(lcEdits);
|
||||
await applySnippetTextEdits(editor, edits);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
@ -67,8 +67,7 @@ export interface JoinLinesParams {
|
|||
}
|
||||
export const joinLines = new lc.RequestType<JoinLinesParams, lc.TextEdit[], unknown>('experimental/joinLines');
|
||||
|
||||
|
||||
export const onEnter = request<lc.TextDocumentPositionParams, Option<lc.WorkspaceEdit>>("onEnter");
|
||||
export const onEnter = new lc.RequestType<lc.TextDocumentPositionParams, lc.TextEdit[], unknown>('experimental/onEnter');
|
||||
|
||||
export interface RunnablesParams {
|
||||
textDocument: lc.TextDocumentIdentifier;
|
||||
|
|
|
@ -8,7 +8,10 @@ export async function applySnippetWorkspaceEdit(edit: vscode.WorkspaceEdit) {
|
|||
|
||||
const editor = vscode.window.visibleTextEditors.find((it) => it.document.uri.toString() === uri.toString());
|
||||
if (!editor) return;
|
||||
await applySnippetTextEdits(editor, edits);
|
||||
}
|
||||
|
||||
export async function applySnippetTextEdits(editor: vscode.TextEditor, edits: vscode.TextEdit[]) {
|
||||
let selection: vscode.Selection | undefined = undefined;
|
||||
let lineDelta = 0;
|
||||
await editor.edit((builder) => {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue