diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2019-12-30 14:26:07 +0000 |
---|---|---|
committer | GitHub <[email protected]> | 2019-12-30 14:26:07 +0000 |
commit | 28ef2ea4f98e7e5c4e1df73e2e120dea7d279357 (patch) | |
tree | 12032141b5a113aca0a05ce2ebb3da55ce87f7f9 /editors/code/src/commands/matching_brace.ts | |
parent | 9cad88dd95773f9ede6233fd7d0f3a076c5cda61 (diff) | |
parent | 5dd9edaeafde3d5b5975cefe8dc1a65ccd9cd59f (diff) |
Merge #2687
2687: Move matching brace to new Ctx r=matklad a=matklad
Co-authored-by: Aleksey Kladov <[email protected]>
Diffstat (limited to 'editors/code/src/commands/matching_brace.ts')
-rw-r--r-- | editors/code/src/commands/matching_brace.ts | 53 |
1 files changed, 26 insertions, 27 deletions
diff --git a/editors/code/src/commands/matching_brace.ts b/editors/code/src/commands/matching_brace.ts index 364208cc7..665b0c33c 100644 --- a/editors/code/src/commands/matching_brace.ts +++ b/editors/code/src/commands/matching_brace.ts | |||
@@ -1,34 +1,33 @@ | |||
1 | import * as vscode from 'vscode'; | 1 | import * as vscode from 'vscode'; |
2 | |||
3 | import { Position, TextDocumentIdentifier } from 'vscode-languageclient'; | 2 | import { Position, TextDocumentIdentifier } from 'vscode-languageclient'; |
4 | import { Server } from '../server'; | 3 | import { Ctx, Cmd } from '../ctx'; |
4 | |||
5 | export function matchingBrace(ctx: Ctx): Cmd { | ||
6 | return async () => { | ||
7 | const editor = ctx.activeRustEditor; | ||
8 | if (!editor) { | ||
9 | return; | ||
10 | } | ||
11 | const request: FindMatchingBraceParams = { | ||
12 | textDocument: { uri: editor.document.uri.toString() }, | ||
13 | offsets: editor.selections.map(s => ctx.client.code2ProtocolConverter.asPosition(s.active)), | ||
14 | }; | ||
15 | const response = await ctx.client.sendRequest<Position[]>( | ||
16 | 'rust-analyzer/findMatchingBrace', | ||
17 | request, | ||
18 | ); | ||
19 | editor.selections = editor.selections.map((sel, idx) => { | ||
20 | const active = ctx.client.protocol2CodeConverter.asPosition( | ||
21 | response[idx], | ||
22 | ); | ||
23 | const anchor = sel.isEmpty ? active : sel.anchor; | ||
24 | return new vscode.Selection(anchor, active); | ||
25 | }); | ||
26 | editor.revealRange(editor.selection); | ||
27 | } | ||
28 | } | ||
5 | 29 | ||
6 | interface FindMatchingBraceParams { | 30 | interface FindMatchingBraceParams { |
7 | textDocument: TextDocumentIdentifier; | 31 | textDocument: TextDocumentIdentifier; |
8 | offsets: Position[]; | 32 | offsets: Position[]; |
9 | } | 33 | } |
10 | |||
11 | export async function handle() { | ||
12 | const editor = vscode.window.activeTextEditor; | ||
13 | if (editor == null || editor.document.languageId !== 'rust') { | ||
14 | return; | ||
15 | } | ||
16 | const request: FindMatchingBraceParams = { | ||
17 | textDocument: { uri: editor.document.uri.toString() }, | ||
18 | offsets: editor.selections.map(s => { | ||
19 | return Server.client.code2ProtocolConverter.asPosition(s.active); | ||
20 | }), | ||
21 | }; | ||
22 | const response = await Server.client.sendRequest<Position[]>( | ||
23 | 'rust-analyzer/findMatchingBrace', | ||
24 | request, | ||
25 | ); | ||
26 | editor.selections = editor.selections.map((sel, idx) => { | ||
27 | const active = Server.client.protocol2CodeConverter.asPosition( | ||
28 | response[idx], | ||
29 | ); | ||
30 | const anchor = sel.isEmpty ? active : sel.anchor; | ||
31 | return new vscode.Selection(anchor, active); | ||
32 | }); | ||
33 | editor.revealRange(editor.selection); | ||
34 | } | ||