aboutsummaryrefslogtreecommitdiff
path: root/editors
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2020-05-25 13:12:53 +0100
committerAleksey Kladov <[email protected]>2020-05-25 13:28:47 +0100
commit76e170c3d0d0784c0e612c5849798c65a2034f29 (patch)
tree8cf69f49502a9f2b08d2d2975be79f54f9a04ccb /editors
parente4f91bfa578e57c1ef4be3343ebb4e8950e5dae6 (diff)
Less rust-analyzer specific onEnter
Diffstat (limited to 'editors')
-rw-r--r--editors/code/src/commands.ts10
-rw-r--r--editors/code/src/rust-analyzer-api.ts3
-rw-r--r--editors/code/src/snippets.ts3
3 files changed, 9 insertions, 7 deletions
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';
3import * as ra from './rust-analyzer-api'; 3import * as ra from './rust-analyzer-api';
4 4
5import { Ctx, Cmd } from './ctx'; 5import { Ctx, Cmd } from './ctx';
6import { applySnippetWorkspaceEdit } from './snippets'; 6import { applySnippetWorkspaceEdit, applySnippetTextEdits } from './snippets';
7import { spawnSync } from 'child_process'; 7import { spawnSync } from 'child_process';
8import { RunnableQuickPick, selectRunnable, createTask } from './run'; 8import { RunnableQuickPick, selectRunnable, createTask } from './run';
9import { AstInspector } from './ast_inspector'; 9import { AstInspector } from './ast_inspector';
@@ -102,7 +102,7 @@ export function onEnter(ctx: Ctx): Cmd {
102 102
103 if (!editor || !client) return false; 103 if (!editor || !client) return false;
104 104
105 const change = await client.sendRequest(ra.onEnter, { 105 const lcEdits = await client.sendRequest(ra.onEnter, {
106 textDocument: { uri: editor.document.uri.toString() }, 106 textDocument: { uri: editor.document.uri.toString() },
107 position: client.code2ProtocolConverter.asPosition( 107 position: client.code2ProtocolConverter.asPosition(
108 editor.selection.active, 108 editor.selection.active,
@@ -111,10 +111,10 @@ export function onEnter(ctx: Ctx): Cmd {
111 // client.logFailedRequest(OnEnterRequest.type, error); 111 // client.logFailedRequest(OnEnterRequest.type, error);
112 return null; 112 return null;
113 }); 113 });
114 if (!change) return false; 114 if (!lcEdits) return false;
115 115
116 const workspaceEdit = client.protocol2CodeConverter.asWorkspaceEdit(change); 116 const edits = client.protocol2CodeConverter.asTextEdits(lcEdits);
117 await applySnippetWorkspaceEdit(workspaceEdit); 117 await applySnippetTextEdits(editor, edits);
118 return true; 118 return true;
119 } 119 }
120 120
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 {
67} 67}
68export const joinLines = new lc.RequestType<JoinLinesParams, lc.TextEdit[], unknown>('experimental/joinLines'); 68export const joinLines = new lc.RequestType<JoinLinesParams, lc.TextEdit[], unknown>('experimental/joinLines');
69 69
70 70export const onEnter = new lc.RequestType<lc.TextDocumentPositionParams, lc.TextEdit[], unknown>('experimental/onEnter');
71export const onEnter = request<lc.TextDocumentPositionParams, Option<lc.WorkspaceEdit>>("onEnter");
72 71
73export interface RunnablesParams { 72export interface RunnablesParams {
74 textDocument: lc.TextDocumentIdentifier; 73 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) {
8 8
9 const editor = vscode.window.visibleTextEditors.find((it) => it.document.uri.toString() === uri.toString()); 9 const editor = vscode.window.visibleTextEditors.find((it) => it.document.uri.toString() === uri.toString());
10 if (!editor) return; 10 if (!editor) return;
11 await applySnippetTextEdits(editor, edits);
12}
11 13
14export async function applySnippetTextEdits(editor: vscode.TextEditor, edits: vscode.TextEdit[]) {
12 let selection: vscode.Selection | undefined = undefined; 15 let selection: vscode.Selection | undefined = undefined;
13 let lineDelta = 0; 16 let lineDelta = 0;
14 await editor.edit((builder) => { 17 await editor.edit((builder) => {