v0.0.2
This commit is contained in:
parent
7707ba49f6
commit
ff66c26ad4
16 changed files with 2250 additions and 88 deletions
23
.eslintrc.js
23
.eslintrc.js
|
@ -1,23 +0,0 @@
|
|||
/**@type {import('eslint').Linter.Config} */
|
||||
// eslint-disable-next-line no-undef
|
||||
module.exports = {
|
||||
root: true,
|
||||
parser: '@typescript-eslint/parser',
|
||||
plugins: [
|
||||
'@typescript-eslint',
|
||||
],
|
||||
extends: [
|
||||
'eslint:recommended',
|
||||
'plugin:@typescript-eslint/recommended',
|
||||
],
|
||||
rules: {
|
||||
'semi': [
|
||||
2,
|
||||
"always"
|
||||
],
|
||||
'@typescript-eslint/no-unused-vars': 0,
|
||||
'@typescript-eslint/no-explicit-any': 0,
|
||||
'@typescript-eslint/explicit-module-boundary-types': 0,
|
||||
'@typescript-eslint/no-non-null-assertion': 0,
|
||||
}
|
||||
};
|
19
.eslintrc.json
Normal file
19
.eslintrc.json
Normal file
|
@ -0,0 +1,19 @@
|
|||
{
|
||||
"root": true,
|
||||
"parser": "@typescript-eslint/parser",
|
||||
"parserOptions": {
|
||||
"ecmaVersion": 6,
|
||||
"sourceType": "module"
|
||||
},
|
||||
"plugins": [
|
||||
"@typescript-eslint"
|
||||
],
|
||||
"rules": {
|
||||
"@typescript-eslint/naming-convention": "warn",
|
||||
"@typescript-eslint/semi": "warn",
|
||||
"curly": "warn",
|
||||
"eqeqeq": "warn",
|
||||
"no-throw-literal": "warn",
|
||||
"semi": "off"
|
||||
}
|
||||
}
|
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
|
@ -0,0 +1,2 @@
|
|||
node_modules
|
||||
out
|
8
.vscode/extensions.json
vendored
8
.vscode/extensions.json
vendored
|
@ -1,5 +1,7 @@
|
|||
{
|
||||
"recommendations": [
|
||||
"dbaeumer.vscode-eslint"
|
||||
]
|
||||
// See http://go.microsoft.com/fwlink/?LinkId=827846
|
||||
// for the documentation about the extensions.json format
|
||||
"recommendations": [
|
||||
"dbaeumer.vscode-eslint"
|
||||
]
|
||||
}
|
||||
|
|
44
.vscode/launch.json
vendored
44
.vscode/launch.json
vendored
|
@ -1,14 +1,34 @@
|
|||
// A launch configuration that compiles the extension and then opens it inside a new window
|
||||
// Use IntelliSense to learn about possible attributes.
|
||||
// Hover to view descriptions of existing attributes.
|
||||
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
|
||||
{
|
||||
"version": "0.2.0",
|
||||
"configurations": [
|
||||
{
|
||||
"name": "Run Extension",
|
||||
"type": "extensionHost",
|
||||
"request": "launch",
|
||||
"runtimeExecutable": "${execPath}",
|
||||
"args": [
|
||||
"--extensionDevelopmentPath=${workspaceFolder}"
|
||||
]
|
||||
}
|
||||
]
|
||||
"version": "0.2.0",
|
||||
"configurations": [
|
||||
{
|
||||
"name": "Run Extension",
|
||||
"type": "extensionHost",
|
||||
"request": "launch",
|
||||
"args": [
|
||||
"--extensionDevelopmentPath=${workspaceFolder}"
|
||||
],
|
||||
"outFiles": [
|
||||
"${workspaceFolder}/out/**/*.js"
|
||||
],
|
||||
"preLaunchTask": "${defaultBuildTask}"
|
||||
},
|
||||
{
|
||||
"name": "Extension Tests",
|
||||
"type": "extensionHost",
|
||||
"request": "launch",
|
||||
"args": [
|
||||
"--extensionDevelopmentPath=${workspaceFolder}",
|
||||
"--extensionTestsPath=${workspaceFolder}/out/test/suite/index"
|
||||
],
|
||||
"outFiles": [
|
||||
"${workspaceFolder}/out/test/**/*.js"
|
||||
],
|
||||
"preLaunchTask": "${defaultBuildTask}"
|
||||
}
|
||||
]
|
||||
}
|
||||
|
|
10
.vscode/settings.json
vendored
10
.vscode/settings.json
vendored
|
@ -1,3 +1,11 @@
|
|||
// Place your settings in this file to overwrite default and user settings.
|
||||
{
|
||||
"editor.insertSpaces": false
|
||||
"files.exclude": {
|
||||
"out": false // set this to true to hide the "out" folder with the compiled JS files
|
||||
},
|
||||
"search.exclude": {
|
||||
"out": true // set this to false to include "out" folder in search results
|
||||
},
|
||||
// Turn off tsc task auto detection since we have the necessary tasks as npm scripts
|
||||
"typescript.tsc.autoDetect": "off"
|
||||
}
|
11
.vscodeignore
Normal file
11
.vscodeignore
Normal file
|
@ -0,0 +1,11 @@
|
|||
.vscode/**
|
||||
.vscode-test/**
|
||||
out/test/**
|
||||
src/**
|
||||
.gitignore
|
||||
.yarnrc
|
||||
vsc-extension-quickstart.md
|
||||
**/tsconfig.json
|
||||
**/.eslintrc.json
|
||||
**/*.map
|
||||
**/*.ts
|
|
@ -12,9 +12,6 @@ Extension in active development! Your contribution is always welcome :)
|
|||
| Prefix| Description | Example |
|
||||
| :---- |:-----------:| -------:|
|
||||
| `pkg` | Package header line | `package test` |
|
||||
| `tyi` | Type interface declaration | ```type test interface { }``` |
|
||||
| `tys` | Type structure declaration | ```type test struct { }``` |
|
||||
| `construct` | Constructor for structure type | see in action |
|
||||
| `var` | Variable with type and value | `var test string = "hello"` |
|
||||
| `stack` | Stack from array of types | see in action |
|
||||
|
||||
|
|
1963
package-lock.json
generated
Normal file
1963
package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load diff
87
package.json
87
package.json
|
@ -1,29 +1,62 @@
|
|||
{
|
||||
"name": "gotools",
|
||||
"displayName": "Golang snippets",
|
||||
"description": "Snippets for productive work",
|
||||
"version": "0.0.1",
|
||||
"publisher": "neonxp",
|
||||
"engines": {
|
||||
"vscode": "^1.28.0"
|
||||
},
|
||||
"icon": "icon.png",
|
||||
"categories": [
|
||||
"Snippets"
|
||||
],
|
||||
"contributes": {
|
||||
"snippets": [
|
||||
{
|
||||
"language": "go",
|
||||
"path": "./snippets.json"
|
||||
}
|
||||
]
|
||||
},
|
||||
"scripts": {
|
||||
"build": "vsce package"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/neonxp/GoTools"
|
||||
}
|
||||
"name": "gotools",
|
||||
"displayName": "Golang tools",
|
||||
"description": "Tools for productive work",
|
||||
"version": "0.0.2",
|
||||
"publisher": "neonxp",
|
||||
"author": {
|
||||
"name": "Alexander NeonXP Kiryukhin",
|
||||
"email": "a.kiryukhin@mail.ru",
|
||||
"url": "https://neonxp.ru/"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/neonxp/GoTools"
|
||||
},
|
||||
"icon": "icon.png",
|
||||
"categories": [
|
||||
"Programming Languages",
|
||||
"Snippets",
|
||||
"Other"
|
||||
],
|
||||
"keywords": [
|
||||
"go",
|
||||
"golang"
|
||||
],
|
||||
"engines": {
|
||||
"vscode": "^1.54.0"
|
||||
},
|
||||
"main": "./out/extension.js",
|
||||
"activationEvents": [
|
||||
"onLanguage:go"
|
||||
],
|
||||
"contributes": {
|
||||
"snippets": [
|
||||
{
|
||||
"language": "go",
|
||||
"path": "./snippets/snippets.json"
|
||||
}
|
||||
]
|
||||
},
|
||||
"scripts": {
|
||||
"vscode:prepublish": "npm run compile",
|
||||
"compile": "tsc -p ./",
|
||||
"watch": "tsc -watch -p ./",
|
||||
"pretest": "npm run compile && npm run lint",
|
||||
"lint": "eslint src --ext ts",
|
||||
"test": "node ./out/test/runTest.js"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/vscode": "^1.54.0",
|
||||
"@types/glob": "^7.1.3",
|
||||
"@types/mocha": "^8.0.4",
|
||||
"@types/node": "^12.11.7",
|
||||
"eslint": "^7.19.0",
|
||||
"@typescript-eslint/eslint-plugin": "^4.14.1",
|
||||
"@typescript-eslint/parser": "^4.14.1",
|
||||
"glob": "^7.1.6",
|
||||
"mocha": "^8.2.1",
|
||||
"typescript": "^4.1.3",
|
||||
"vscode-test": "^1.5.0"
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,13 +1,4 @@
|
|||
{
|
||||
"Interface declaration": {
|
||||
"body": [
|
||||
"type $1 interface {",
|
||||
"\t$0",
|
||||
"}"
|
||||
],
|
||||
"description": "go interface type",
|
||||
"prefix": "tyi"
|
||||
},
|
||||
"Package line": {
|
||||
"body": [
|
||||
"package ${TM_DIRECTORY/.+\\/(.+)$/${1:/downcase}/}",
|
||||
|
@ -48,15 +39,6 @@
|
|||
"description": "constructor for structure type",
|
||||
"prefix": "construct"
|
||||
},
|
||||
"Structure declaration": {
|
||||
"body": [
|
||||
"type $1 struct {",
|
||||
"\t$0",
|
||||
"}"
|
||||
],
|
||||
"description": "strucutre type",
|
||||
"prefix": "tys"
|
||||
},
|
||||
"Variable declaration": {
|
||||
"body": "var $1 $2 = $3",
|
||||
"description": "variable with type and value",
|
51
src/extension.ts
Normal file
51
src/extension.ts
Normal file
|
@ -0,0 +1,51 @@
|
|||
// The module 'vscode' contains the VS Code extensibility API
|
||||
// Import the module and reference it with the alias vscode in your code below
|
||||
import * as vscode from 'vscode';
|
||||
|
||||
// this method is called when your extension is activated
|
||||
// your extension is activated the very first time the command is executed
|
||||
export function activate(context: vscode.ExtensionContext) {
|
||||
context.subscriptions.push(vscode.languages.registerCodeActionsProvider('go', new ErrorsWrapper(), {
|
||||
providedCodeActionKinds: ErrorsWrapper.providedCodeActionKinds
|
||||
}));
|
||||
context.subscriptions.push(
|
||||
vscode.commands.registerCommand('gotools.wrap-error', () => {
|
||||
const editor = vscode.window.activeTextEditor;
|
||||
|
||||
if (editor) {
|
||||
const document = editor.document;
|
||||
const selection = editor.selection;
|
||||
const line = document.lineAt(editor.selection.start.line)
|
||||
const idx = line.firstNonWhitespaceCharacterIndex
|
||||
const word = document.getText(selection);
|
||||
const space = "\t".repeat(idx)
|
||||
let errPrefix = ""
|
||||
if (word.indexOf("=") == -1) {
|
||||
errPrefix = "err :="
|
||||
}
|
||||
editor.edit(editBuilder => {
|
||||
editBuilder.replace(selection, `if ${errPrefix}${word}; err != nil {\n${space}\rreturn err\n${space}}`);
|
||||
});
|
||||
}
|
||||
})
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
// this method is called when your extension is deactivated
|
||||
export function deactivate() { }
|
||||
|
||||
export class ErrorsWrapper implements vscode.CodeActionProvider {
|
||||
|
||||
public static readonly providedCodeActionKinds = [
|
||||
vscode.CodeActionKind.RefactorRewrite
|
||||
];
|
||||
|
||||
public provideCodeActions(document: vscode.TextDocument, range: vscode.Range): vscode.CodeAction[] | undefined {
|
||||
const action = new vscode.CodeAction('Wrap error', vscode.CodeActionKind.RefactorRewrite);
|
||||
action.command = { command: 'gotools.wrap-error', title: 'Wrap with error block', tooltip: '' };
|
||||
return [
|
||||
action
|
||||
]
|
||||
}
|
||||
}
|
23
src/test/runTest.ts
Normal file
23
src/test/runTest.ts
Normal file
|
@ -0,0 +1,23 @@
|
|||
import * as path from 'path';
|
||||
|
||||
import { runTests } from 'vscode-test';
|
||||
|
||||
async function main() {
|
||||
try {
|
||||
// The folder containing the Extension Manifest package.json
|
||||
// Passed to `--extensionDevelopmentPath`
|
||||
const extensionDevelopmentPath = path.resolve(__dirname, '../../');
|
||||
|
||||
// The path to test runner
|
||||
// Passed to --extensionTestsPath
|
||||
const extensionTestsPath = path.resolve(__dirname, './suite/index');
|
||||
|
||||
// Download VS Code, unzip it and run the integration test
|
||||
await runTests({ extensionDevelopmentPath, extensionTestsPath });
|
||||
} catch (err) {
|
||||
console.error('Failed to run tests');
|
||||
process.exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
main();
|
15
src/test/suite/extension.test.ts
Normal file
15
src/test/suite/extension.test.ts
Normal file
|
@ -0,0 +1,15 @@
|
|||
import * as assert from 'assert';
|
||||
|
||||
// You can import and use all API from the 'vscode' module
|
||||
// as well as import your extension to test it
|
||||
import * as vscode from 'vscode';
|
||||
// import * as myExtension from '../../extension';
|
||||
|
||||
suite('Extension Test Suite', () => {
|
||||
vscode.window.showInformationMessage('Start all tests.');
|
||||
|
||||
test('Sample test', () => {
|
||||
assert.strictEqual(-1, [1, 2, 3].indexOf(5));
|
||||
assert.strictEqual(-1, [1, 2, 3].indexOf(0));
|
||||
});
|
||||
});
|
38
src/test/suite/index.ts
Normal file
38
src/test/suite/index.ts
Normal file
|
@ -0,0 +1,38 @@
|
|||
import * as path from 'path';
|
||||
import * as Mocha from 'mocha';
|
||||
import * as glob from 'glob';
|
||||
|
||||
export function run(): Promise<void> {
|
||||
// Create the mocha test
|
||||
const mocha = new Mocha({
|
||||
ui: 'tdd',
|
||||
color: true
|
||||
});
|
||||
|
||||
const testsRoot = path.resolve(__dirname, '..');
|
||||
|
||||
return new Promise((c, e) => {
|
||||
glob('**/**.test.js', { cwd: testsRoot }, (err, files) => {
|
||||
if (err) {
|
||||
return e(err);
|
||||
}
|
||||
|
||||
// Add files to the test suite
|
||||
files.forEach(f => mocha.addFile(path.resolve(testsRoot, f)));
|
||||
|
||||
try {
|
||||
// Run the mocha test
|
||||
mocha.run(failures => {
|
||||
if (failures > 0) {
|
||||
e(new Error(`${failures} tests failed.`));
|
||||
} else {
|
||||
c();
|
||||
}
|
||||
});
|
||||
} catch (err) {
|
||||
console.error(err);
|
||||
e(err);
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
21
tsconfig.json
Normal file
21
tsconfig.json
Normal file
|
@ -0,0 +1,21 @@
|
|||
{
|
||||
"compilerOptions": {
|
||||
"module": "commonjs",
|
||||
"target": "es6",
|
||||
"outDir": "out",
|
||||
"lib": [
|
||||
"es6"
|
||||
],
|
||||
"sourceMap": true,
|
||||
"rootDir": "src",
|
||||
"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. */
|
||||
},
|
||||
"exclude": [
|
||||
"node_modules",
|
||||
".vscode-test"
|
||||
]
|
||||
}
|
Loading…
Reference in a new issue