From 69de7e2fd71c3a808f0ac856d7b105eeb210f169 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adolfo=20Ochagav=C3=ADa?= Date: Sun, 7 Oct 2018 22:44:25 +0200 Subject: Refactor vscode extension --- editors/code/src/commands/matching_brace.ts | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 editors/code/src/commands/matching_brace.ts (limited to 'editors/code/src/commands/matching_brace.ts') 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 @@ +import * as vscode from 'vscode'; + +import { TextDocumentIdentifier, Position } from "vscode-languageclient"; +import { Server } from '../server'; + +interface FindMatchingBraceParams { + textDocument: TextDocumentIdentifier; + offsets: Position[]; +} + +export async function handle() { + 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 Server.client.code2ProtocolConverter.asPosition(s.active) + }) + } + let response = await Server.client.sendRequest("m/findMatchingBrace", request) + editor.selections = editor.selections.map((sel, idx) => { + let active = Server.client.protocol2CodeConverter.asPosition(response[idx]) + let anchor = sel.isEmpty ? active : sel.anchor + return new vscode.Selection(anchor, active) + }) + editor.revealRange(editor.selection) +}; -- cgit v1.2.3 From 4d62cfccbb8281f33b6f894df07e7316a9d45bfb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adolfo=20Ochagav=C3=ADa?= Date: Sun, 7 Oct 2018 22:59:02 +0200 Subject: Apply tslint suggestions, round one --- editors/code/src/commands/matching_brace.ts | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) (limited to 'editors/code/src/commands/matching_brace.ts') diff --git a/editors/code/src/commands/matching_brace.ts b/editors/code/src/commands/matching_brace.ts index 572c15ce8..cf7f6bf8f 100644 --- a/editors/code/src/commands/matching_brace.ts +++ b/editors/code/src/commands/matching_brace.ts @@ -1,6 +1,6 @@ import * as vscode from 'vscode'; -import { TextDocumentIdentifier, Position } from "vscode-languageclient"; +import { Position, TextDocumentIdentifier } from 'vscode-languageclient'; import { Server } from '../server'; interface FindMatchingBraceParams { @@ -9,19 +9,19 @@ interface FindMatchingBraceParams { } export async function handle() { - let editor = vscode.window.activeTextEditor - if (editor == null || editor.document.languageId != "rust") return - let request: FindMatchingBraceParams = { + const editor = vscode.window.activeTextEditor; + if (editor == null || editor.document.languageId != 'rust') { return; } + const request: FindMatchingBraceParams = { textDocument: { uri: editor.document.uri.toString() }, offsets: editor.selections.map((s) => { - return Server.client.code2ProtocolConverter.asPosition(s.active) - }) - } - let response = await Server.client.sendRequest("m/findMatchingBrace", request) + return Server.client.code2ProtocolConverter.asPosition(s.active); + }), + }; + const response = await Server.client.sendRequest('m/findMatchingBrace', request); editor.selections = editor.selections.map((sel, idx) => { - let active = Server.client.protocol2CodeConverter.asPosition(response[idx]) - let anchor = sel.isEmpty ? active : sel.anchor - return new vscode.Selection(anchor, active) - }) - editor.revealRange(editor.selection) -}; + const active = Server.client.protocol2CodeConverter.asPosition(response[idx]); + const anchor = sel.isEmpty ? active : sel.anchor; + return new vscode.Selection(anchor, active); + }); + editor.revealRange(editor.selection); +} -- cgit v1.2.3 From 62b1b05a0d9dd021f98352b6229e48e0d8b94f78 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adolfo=20Ochagav=C3=ADa?= Date: Mon, 8 Oct 2018 20:18:55 +0200 Subject: Fix remaining tslint suggestions --- editors/code/src/commands/matching_brace.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'editors/code/src/commands/matching_brace.ts') diff --git a/editors/code/src/commands/matching_brace.ts b/editors/code/src/commands/matching_brace.ts index cf7f6bf8f..a80446a8f 100644 --- a/editors/code/src/commands/matching_brace.ts +++ b/editors/code/src/commands/matching_brace.ts @@ -10,7 +10,7 @@ interface FindMatchingBraceParams { export async function handle() { const editor = vscode.window.activeTextEditor; - if (editor == null || editor.document.languageId != 'rust') { return; } + if (editor == null || editor.document.languageId !== 'rust') { return; } const request: FindMatchingBraceParams = { textDocument: { uri: editor.document.uri.toString() }, offsets: editor.selections.map((s) => { -- cgit v1.2.3