From 7818c08dc67c6916956c50e93e01e0a04010898b Mon Sep 17 00:00:00 2001 From: Alexander Kiryukhin Date: Sun, 4 Apr 2021 01:14:39 +0300 Subject: [PATCH] v0.0.7 Macbook Touchbar button for error wrapping --- .github/workflows/publish.yml | 1 + package.json | 16 +++++++++++++++- src/extension.ts | 6 +++++- tsconfig.json | 5 +++-- 4 files changed, 24 insertions(+), 4 deletions(-) diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index e5582e0..5801575 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -1,5 +1,6 @@ on: release: + push: name: Deploy Extension jobs: deploy: diff --git a/package.json b/package.json index 7a804bb..a73e01c 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "gotools", "displayName": "Golang Tools", "description": "Tools for productive work", - "version": "0.0.6", + "version": "0.0.7", "publisher": "neonxp", "license": "GPL-3.0-or-later", "author": { @@ -37,6 +37,20 @@ "language": "go", "path": "./snippets/snippets.json" } + ], + "menus": { + "touchBar": [ + { + "command": "gotools.wrap-error", + "when": "allowWrapIferr" + } + ] + }, + "commands": [ + { + "command": "gotools.wrap-error", + "title": "if err≠nil {...}" + } ] }, "scripts": { 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) { diff --git a/tsconfig.json b/tsconfig.json index df5ac7f..622cc91 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -8,11 +8,12 @@ ], "sourceMap": true, "rootDir": "src", - "strict": true /* enable all strict type-checking options */ + "strict": true, /* enable all strict type-checking options */ /* Additional Checks */ // "noImplicitReturns": true, /* Report error when not all code paths in function return a value. */ // "noFallthroughCasesInSwitch": true, /* Report errors for fallthrough cases in switch statement. */ - // "noUnusedParameters": true, /* Report errors on unused parameters. */ + // "noUnusedParameters": true, /* Report errors on unused parameters. */, + "allowJs": false }, "exclude": [ "node_modules",