From c631b585a7358d1569a051f2529ecaae222e95cd Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Thu, 16 Aug 2018 00:23:22 +0300 Subject: matching brace --- code/src/extension.ts | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'code/src') 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) { return new vscode.Selection(r.start, r.end) }) }) + registerCommand('libsyntax-rust.matchingBrace', async () => { + let editor = vscode.window.activeTextEditor + if (editor == null || editor.document.languageId != "rust") return + let request: FindMatchingBraceParams = { + textDocument: { uri: editor.document.uri.toString() }, + offsets: editor.selections.map((s) => { + return client.code2ProtocolConverter.asPosition(s.active) + }) + } + let response = await client.sendRequest("m/findMatchingBrace", request) + editor.selections = editor.selections.map((sel, idx) => { + let active = client.protocol2CodeConverter.asPosition(response[idx]) + let anchor = sel.isEmpty ? active : sel.anchor + return new vscode.Selection(anchor, active) + }) + }) dispose(vscode.workspace.registerTextDocumentContentProvider( 'libsyntax-rust', @@ -184,6 +200,11 @@ interface ExtendSelectionResult { selections: lc.Range[]; } +interface FindMatchingBraceParams { + textDocument: lc.TextDocumentIdentifier; + offsets: lc.Position[]; +} + interface PublishDecorationsParams { uri: string, decorations: Decoration[], -- cgit v1.2.3