diff options
author | Adolfo OchagavĂa <[email protected]> | 2018-10-07 21:44:25 +0100 |
---|---|---|
committer | Adolfo OchagavĂa <[email protected]> | 2018-10-07 22:03:38 +0100 |
commit | 69de7e2fd71c3a808f0ac856d7b105eeb210f169 (patch) | |
tree | 62a163c43cb710cff18de6c7e8e47a81038ad1bb /editors/code/src/commands/matching_brace.ts | |
parent | e4fdfd15012c983e4555996aa466b57d787e4385 (diff) |
Refactor vscode extension
Diffstat (limited to 'editors/code/src/commands/matching_brace.ts')
-rw-r--r-- | editors/code/src/commands/matching_brace.ts | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/editors/code/src/commands/matching_brace.ts b/editors/code/src/commands/matching_brace.ts new file mode 100644 index 000000000..572c15ce8 --- /dev/null +++ b/editors/code/src/commands/matching_brace.ts | |||
@@ -0,0 +1,27 @@ | |||
1 | import * as vscode from 'vscode'; | ||
2 | |||
3 | import { TextDocumentIdentifier, Position } from "vscode-languageclient"; | ||
4 | import { Server } from '../server'; | ||
5 | |||
6 | interface FindMatchingBraceParams { | ||
7 | textDocument: TextDocumentIdentifier; | ||
8 | offsets: Position[]; | ||
9 | } | ||
10 | |||
11 | export async function handle() { | ||
12 | let editor = vscode.window.activeTextEditor | ||
13 | if (editor == null || editor.document.languageId != "rust") return | ||
14 | let request: FindMatchingBraceParams = { | ||
15 | textDocument: { uri: editor.document.uri.toString() }, | ||
16 | offsets: editor.selections.map((s) => { | ||
17 | return Server.client.code2ProtocolConverter.asPosition(s.active) | ||
18 | }) | ||
19 | } | ||
20 | let response = await Server.client.sendRequest<Position[]>("m/findMatchingBrace", request) | ||
21 | editor.selections = editor.selections.map((sel, idx) => { | ||
22 | let active = Server.client.protocol2CodeConverter.asPosition(response[idx]) | ||
23 | let anchor = sel.isEmpty ? active : sel.anchor | ||
24 | return new vscode.Selection(anchor, active) | ||
25 | }) | ||
26 | editor.revealRange(editor.selection) | ||
27 | }; | ||