diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2020-05-21 19:05:58 +0100 |
---|---|---|
committer | GitHub <[email protected]> | 2020-05-21 19:05:58 +0100 |
commit | 59732df8d40dfadc6dcf5951265416576399712a (patch) | |
tree | 5accb5fce10496334b49ed5a823d321572b375b4 /editors/code/src | |
parent | ba6cf638fbf3d0a025e804f2d354d91abc8afd28 (diff) | |
parent | 5b5ebec440841ee98a0aa70b71a135d94f5ca077 (diff) |
Merge #4557
4557: Formalize JoinLines protocol extension r=matklad a=matklad
bors r+
🤖
Co-authored-by: Aleksey Kladov <[email protected]>
Diffstat (limited to 'editors/code/src')
-rw-r--r-- | editors/code/src/commands/join_lines.ts | 12 | ||||
-rw-r--r-- | editors/code/src/rust-analyzer-api.ts | 4 |
2 files changed, 10 insertions, 6 deletions
diff --git a/editors/code/src/commands/join_lines.ts b/editors/code/src/commands/join_lines.ts index de0614653..0bf1ee6e6 100644 --- a/editors/code/src/commands/join_lines.ts +++ b/editors/code/src/commands/join_lines.ts | |||
@@ -1,7 +1,7 @@ | |||
1 | import * as ra from '../rust-analyzer-api'; | 1 | import * as ra from '../rust-analyzer-api'; |
2 | import * as lc from 'vscode-languageclient'; | ||
2 | 3 | ||
3 | import { Ctx, Cmd } from '../ctx'; | 4 | import { Ctx, Cmd } from '../ctx'; |
4 | import { applySourceChange } from '../source_change'; | ||
5 | 5 | ||
6 | export function joinLines(ctx: Ctx): Cmd { | 6 | export function joinLines(ctx: Ctx): Cmd { |
7 | return async () => { | 7 | return async () => { |
@@ -9,10 +9,14 @@ export function joinLines(ctx: Ctx): Cmd { | |||
9 | const client = ctx.client; | 9 | const client = ctx.client; |
10 | if (!editor || !client) return; | 10 | if (!editor || !client) return; |
11 | 11 | ||
12 | const change = await client.sendRequest(ra.joinLines, { | 12 | const items: lc.TextEdit[] = await client.sendRequest(ra.joinLines, { |
13 | range: client.code2ProtocolConverter.asRange(editor.selection), | 13 | ranges: editor.selections.map((it) => client.code2ProtocolConverter.asRange(it)), |
14 | textDocument: { uri: editor.document.uri.toString() }, | 14 | textDocument: { uri: editor.document.uri.toString() }, |
15 | }); | 15 | }); |
16 | await applySourceChange(ctx, change); | 16 | editor.edit((builder) => { |
17 | client.protocol2CodeConverter.asTextEdits(items).forEach((edit) => { | ||
18 | builder.replace(edit.range, edit.newText); | ||
19 | }); | ||
20 | }); | ||
17 | }; | 21 | }; |
18 | } | 22 | } |
diff --git a/editors/code/src/rust-analyzer-api.ts b/editors/code/src/rust-analyzer-api.ts index 3b83b10e3..8ed56c173 100644 --- a/editors/code/src/rust-analyzer-api.ts +++ b/editors/code/src/rust-analyzer-api.ts | |||
@@ -64,9 +64,9 @@ export const parentModule = request<lc.TextDocumentPositionParams, Vec<lc.Locati | |||
64 | 64 | ||
65 | export interface JoinLinesParams { | 65 | export interface JoinLinesParams { |
66 | textDocument: lc.TextDocumentIdentifier; | 66 | textDocument: lc.TextDocumentIdentifier; |
67 | range: lc.Range; | 67 | ranges: lc.Range[]; |
68 | } | 68 | } |
69 | export const joinLines = request<JoinLinesParams, SourceChange>("joinLines"); | 69 | export const joinLines = new lc.RequestType<JoinLinesParams, lc.TextEdit[], unknown>('experimental/joinLines'); |
70 | 70 | ||
71 | 71 | ||
72 | export const onEnter = request<lc.TextDocumentPositionParams, Option<lc.WorkspaceEdit>>("onEnter"); | 72 | export const onEnter = request<lc.TextDocumentPositionParams, Option<lc.WorkspaceEdit>>("onEnter"); |