blob: 59c253f8866db7a09e33d42619de35fb0b7b1c22 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
|
import * as vscode from 'vscode';
import * as lc from 'vscode-languageclient';
import { Ctx, Cmd } from '../ctx';
export function matchingBrace(ctx: Ctx): Cmd {
return async () => {
const editor = ctx.activeRustEditor;
if (!editor) {
return;
}
const request: FindMatchingBraceParams = {
textDocument: { uri: editor.document.uri.toString() },
offsets: editor.selections.map(s =>
ctx.client.code2ProtocolConverter.asPosition(s.active),
),
};
const response = await ctx.client.sendRequest<lc.Position[]>(
'rust-analyzer/findMatchingBrace',
request,
);
editor.selections = editor.selections.map((sel, idx) => {
const active = ctx.client.protocol2CodeConverter.asPosition(
response[idx],
);
const anchor = sel.isEmpty ? active : sel.anchor;
return new vscode.Selection(anchor, active);
});
editor.revealRange(editor.selection);
};
}
interface FindMatchingBraceParams {
textDocument: lc.TextDocumentIdentifier;
offsets: lc.Position[];
}
|