aboutsummaryrefslogtreecommitdiff
path: root/code
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2018-08-15 22:23:22 +0100
committerAleksey Kladov <[email protected]>2018-08-15 22:23:22 +0100
commitc631b585a7358d1569a051f2529ecaae222e95cd (patch)
tree2e8332d166900c29cf485297b8510451b97accd0 /code
parentaa0d344581dcfd7f18c595688a4b2709b0f2421e (diff)
matching brace
Diffstat (limited to 'code')
-rw-r--r--code/package.json5
-rw-r--r--code/src/extension.ts21
2 files changed, 26 insertions, 0 deletions
diff --git a/code/package.json b/code/package.json
index 8563ba73c..fd3b8e423 100644
--- a/code/package.json
+++ b/code/package.json
@@ -36,6 +36,11 @@
36 { 36 {
37 "command": "libsyntax-rust.extendSelection", 37 "command": "libsyntax-rust.extendSelection",
38 "title": "Rust Extend Selection" 38 "title": "Rust Extend Selection"
39 },
40 {
41 "command": "libsyntax-rust.matchingBrace",
42 "key": "ctrl+shift+m",
43 "title": "Rust Matching Brace"
39 } 44 }
40 ], 45 ],
41 "keybindings": [ 46 "keybindings": [
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
203interface FindMatchingBraceParams {
204 textDocument: lc.TextDocumentIdentifier;
205 offsets: lc.Position[];
206}
207
187interface PublishDecorationsParams { 208interface PublishDecorationsParams {
188 uri: string, 209 uri: string,
189 decorations: Decoration[], 210 decorations: Decoration[],