diff options
Diffstat (limited to 'editors/code/src/commands/matching_brace.ts')
-rw-r--r-- | editors/code/src/commands/matching_brace.ts | 58 |
1 files changed, 30 insertions, 28 deletions
diff --git a/editors/code/src/commands/matching_brace.ts b/editors/code/src/commands/matching_brace.ts index 364208cc7..7c58bb7e7 100644 --- a/editors/code/src/commands/matching_brace.ts +++ b/editors/code/src/commands/matching_brace.ts | |||
@@ -1,34 +1,36 @@ | |||
1 | import * as vscode from 'vscode'; | 1 | import * as vscode from 'vscode'; |
2 | import * as lc from 'vscode-languageclient'; | ||
2 | 3 | ||
3 | import { Position, TextDocumentIdentifier } from 'vscode-languageclient'; | 4 | import { Ctx, Cmd } from '../ctx'; |
4 | import { Server } from '../server'; | ||
5 | 5 | ||
6 | interface FindMatchingBraceParams { | 6 | export function matchingBrace(ctx: Ctx): Cmd { |
7 | textDocument: TextDocumentIdentifier; | 7 | return async () => { |
8 | offsets: Position[]; | 8 | const editor = ctx.activeRustEditor; |
9 | } | 9 | const client = ctx.client; |
10 | if (!editor || !client) return; | ||
10 | 11 | ||
11 | export async function handle() { | 12 | const request: FindMatchingBraceParams = { |
12 | const editor = vscode.window.activeTextEditor; | 13 | textDocument: { uri: editor.document.uri.toString() }, |
13 | if (editor == null || editor.document.languageId !== 'rust') { | 14 | offsets: editor.selections.map(s => |
14 | return; | 15 | client.code2ProtocolConverter.asPosition(s.active), |
15 | } | 16 | ), |
16 | const request: FindMatchingBraceParams = { | 17 | }; |
17 | textDocument: { uri: editor.document.uri.toString() }, | 18 | const response = await client.sendRequest<lc.Position[]>( |
18 | offsets: editor.selections.map(s => { | 19 | 'rust-analyzer/findMatchingBrace', |
19 | return Server.client.code2ProtocolConverter.asPosition(s.active); | 20 | request, |
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 | ); | 21 | ); |
30 | const anchor = sel.isEmpty ? active : sel.anchor; | 22 | editor.selections = editor.selections.map((sel, idx) => { |
31 | return new vscode.Selection(anchor, active); | 23 | const active = client.protocol2CodeConverter.asPosition( |
32 | }); | 24 | response[idx], |
33 | editor.revealRange(editor.selection); | 25 | ); |
26 | const anchor = sel.isEmpty ? active : sel.anchor; | ||
27 | return new vscode.Selection(anchor, active); | ||
28 | }); | ||
29 | editor.revealRange(editor.selection); | ||
30 | }; | ||
31 | } | ||
32 | |||
33 | interface FindMatchingBraceParams { | ||
34 | textDocument: lc.TextDocumentIdentifier; | ||
35 | offsets: lc.Position[]; | ||
34 | } | 36 | } |