Helper
This commit is contained in:
commit
4d4ed174e9
BIN
type-script-helper-0.0.1.vsix
Normal file
BIN
type-script-helper-0.0.1.vsix
Normal file
Binary file not shown.
BIN
type-script-helper-1.0.0.vsix
Normal file
BIN
type-script-helper-1.0.0.vsix
Normal file
Binary file not shown.
BIN
type-script-helper-1.0.1.vsix
Normal file
BIN
type-script-helper-1.0.1.vsix
Normal file
Binary file not shown.
BIN
type-script-helper-1.1.0.vsix
Normal file
BIN
type-script-helper-1.1.0.vsix
Normal file
Binary file not shown.
BIN
type-script-helper-1.1.1.vsix
Normal file
BIN
type-script-helper-1.1.1.vsix
Normal file
Binary file not shown.
BIN
type-script-helper-1.1.2.vsix
Normal file
BIN
type-script-helper-1.1.2.vsix
Normal file
Binary file not shown.
BIN
type-script-helper-1.1.3.vsix
Normal file
BIN
type-script-helper-1.1.3.vsix
Normal file
Binary file not shown.
BIN
type-script-helper-1.1.4.vsix
Normal file
BIN
type-script-helper-1.1.4.vsix
Normal file
Binary file not shown.
BIN
type-script-helper-1.1.5.vsix
Normal file
BIN
type-script-helper-1.1.5.vsix
Normal file
Binary file not shown.
4
type-script-helper/.gitignore
vendored
Normal file
4
type-script-helper/.gitignore
vendored
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
out
|
||||||
|
node_modules
|
||||||
|
.vscode-test/
|
||||||
|
*.vsix
|
7
type-script-helper/.vscode/extensions.json
vendored
Normal file
7
type-script-helper/.vscode/extensions.json
vendored
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
{
|
||||||
|
// See http://go.microsoft.com/fwlink/?LinkId=827846
|
||||||
|
// for the documentation about the extensions.json format
|
||||||
|
"recommendations": [
|
||||||
|
"ms-vscode.vscode-typescript-tslint-plugin"
|
||||||
|
]
|
||||||
|
}
|
36
type-script-helper/.vscode/launch.json
vendored
Normal file
36
type-script-helper/.vscode/launch.json
vendored
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
// 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}"
|
||||||
|
],
|
||||||
|
"outFiles": [
|
||||||
|
"${workspaceFolder}/out/**/*.js"
|
||||||
|
],
|
||||||
|
"preLaunchTask": "${defaultBuildTask}"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Extension Tests",
|
||||||
|
"type": "extensionHost",
|
||||||
|
"request": "launch",
|
||||||
|
"runtimeExecutable": "${execPath}",
|
||||||
|
"args": [
|
||||||
|
"--extensionDevelopmentPath=${workspaceFolder}",
|
||||||
|
"--extensionTestsPath=${workspaceFolder}/out/test/suite/index"
|
||||||
|
],
|
||||||
|
"outFiles": [
|
||||||
|
"${workspaceFolder}/out/test/**/*.js"
|
||||||
|
],
|
||||||
|
"preLaunchTask": "${defaultBuildTask}"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
11
type-script-helper/.vscode/settings.json
vendored
Normal file
11
type-script-helper/.vscode/settings.json
vendored
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
// Place your settings in this file to overwrite default and user settings.
|
||||||
|
{
|
||||||
|
"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"
|
||||||
|
}
|
20
type-script-helper/.vscode/tasks.json
vendored
Normal file
20
type-script-helper/.vscode/tasks.json
vendored
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
// See https://go.microsoft.com/fwlink/?LinkId=733558
|
||||||
|
// for the documentation about the tasks.json format
|
||||||
|
{
|
||||||
|
"version": "2.0.0",
|
||||||
|
"tasks": [
|
||||||
|
{
|
||||||
|
"type": "npm",
|
||||||
|
"script": "watch",
|
||||||
|
"problemMatcher": "$tsc-watch",
|
||||||
|
"isBackground": true,
|
||||||
|
"presentation": {
|
||||||
|
"reveal": "never"
|
||||||
|
},
|
||||||
|
"group": {
|
||||||
|
"kind": "build",
|
||||||
|
"isDefault": true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
10
type-script-helper/.vscodeignore
Normal file
10
type-script-helper/.vscodeignore
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
.vscode/**
|
||||||
|
.vscode-test/**
|
||||||
|
out/test/**
|
||||||
|
src/**
|
||||||
|
.gitignore
|
||||||
|
vsc-extension-quickstart.md
|
||||||
|
**/tsconfig.json
|
||||||
|
**/tslint.json
|
||||||
|
**/*.map
|
||||||
|
**/*.ts
|
9
type-script-helper/CHANGELOG.md
Normal file
9
type-script-helper/CHANGELOG.md
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
# Change Log
|
||||||
|
|
||||||
|
All notable changes to the "type-script-helper" extension will be documented in this file.
|
||||||
|
|
||||||
|
Check [Keep a Changelog](http://keepachangelog.com/) for recommendations on how to structure this file.
|
||||||
|
|
||||||
|
## [Unreleased]
|
||||||
|
|
||||||
|
- Initial release
|
50
type-script-helper/README.md
Normal file
50
type-script-helper/README.md
Normal file
@ -0,0 +1,50 @@
|
|||||||
|
# type-script-helper README
|
||||||
|
|
||||||
|
Helpers
|
||||||
|
|
||||||
|
## Features
|
||||||
|
|
||||||
|
See Contributions tab
|
||||||
|
|
||||||
|
## Requirements
|
||||||
|
|
||||||
|
None
|
||||||
|
|
||||||
|
## Extension Settings
|
||||||
|
|
||||||
|
None
|
||||||
|
|
||||||
|
## Known Issues
|
||||||
|
|
||||||
|
None
|
||||||
|
|
||||||
|
## Release Notes
|
||||||
|
|
||||||
|
cd "C:\Users\phares\source\yo_vscode"
|
||||||
|
yo code
|
||||||
|
Type Script Helper
|
||||||
|
(type-script-helper)
|
||||||
|
Modify .package
|
||||||
|
Add publisher
|
||||||
|
cd type-script-helper
|
||||||
|
vsce package
|
||||||
|
|
||||||
|
F1
|
||||||
|
Extensions: Install from VSIX
|
||||||
|
|
||||||
|
### 1.0.0
|
||||||
|
|
||||||
|
Initial release of ...
|
||||||
|
|
||||||
|
### 1.0.1
|
||||||
|
|
||||||
|
Fixed issue in replace function
|
||||||
|
https://stackoverflow.com/questions/37197311/in-typescript-string-replace-only-replaces-first-occurrence-of-matched-string
|
||||||
|
Added split(' group by ').join('\r\n GROUP BY ').
|
||||||
|
|
||||||
|
### 1.1.0
|
||||||
|
-----------------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
## Working with Markdown
|
||||||
|
|
||||||
|
### For more information
|
1030
type-script-helper/package-lock.json
generated
Normal file
1030
type-script-helper/package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
74
type-script-helper/package.json
Normal file
74
type-script-helper/package.json
Normal file
@ -0,0 +1,74 @@
|
|||||||
|
{
|
||||||
|
"name": "type-script-helper",
|
||||||
|
"displayName": "Type Script Helper",
|
||||||
|
"description": "Helper for VS Code in TypeScript",
|
||||||
|
"publisher": "IFX",
|
||||||
|
"version": "1.1.5",
|
||||||
|
"engines": {
|
||||||
|
"vscode": "^1.40.0"
|
||||||
|
},
|
||||||
|
"categories": [
|
||||||
|
"Other"
|
||||||
|
],
|
||||||
|
"main": "./out/extension.js",
|
||||||
|
"activationEvents": [
|
||||||
|
"onCommand:helper.addCSharpComment",
|
||||||
|
"onCommand:helper.addVBComment",
|
||||||
|
"onCommand:helper.convertToRegularExpression",
|
||||||
|
"onCommand:helper.expandSql",
|
||||||
|
"onCommand:helper.prettySql",
|
||||||
|
"onCommand:helper.removeComment",
|
||||||
|
"onCommand:helper.sortNormal",
|
||||||
|
"onCommand:helper.unwrapSql",
|
||||||
|
"onCommand:helper.wrapSqlCSharp",
|
||||||
|
"onCommand:helper.wrapSqlVB"
|
||||||
|
],
|
||||||
|
"contributes": {
|
||||||
|
"commands": [
|
||||||
|
{ "command": "helper.addCSharpComment", "title": "Add C# Comment" },
|
||||||
|
{ "command": "helper.addVBComment", "title": "Add VB Comment" },
|
||||||
|
{ "command": "helper.expandSql", "title": "Expand Sql" },
|
||||||
|
{ "command": "helper.convertToRegularExpression", "title": "Convert to Regular Expression" },
|
||||||
|
{ "command": "helper.prettySql", "title": "Pretty Sql" },
|
||||||
|
{ "command": "helper.removeComment", "title": "Remove comment" },
|
||||||
|
{ "command": "helper.sortNormal", "title": "My Sort lines (ascending, case sensitive)" },
|
||||||
|
{ "command": "helper.unwrapSql", "title": "Un-wrap Sql" },
|
||||||
|
{ "command": "helper.wrapSqlCSharp", "title": "Wrap Sql for C#" },
|
||||||
|
{ "command": "helper.wrapSqlVB", "title": "Wrap Sql for VB" }
|
||||||
|
],
|
||||||
|
"keybindings": [
|
||||||
|
{
|
||||||
|
"command": "helper.unwrapSql",
|
||||||
|
"key": "shift + f9",
|
||||||
|
"when": "editorTextFocus"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"menus": {
|
||||||
|
"editor/context": [
|
||||||
|
{
|
||||||
|
"command": "helper.unwrapSql",
|
||||||
|
"when": "editorTextFocus",
|
||||||
|
"group": "helper@1"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"scripts": {
|
||||||
|
"vscode:prepublish": "npm run compile",
|
||||||
|
"compile": "tsc -p ./",
|
||||||
|
"watch": "tsc -watch -p ./",
|
||||||
|
"pretest": "npm run compile",
|
||||||
|
"test": "node ./out/test/runTest.js"
|
||||||
|
},
|
||||||
|
"devDependencies": {
|
||||||
|
"@types/glob": "^7.1.1",
|
||||||
|
"@types/mocha": "^5.2.7",
|
||||||
|
"@types/node": "^12.11.7",
|
||||||
|
"@types/vscode": "^1.40.0",
|
||||||
|
"glob": "^7.1.5",
|
||||||
|
"mocha": "^6.2.2",
|
||||||
|
"typescript": "^3.6.4",
|
||||||
|
"tslint": "^5.20.0",
|
||||||
|
"vscode-test": "^1.2.2"
|
||||||
|
}
|
||||||
|
}
|
44
type-script-helper/src/extension.ts
Normal file
44
type-script-helper/src/extension.ts
Normal file
@ -0,0 +1,44 @@
|
|||||||
|
// 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';
|
||||||
|
import * as helper from './helper';
|
||||||
|
|
||||||
|
// 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) {
|
||||||
|
|
||||||
|
// Use the console to output diagnostic information (console.log) and errors (console.error)
|
||||||
|
// This line of code will only be executed once when your extension is activated
|
||||||
|
console.log('Congratulations, your extension "type-script-helper" is now active!');
|
||||||
|
|
||||||
|
// The command has been defined in the package.json file
|
||||||
|
// Now provide the implementation of the command with registerCommand
|
||||||
|
// The commandId parameter must match the command field in package.json
|
||||||
|
// let disposable = vscode.commands.registerCommand('extension.helloWorld', () => {
|
||||||
|
// // The code you place here will be executed every time your command is executed
|
||||||
|
|
||||||
|
// // Display a message box to the user
|
||||||
|
// vscode.window.showInformationMessage('Hello World!');
|
||||||
|
// });
|
||||||
|
|
||||||
|
|
||||||
|
// context.subscriptions.push(disposable);
|
||||||
|
|
||||||
|
const commands = [
|
||||||
|
vscode.commands.registerCommand('helper.addCSharpComment', helper.addCSharpComment),
|
||||||
|
vscode.commands.registerCommand('helper.addVBComment', helper.addVBComment),
|
||||||
|
vscode.commands.registerCommand('helper.convertToRegularExpression', helper.convertToRegularExpression),
|
||||||
|
vscode.commands.registerCommand('helper.expandSql', helper.expandSql),
|
||||||
|
vscode.commands.registerCommand('helper.prettySql', helper.prettySql),
|
||||||
|
vscode.commands.registerCommand('helper.removeComment', helper.removeComment),
|
||||||
|
vscode.commands.registerCommand('helper.sortNormal', helper.sortNormal),
|
||||||
|
vscode.commands.registerCommand('helper.unwrapSql', helper.unwrapSql),
|
||||||
|
vscode.commands.registerCommand('helper.wrapSqlCSharp', helper.wrapSqlCSharp),
|
||||||
|
vscode.commands.registerCommand('helper.wrapSqlVB', helper.wrapSqlVB)
|
||||||
|
];
|
||||||
|
|
||||||
|
commands.forEach(command => context.subscriptions.push(command));
|
||||||
|
}
|
||||||
|
|
||||||
|
// this method is called when your extension is deactivated
|
||||||
|
export function deactivate() {}
|
246
type-script-helper/src/helper.ts
Normal file
246
type-script-helper/src/helper.ts
Normal file
@ -0,0 +1,246 @@
|
|||||||
|
import * as vscode from 'vscode';
|
||||||
|
import { stringify } from 'querystring';
|
||||||
|
|
||||||
|
type ArrayTransformer = (lines: string[]) => string[];
|
||||||
|
type SortingAlgorithm = (a: string, b: string) => number;
|
||||||
|
|
||||||
|
enum LinesAction {
|
||||||
|
addCSharpComment,
|
||||||
|
addVBComment,
|
||||||
|
convertToRegularExpression,
|
||||||
|
expandSql,
|
||||||
|
prettySql,
|
||||||
|
removeComment,
|
||||||
|
sortNormal,
|
||||||
|
unwrapSql,
|
||||||
|
wrapSqlCSharp,
|
||||||
|
wrapSqlVB
|
||||||
|
}
|
||||||
|
|
||||||
|
function removeBlanks(lines: string[]): void {
|
||||||
|
for (let i = 0; i < lines.length; ++i) {
|
||||||
|
if (lines[i].trim() === '') {
|
||||||
|
lines.splice(i, 1);
|
||||||
|
i--;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function getLines(textEditor: vscode.TextEditor, startLine: number, endLine: number) {
|
||||||
|
let results: string[] = [];
|
||||||
|
for (let i = startLine; i <= endLine; i++) {
|
||||||
|
results.push(textEditor.document.lineAt(i).text);
|
||||||
|
}
|
||||||
|
return results;
|
||||||
|
}
|
||||||
|
|
||||||
|
function addCSharpCommentLogic(lines: string[]): void {
|
||||||
|
for (let i = 0; i < lines.length; ++i) {
|
||||||
|
lines[i] = '//' + lines[i].trim();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function addVBCommentLogic(lines: string[]): void {
|
||||||
|
for (let i = 0; i < lines.length; ++i) {
|
||||||
|
lines[i] = "'" + lines[i].trim();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function convertToRegularExpressionLogic(lines: string[]): string[] {
|
||||||
|
let results: string[];
|
||||||
|
let result: string = "";
|
||||||
|
let explicitLines = 50;
|
||||||
|
for (let i = 0; i < lines.length - 1 && i < explicitLines; ++i) {
|
||||||
|
result = result + lines[i].trim().
|
||||||
|
split('\\').join('\\\\').
|
||||||
|
split('(').join('\\(').
|
||||||
|
split(')').join('\\)').
|
||||||
|
split('[').join('\\[').
|
||||||
|
split(']').join('\\]').
|
||||||
|
split('.').join('\\.').
|
||||||
|
split('*').join('\\*').
|
||||||
|
split('+').join('\\+').
|
||||||
|
split('?').join('\\?').
|
||||||
|
split('|').join('\\|').
|
||||||
|
split('$').join('\\$').
|
||||||
|
split('^').join('\\^') +
|
||||||
|
'~';
|
||||||
|
}
|
||||||
|
for (let i = explicitLines; i < lines.length - 1; ++i) {
|
||||||
|
result = result + '.*~';
|
||||||
|
}
|
||||||
|
result = result.
|
||||||
|
substring(0, result.length - 1).
|
||||||
|
split('~').join('\\r\\n\?\\s\*');
|
||||||
|
results = [result];
|
||||||
|
return results;
|
||||||
|
}
|
||||||
|
|
||||||
|
function expandSqlLogic(lines: string[]): void {
|
||||||
|
for (let i = 0; i < lines.length; ++i) {
|
||||||
|
lines[i] = ' ' + lines[i];
|
||||||
|
lines[i] = lines[i].
|
||||||
|
split(' select ').join(' SELECT\r\n').
|
||||||
|
split(' from ').join('\r\n FROM ').
|
||||||
|
split(' where ').join('\r\n WHERE ').
|
||||||
|
split(' and ').join('\r\n and ').
|
||||||
|
split(' join ').join('\r\n join ').
|
||||||
|
split(' left join ').join('\r\n left join ').
|
||||||
|
split(' on ').join('\r\n ON ').
|
||||||
|
split(' group by ').join('\r\n GROUP BY ').
|
||||||
|
split(' order by ').join('\r\n ORDER BY ').
|
||||||
|
split(' SELECT ').join(' SELECT\r\n').
|
||||||
|
split(' FROM ').join('\r\n FROM ').
|
||||||
|
split(' WHERE ').join('\r\n WHERE ').
|
||||||
|
split(' AND ').join('\r\n AND ').
|
||||||
|
split(' JOIN ').join('\r\n JOIN ').
|
||||||
|
split(' LEFT JOIN ').join('\r\n LEFT JOIN ').
|
||||||
|
split(' ON ').join('\r\n ON ').
|
||||||
|
split(' GROUP BY ').join('\r\n GROUP BY ').
|
||||||
|
split(' ORDER BY ').join('\r\n ORDER BY ').
|
||||||
|
split('\r\n\r\n').join('\r\n').
|
||||||
|
trim();
|
||||||
|
}
|
||||||
|
removeBlanks(lines);
|
||||||
|
prettySqlLogic(lines);
|
||||||
|
}
|
||||||
|
|
||||||
|
function prettySqlLogic(lines: string[]): void {
|
||||||
|
for (let i = 0; i < lines.length; ++i) {
|
||||||
|
lines[i] = ' ' + lines[i];
|
||||||
|
lines[i] = lines[i].
|
||||||
|
split(' select ').join(' SELECT ').
|
||||||
|
split(' distinct ').join(' DISTINCT ').
|
||||||
|
split(' as ').join(' AS ').
|
||||||
|
split(' from ').join(' FROM ').
|
||||||
|
split(' where ').join(' WHERE ').
|
||||||
|
split(' and ').join(' AND ').
|
||||||
|
split(' join ').join(' JOIN ').
|
||||||
|
split(' left join ').join(' LEFT JOIN ').
|
||||||
|
split(' on ').join(' ON ').
|
||||||
|
split(' group by ').join(' GROUP BY ').
|
||||||
|
split(' order by ').join(' ORDER BY ').
|
||||||
|
split('\r\n\r\n').join('\r\n').
|
||||||
|
trim();
|
||||||
|
}
|
||||||
|
removeBlanks(lines);
|
||||||
|
}
|
||||||
|
|
||||||
|
function makeSorter(algorithm?: SortingAlgorithm): ArrayTransformer {
|
||||||
|
return function (lines: string[]): string[] {
|
||||||
|
return lines.sort(algorithm);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
function removeCommentLogic(lines: string[]): void {
|
||||||
|
for (let i = 0; i < lines.length; ++i) {
|
||||||
|
lines[i] = lines[i].trim();
|
||||||
|
if(lines[i].length > 1 && lines[i][0] === '/' && lines[i][1] === '/') {
|
||||||
|
lines[i] = lines[i].substr(2);
|
||||||
|
}
|
||||||
|
if(lines[i].length > 0 && lines[i][0] === "'") {
|
||||||
|
lines[i] = lines[i].substr(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function sortNormalLogic(lines: string[]): void {
|
||||||
|
var transformers: ArrayTransformer[] = [];
|
||||||
|
transformers.push(makeSorter());
|
||||||
|
|
||||||
|
removeBlanks(lines);
|
||||||
|
|
||||||
|
lines = transformers.reduce((currentLines, transform) => transform(currentLines), lines);
|
||||||
|
}
|
||||||
|
|
||||||
|
function unwrapSqlLogic(lines: string[]): void {
|
||||||
|
for (let i = 0; i < lines.length; ++i) {
|
||||||
|
lines[i] = "//" + lines[i].
|
||||||
|
split('sql = "').join('').
|
||||||
|
split('sql = sql & "').join('').
|
||||||
|
split('sql.Append("').join('').
|
||||||
|
split('.Append("').join('').
|
||||||
|
split('Append("').join('').
|
||||||
|
split('");').join('').
|
||||||
|
split('").').join('').
|
||||||
|
split('")').join('').
|
||||||
|
split('" & ').join('$').
|
||||||
|
split(' & "').join('$').
|
||||||
|
split('"').join('').
|
||||||
|
trim();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function wrapSqlCSharpLogic(lines: string[]): void {
|
||||||
|
for (let i = 0; i < lines.length; ++i) {
|
||||||
|
lines[i] = lines[i].trim();
|
||||||
|
if(lines[i].length > 1 && lines[i][0] === '/' && lines[i][1] === '/') {
|
||||||
|
lines[i] = lines[i].substr(2);
|
||||||
|
}
|
||||||
|
lines[i] = 'Append(" ' + lines[i] + ' ").';
|
||||||
|
}
|
||||||
|
if(lines.length > 0) {
|
||||||
|
lines[0] = 'sql.' + lines[0];
|
||||||
|
lines[lines.length - 1] = lines[lines.length - 1].split(' ").').join(' ");');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function wrapSqlVBLogic(lines: string[]): void {
|
||||||
|
for (let i = 0; i < lines.length; ++i) {
|
||||||
|
lines[i] = lines[i].trim();
|
||||||
|
if(lines[i].length > 0 && lines[i][0] === "'") {
|
||||||
|
lines[i] = lines[i].substr(1);
|
||||||
|
}
|
||||||
|
lines[i] = 'Append(" ' + lines[i] + ' ").';
|
||||||
|
}
|
||||||
|
if(lines.length > 0) {
|
||||||
|
lines[0] = 'sql.' + lines[0];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function returnLines(textEditor: vscode.TextEditor, startLine: number, endLine: number, lines: string[]) {
|
||||||
|
return textEditor.edit(editBuilder => {
|
||||||
|
const range = new vscode.Range(startLine, 0, endLine, textEditor.document.lineAt(endLine).text.length);
|
||||||
|
editBuilder.replace(range, lines.join('\n'));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function linesFunction(linesAction: LinesAction): Thenable<boolean> | undefined {
|
||||||
|
const textEditor = vscode.window.activeTextEditor;
|
||||||
|
if (!textEditor) {
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
var startLine = 0;
|
||||||
|
var endLine = textEditor.document.lineCount - 1;
|
||||||
|
const selection = textEditor.selection;
|
||||||
|
if (!selection.isEmpty) {
|
||||||
|
startLine = selection.start.line;
|
||||||
|
endLine = selection.end.line;
|
||||||
|
}
|
||||||
|
let lines: string[] = getLines(textEditor, startLine, endLine);
|
||||||
|
switch (linesAction) {
|
||||||
|
case LinesAction.addCSharpComment: { addCSharpCommentLogic(lines); break; }
|
||||||
|
case LinesAction.addVBComment: { addVBCommentLogic(lines); break; }
|
||||||
|
case LinesAction.convertToRegularExpression: { lines = convertToRegularExpressionLogic(lines); break; }
|
||||||
|
case LinesAction.expandSql: { expandSqlLogic(lines); break; }
|
||||||
|
case LinesAction.prettySql: { prettySqlLogic(lines); break; }
|
||||||
|
case LinesAction.removeComment: { removeCommentLogic(lines); break; }
|
||||||
|
case LinesAction.sortNormal: { sortNormalLogic(lines); break; }
|
||||||
|
case LinesAction.unwrapSql: { unwrapSqlLogic(lines); break; }
|
||||||
|
case LinesAction.wrapSqlCSharp: { wrapSqlCSharpLogic(lines); break; }
|
||||||
|
case LinesAction.wrapSqlVB: { wrapSqlVBLogic(lines); break; }
|
||||||
|
default: { throw new Error(); }
|
||||||
|
}
|
||||||
|
return returnLines(textEditor, startLine, endLine, lines);
|
||||||
|
}
|
||||||
|
|
||||||
|
export const addCSharpComment = () => linesFunction(LinesAction.addCSharpComment);
|
||||||
|
export const addVBComment = () => linesFunction(LinesAction.addVBComment);
|
||||||
|
export const convertToRegularExpression = () => linesFunction(LinesAction.convertToRegularExpression);
|
||||||
|
export const expandSql = () => linesFunction(LinesAction.expandSql);
|
||||||
|
export const prettySql = () => linesFunction(LinesAction.prettySql);
|
||||||
|
export const removeComment = () => linesFunction(LinesAction.removeComment);
|
||||||
|
export const sortNormal = () => linesFunction(LinesAction.sortNormal);
|
||||||
|
export const unwrapSql = () => linesFunction(LinesAction.unwrapSql);
|
||||||
|
export const wrapSqlCSharp = () => linesFunction(LinesAction.wrapSqlCSharp);
|
||||||
|
export const wrapSqlVB = () => linesFunction(LinesAction.wrapSqlVB);
|
23
type-script-helper/src/test/runTest.ts
Normal file
23
type-script-helper/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
type-script-helper/src/test/suite/extension.test.ts
Normal file
15
type-script-helper/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.equal(-1, [1, 2, 3].indexOf(5));
|
||||||
|
assert.equal(-1, [1, 2, 3].indexOf(0));
|
||||||
|
});
|
||||||
|
});
|
37
type-script-helper/src/test/suite/index.ts
Normal file
37
type-script-helper/src/test/suite/index.ts
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
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',
|
||||||
|
});
|
||||||
|
mocha.useColors(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) {
|
||||||
|
e(err);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
21
type-script-helper/tsconfig.json
Normal file
21
type-script-helper/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"
|
||||||
|
]
|
||||||
|
}
|
15
type-script-helper/tslint.json
Normal file
15
type-script-helper/tslint.json
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
{
|
||||||
|
"rules": {
|
||||||
|
"no-string-throw": true,
|
||||||
|
"no-unused-expression": true,
|
||||||
|
"no-duplicate-variable": true,
|
||||||
|
"curly": true,
|
||||||
|
"class-name": true,
|
||||||
|
"semicolon": [
|
||||||
|
true,
|
||||||
|
"always"
|
||||||
|
],
|
||||||
|
"triple-equals": true
|
||||||
|
},
|
||||||
|
"defaultSeverity": "warning"
|
||||||
|
}
|
42
type-script-helper/vsc-extension-quickstart.md
Normal file
42
type-script-helper/vsc-extension-quickstart.md
Normal file
@ -0,0 +1,42 @@
|
|||||||
|
# Welcome to your VS Code Extension
|
||||||
|
|
||||||
|
## What's in the folder
|
||||||
|
|
||||||
|
* This folder contains all of the files necessary for your extension.
|
||||||
|
* `package.json` - this is the manifest file in which you declare your extension and command.
|
||||||
|
* The sample plugin registers a command and defines its title and command name. With this information VS Code can show the command in the command palette. It doesn’t yet need to load the plugin.
|
||||||
|
* `src/extension.ts` - this is the main file where you will provide the implementation of your command.
|
||||||
|
* The file exports one function, `activate`, which is called the very first time your extension is activated (in this case by executing the command). Inside the `activate` function we call `registerCommand`.
|
||||||
|
* We pass the function containing the implementation of the command as the second parameter to `registerCommand`.
|
||||||
|
|
||||||
|
## Get up and running straight away
|
||||||
|
|
||||||
|
* Press `F5` to open a new window with your extension loaded.
|
||||||
|
* Run your command from the command palette by pressing (`Ctrl+Shift+P` or `Cmd+Shift+P` on Mac) and typing `Hello World`.
|
||||||
|
* Set breakpoints in your code inside `src/extension.ts` to debug your extension.
|
||||||
|
* Find output from your extension in the debug console.
|
||||||
|
|
||||||
|
## Make changes
|
||||||
|
|
||||||
|
* You can relaunch the extension from the debug toolbar after changing code in `src/extension.ts`.
|
||||||
|
* You can also reload (`Ctrl+R` or `Cmd+R` on Mac) the VS Code window with your extension to load your changes.
|
||||||
|
|
||||||
|
|
||||||
|
## Explore the API
|
||||||
|
|
||||||
|
* You can open the full set of our API when you open the file `node_modules/@types/vscode/index.d.ts`.
|
||||||
|
|
||||||
|
## Run tests
|
||||||
|
|
||||||
|
* Open the debug viewlet (`Ctrl+Shift+D` or `Cmd+Shift+D` on Mac) and from the launch configuration dropdown pick `Extension Tests`.
|
||||||
|
* Press `F5` to run the tests in a new window with your extension loaded.
|
||||||
|
* See the output of the test result in the debug console.
|
||||||
|
* Make changes to `src/test/suite/extension.test.ts` or create new test files inside the `test/suite` folder.
|
||||||
|
* The provided test runner will only consider files matching the name pattern `**.test.ts`.
|
||||||
|
* You can create folders inside the `test` folder to structure your tests any way you want.
|
||||||
|
|
||||||
|
## Go further
|
||||||
|
|
||||||
|
* Reduce the extension size and improve the startup time by [bundling your extension](https://code.visualstudio.com/api/working-with-extensions/bundling-extension).
|
||||||
|
* [Publish your extension](https://code.visualstudio.com/api/working-with-extensions/publishing-extension) on the VSCode extension marketplace.
|
||||||
|
* Automate builds by setting up [Continuous Integration](https://code.visualstudio.com/api/working-with-extensions/continuous-integration).
|
Loading…
x
Reference in New Issue
Block a user