aboutsummaryrefslogtreecommitdiff
path: root/src/extension.ts
diff options
context:
space:
mode:
Diffstat (limited to 'src/extension.ts')
-rw-r--r--src/extension.ts6
1 files changed, 5 insertions, 1 deletions
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) {