diff options
author | Alexander Kiryukhin <a.kiryukhin@mail.ru> | 2021-04-04 01:14:39 +0300 |
---|---|---|
committer | Alexander Kiryukhin <a.kiryukhin@mail.ru> | 2021-04-04 01:52:27 +0300 |
commit | 7818c08dc67c6916956c50e93e01e0a04010898b (patch) | |
tree | 887b70a35772c9165f696a7497267d234ee4f041 /src/extension.ts | |
parent | 6c3aa1bf769f3f161e3fc60560c605c38e9f2c6b (diff) |
v0.0.7 Macbook Touchbar button for error wrapping
Diffstat (limited to 'src/extension.ts')
-rw-r--r-- | src/extension.ts | 6 |
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) { |