Skip to content
This repository has been archived by the owner on Apr 28, 2024. It is now read-only.

Commit

Permalink
v0.0.7 Macbook Touchbar button for error wrapping
Browse files Browse the repository at this point in the history
  • Loading branch information
neonxp committed Apr 3, 2021
1 parent 6c3aa1b commit c074656
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 4 deletions.
19 changes: 18 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down Expand Up @@ -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": {
Expand All @@ -59,5 +73,8 @@
"mocha": "^8.2.1",
"typescript": "^4.1.3",
"vscode-test": "^1.5.0"
},
"dependencies": {
"child_process": "^1.0.2"
}
}
6 changes: 5 additions & 1 deletion src/extension.ts
Original file line number Diff line number Diff line change
@@ -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(
Expand Down Expand Up @@ -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 [
Expand All @@ -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) {
Expand Down
5 changes: 3 additions & 2 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,12 @@
],
"sourceMap": true,
"rootDir": "src",
"strict": true /* enable all strict type-checking options */
"strict": false, /* 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": true
},
"exclude": [
"node_modules",
Expand Down

0 comments on commit c074656

Please sign in to comment.