diff options
author | bors[bot] <bors[bot]@users.noreply.github.com> | 2018-10-08 20:39:52 +0100 |
---|---|---|
committer | bors[bot] <bors[bot]@users.noreply.github.com> | 2018-10-08 20:39:52 +0100 |
commit | f4ad36e972989c3feed8671d6d6fca0aed37cd8f (patch) | |
tree | f60e1aa4703c3e176315ecd886206848028b8cbf /editors/code/src/commands/matching_brace.ts | |
parent | a05e09e9c514878148ddf26aa76d6b9183583d0f (diff) | |
parent | bbf38b9e722e8d6455828ff22242c92219da346d (diff) |
Merge #103
103: WIP: refactor vscode extension r=aochagavia a=aochagavia
Todo:
- [x] Add more comments, so other people can find their way in the codebase
- [x] Resolve remaining tslint suggestions
- [ ] Integrate with CI
@matklad The standard configuration of tslint forbids using `console.log` and `console.error`. Is there any reason we are using those or can I remove them? If they are used for debugging purposes I would prefer to remove them and rely on vscode's excellent debugger.
Co-authored-by: Adolfo OchagavĂa <[email protected]>
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..a80446a8f --- /dev/null +++ b/editors/code/src/commands/matching_brace.ts | |||
@@ -0,0 +1,27 @@ | |||
1 | import * as vscode from 'vscode'; | ||
2 | |||
3 | import { Position, TextDocumentIdentifier } 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 | const editor = vscode.window.activeTextEditor; | ||
13 | if (editor == null || editor.document.languageId !== 'rust') { return; } | ||
14 | const 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 | const response = await Server.client.sendRequest<Position[]>('m/findMatchingBrace', request); | ||
21 | editor.selections = editor.selections.map((sel, idx) => { | ||
22 | const active = Server.client.protocol2CodeConverter.asPosition(response[idx]); | ||
23 | const anchor = sel.isEmpty ? active : sel.anchor; | ||
24 | return new vscode.Selection(anchor, active); | ||
25 | }); | ||
26 | editor.revealRange(editor.selection); | ||
27 | } | ||