v0.0.7 Macbook Touchbar button for error wrapping
This commit is contained in:
parent
6c3aa1bf76
commit
7818c08dc6
4 changed files with 24 additions and 4 deletions
1
.github/workflows/publish.yml
vendored
1
.github/workflows/publish.yml
vendored
|
@ -1,5 +1,6 @@
|
||||||
on:
|
on:
|
||||||
release:
|
release:
|
||||||
|
push:
|
||||||
name: Deploy Extension
|
name: Deploy Extension
|
||||||
jobs:
|
jobs:
|
||||||
deploy:
|
deploy:
|
||||||
|
|
16
package.json
16
package.json
|
@ -2,7 +2,7 @@
|
||||||
"name": "gotools",
|
"name": "gotools",
|
||||||
"displayName": "Golang Tools",
|
"displayName": "Golang Tools",
|
||||||
"description": "Tools for productive work",
|
"description": "Tools for productive work",
|
||||||
"version": "0.0.6",
|
"version": "0.0.7",
|
||||||
"publisher": "neonxp",
|
"publisher": "neonxp",
|
||||||
"license": "GPL-3.0-or-later",
|
"license": "GPL-3.0-or-later",
|
||||||
"author": {
|
"author": {
|
||||||
|
@ -37,6 +37,20 @@
|
||||||
"language": "go",
|
"language": "go",
|
||||||
"path": "./snippets/snippets.json"
|
"path": "./snippets/snippets.json"
|
||||||
}
|
}
|
||||||
|
],
|
||||||
|
"menus": {
|
||||||
|
"touchBar": [
|
||||||
|
{
|
||||||
|
"command": "gotools.wrap-error",
|
||||||
|
"when": "allowWrapIferr"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"commands": [
|
||||||
|
{
|
||||||
|
"command": "gotools.wrap-error",
|
||||||
|
"title": "if err≠nil {...}"
|
||||||
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
import * as vscode from 'vscode';
|
import * as vscode from 'vscode';
|
||||||
|
|
||||||
const fnRegex = /^\t*(.*)err\s?:=.+?$/
|
const fnRegex = /^\t*(.*)err\s?:?=.+?$/
|
||||||
|
|
||||||
export function activate(context: vscode.ExtensionContext) {
|
export function activate(context: vscode.ExtensionContext) {
|
||||||
context.subscriptions.push(
|
context.subscriptions.push(
|
||||||
|
@ -28,10 +28,13 @@ export class ErrorsWrapper implements vscode.CodeActionProvider {
|
||||||
if (!editor) {
|
if (!editor) {
|
||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
const line = document.lineAt(editor.selection.start.line);
|
const line = document.lineAt(editor.selection.start.line);
|
||||||
if (!fnRegex.test(line.text)) {
|
if (!fnRegex.test(line.text)) {
|
||||||
|
vscode.commands.executeCommand('setContext', 'allowWrapIferr', false);
|
||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
|
vscode.commands.executeCommand('setContext', 'allowWrapIferr', true);
|
||||||
const action = new vscode.CodeAction('Add error checking', vscode.CodeActionKind.RefactorRewrite);
|
const action = new vscode.CodeAction('Add error checking', vscode.CodeActionKind.RefactorRewrite);
|
||||||
action.command = { command: 'gotools.wrap-error', title: 'Add error checking block', tooltip: '' };
|
action.command = { command: 'gotools.wrap-error', title: 'Add error checking block', tooltip: '' };
|
||||||
return [
|
return [
|
||||||
|
@ -46,6 +49,7 @@ const wrapError = () => {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const document = editor.document;
|
const document = editor.document;
|
||||||
|
|
||||||
const line = document.lineAt(editor.selection.start.line);
|
const line = document.lineAt(editor.selection.start.line);
|
||||||
const matches = line.text.match(fnRegex);
|
const matches = line.text.match(fnRegex);
|
||||||
if (matches == null || matches.length == 0) {
|
if (matches == null || matches.length == 0) {
|
||||||
|
|
|
@ -8,11 +8,12 @@
|
||||||
],
|
],
|
||||||
"sourceMap": true,
|
"sourceMap": true,
|
||||||
"rootDir": "src",
|
"rootDir": "src",
|
||||||
"strict": true /* enable all strict type-checking options */
|
"strict": true, /* enable all strict type-checking options */
|
||||||
/* Additional Checks */
|
/* Additional Checks */
|
||||||
// "noImplicitReturns": true, /* Report error when not all code paths in function return a value. */
|
// "noImplicitReturns": true, /* Report error when not all code paths in function return a value. */
|
||||||
// "noFallthroughCasesInSwitch": true, /* Report errors for fallthrough cases in switch statement. */
|
// "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": [
|
"exclude": [
|
||||||
"node_modules",
|
"node_modules",
|
||||||
|
|
Loading…
Reference in a new issue