From 7818c08dc67c6916956c50e93e01e0a04010898b Mon Sep 17 00:00:00 2001 From: Alexander Kiryukhin Date: Sun, 4 Apr 2021 01:14:39 +0300 Subject: v0.0.7 Macbook Touchbar button for error wrapping --- src/extension.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/extension.ts b/src/extension.ts index 8afea4e..a60f216 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -1,6 +1,6 @@ import * as vscode from 'vscode'; -const fnRegex = /^\t*(.*)err\s?:=.+?$/ +const fnRegex = /^\t*(.*)err\s?:?=.+?$/ export function activate(context: vscode.ExtensionContext) { context.subscriptions.push( @@ -28,10 +28,13 @@ export class ErrorsWrapper implements vscode.CodeActionProvider { if (!editor) { return undefined; } + const line = document.lineAt(editor.selection.start.line); if (!fnRegex.test(line.text)) { + vscode.commands.executeCommand('setContext', 'allowWrapIferr', false); return undefined; } + vscode.commands.executeCommand('setContext', 'allowWrapIferr', true); const action = new vscode.CodeAction('Add error checking', vscode.CodeActionKind.RefactorRewrite); action.command = { command: 'gotools.wrap-error', title: 'Add error checking block', tooltip: '' }; return [ @@ -46,6 +49,7 @@ const wrapError = () => { return; } const document = editor.document; + const line = document.lineAt(editor.selection.start.line); const matches = line.text.match(fnRegex); if (matches == null || matches.length == 0) { -- cgit v1.2.3