From 76e170c3d0d0784c0e612c5849798c65a2034f29 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Mon, 25 May 2020 14:12:53 +0200 Subject: Less rust-analyzer specific onEnter --- editors/code/src/commands.ts | 10 +++++----- editors/code/src/rust-analyzer-api.ts | 3 +-- editors/code/src/snippets.ts | 3 +++ 3 files changed, 9 insertions(+), 7 deletions(-) (limited to 'editors') diff --git a/editors/code/src/commands.ts b/editors/code/src/commands.ts index 573af5aa5..e08030140 100644 --- a/editors/code/src/commands.ts +++ b/editors/code/src/commands.ts @@ -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; } diff --git a/editors/code/src/rust-analyzer-api.ts b/editors/code/src/rust-analyzer-api.ts index 900c5cd5b..c10c0fa78 100644 --- a/editors/code/src/rust-analyzer-api.ts +++ b/editors/code/src/rust-analyzer-api.ts @@ -67,8 +67,7 @@ export interface JoinLinesParams { } export const joinLines = new lc.RequestType('experimental/joinLines'); - -export const onEnter = request>("onEnter"); +export const onEnter = new lc.RequestType('experimental/onEnter'); export interface RunnablesParams { textDocument: lc.TextDocumentIdentifier; diff --git a/editors/code/src/snippets.ts b/editors/code/src/snippets.ts index 794530162..bcb3f2cc7 100644 --- a/editors/code/src/snippets.ts +++ b/editors/code/src/snippets.ts @@ -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) => { -- cgit v1.2.3