diff options
author | Aleksey Kladov <[email protected]> | 2018-08-15 22:23:22 +0100 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2018-08-15 22:23:22 +0100 |
commit | c631b585a7358d1569a051f2529ecaae222e95cd (patch) | |
tree | 2e8332d166900c29cf485297b8510451b97accd0 /code/src/extension.ts | |
parent | aa0d344581dcfd7f18c595688a4b2709b0f2421e (diff) |
matching brace
Diffstat (limited to 'code/src/extension.ts')
-rw-r--r-- | code/src/extension.ts | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/code/src/extension.ts b/code/src/extension.ts index bb724539d..afcbccf63 100644 --- a/code/src/extension.ts +++ b/code/src/extension.ts | |||
@@ -35,6 +35,22 @@ export function activate(context: vscode.ExtensionContext) { | |||
35 | return new vscode.Selection(r.start, r.end) | 35 | return new vscode.Selection(r.start, r.end) |
36 | }) | 36 | }) |
37 | }) | 37 | }) |
38 | registerCommand('libsyntax-rust.matchingBrace', async () => { | ||
39 | let editor = vscode.window.activeTextEditor | ||
40 | if (editor == null || editor.document.languageId != "rust") return | ||
41 | let request: FindMatchingBraceParams = { | ||
42 | textDocument: { uri: editor.document.uri.toString() }, | ||
43 | offsets: editor.selections.map((s) => { | ||
44 | return client.code2ProtocolConverter.asPosition(s.active) | ||
45 | }) | ||
46 | } | ||
47 | let response = await client.sendRequest<lc.Position[]>("m/findMatchingBrace", request) | ||
48 | editor.selections = editor.selections.map((sel, idx) => { | ||
49 | let active = client.protocol2CodeConverter.asPosition(response[idx]) | ||
50 | let anchor = sel.isEmpty ? active : sel.anchor | ||
51 | return new vscode.Selection(anchor, active) | ||
52 | }) | ||
53 | }) | ||
38 | 54 | ||
39 | dispose(vscode.workspace.registerTextDocumentContentProvider( | 55 | dispose(vscode.workspace.registerTextDocumentContentProvider( |
40 | 'libsyntax-rust', | 56 | 'libsyntax-rust', |
@@ -184,6 +200,11 @@ interface ExtendSelectionResult { | |||
184 | selections: lc.Range[]; | 200 | selections: lc.Range[]; |
185 | } | 201 | } |
186 | 202 | ||
203 | interface FindMatchingBraceParams { | ||
204 | textDocument: lc.TextDocumentIdentifier; | ||
205 | offsets: lc.Position[]; | ||
206 | } | ||
207 | |||
187 | interface PublishDecorationsParams { | 208 | interface PublishDecorationsParams { |
188 | uri: string, | 209 | uri: string, |
189 | decorations: Decoration[], | 210 | decorations: Decoration[], |