First with local

This commit is contained in:
Mike Phares 2022-01-11 17:15:26 -07:00
commit ad0108f248
34 changed files with 3621 additions and 0 deletions

266
.gitignore vendored Normal file
View File

@ -0,0 +1,266 @@
## Ignore Visual Studio temporary files, build results, and
## files generated by popular Visual Studio add-ons.
# User-specific files
*.suo
*.user
*.userosscache
*.sln.docstates
# User-specific files (MonoDevelop/Xamarin Studio)
*.userprefs
# Build results
[Dd]ebug/
[Dd]ebugPublic/
[Rr]elease/
[Rr]eleases/
x64/
x86/
bld/
[Bb]in/
[Oo]bj/
[Ll]og/
# Visual Studio 2015 cache/options directory
.vs/
# Uncomment if you have tasks that create the project's static files in wwwroot
#wwwroot/
# MSTest test Results
[Tt]est[Rr]esult*/
[Bb]uild[Ll]og.*
# NUNIT
*.VisualState.xml
TestResult.xml
# Build Results of an ATL Project
[Dd]ebugPS/
[Rr]eleasePS/
dlldata.c
# DNX
project.lock.json
project.fragment.lock.json
artifacts/
*_i.c
*_p.c
*_i.h
*.ilk
*.meta
*.obj
*.pch
*.pdb
*.pgc
*.pgd
*.rsp
*.sbr
*.tlb
*.tli
*.tlh
*.tmp
*.tmp_proj
*.log
*.vspscc
*.vssscc
.builds
*.pidb
*.svclog
*.scc
# Chutzpah Test files
_Chutzpah*
# Visual C++ cache files
ipch/
*.aps
*.ncb
*.opendb
*.opensdf
*.sdf
*.cachefile
*.VC.db
*.VC.VC.opendb
# Visual Studio profiler
*.psess
*.vsp
*.vspx
*.sap
# TFS 2012 Local Workspace
$tf/
# Guidance Automation Toolkit
*.gpState
# ReSharper is a .NET coding add-in
_ReSharper*/
*.[Rr]e[Ss]harper
*.DotSettings.user
# JustCode is a .NET coding add-in
.JustCode
# TeamCity is a build add-in
_TeamCity*
# DotCover is a Code Coverage Tool
*.dotCover
# NCrunch
_NCrunch_*
.*crunch*.local.xml
nCrunchTemp_*
# MightyMoose
*.mm.*
AutoTest.Net/
# Web workbench (sass)
.sass-cache/
# Installshield output folder
[Ee]xpress/
# DocProject is a documentation generator add-in
DocProject/buildhelp/
DocProject/Help/*.HxT
DocProject/Help/*.HxC
DocProject/Help/*.hhc
DocProject/Help/*.hhk
DocProject/Help/*.hhp
DocProject/Help/Html2
DocProject/Help/html
# Click-Once directory
publish/
# Publish Web Output
*.[Pp]ublish.xml
*.azurePubxml
# TODO: Comment the next line if you want to checkin your web deploy settings
# but database connection strings (with potential passwords) will be unencrypted
#*.pubxml
*.publishproj
# Microsoft Azure Web App publish settings. Comment the next line if you want to
# checkin your Azure Web App publish settings, but sensitive information contained
# in these scripts will be unencrypted
PublishScripts/
# NuGet Packages
*.nupkg
# The packages folder can be ignored because of Package Restore
**/packages/*
# except build/, which is used as an MSBuild target.
!**/packages/build/
# Uncomment if necessary however generally it will be regenerated when needed
#!**/packages/repositories.config
# NuGet v3's project.json files produces more ignoreable files
*.nuget.props
*.nuget.targets
# Microsoft Azure Build Output
csx/
*.build.csdef
# Microsoft Azure Emulator
ecf/
rcf/
# Windows Store app package directories and files
AppPackages/
BundleArtifacts/
Package.StoreAssociation.xml
_pkginfo.txt
# Visual Studio cache files
# files ending in .cache can be ignored
*.[Cc]ache
# but keep track of directories ending in .cache
!*.[Cc]ache/
# Others
ClientBin/
~$*
*~
*.dbmdl
*.dbproj.schemaview
*.jfm
*.pfx
*.publishsettings
node_modules/
orleans.codegen.cs
# Since there are multiple workflows, uncomment next line to ignore bower_components
# (https://github.com/github/gitignore/pull/1529#issuecomment-104372622)
#bower_components/
# RIA/Silverlight projects
Generated_Code/
# Backup & report files from converting an old project file
# to a newer Visual Studio version. Backup files are not needed,
# because we have git ;-)
_UpgradeReport_Files/
Backup*/
UpgradeLog*.XML
UpgradeLog*.htm
# SQL Server files
*.mdf
*.ldf
# Business Intelligence projects
*.rdl.data
*.bim.layout
*.bim_*.settings
# Microsoft Fakes
FakesAssemblies/
# GhostDoc plugin setting file
*.GhostDoc.xml
# Node.js Tools for Visual Studio
.ntvs_analysis.dat
# Visual Studio 6 build log
*.plg
# Visual Studio 6 workspace options file
*.opt
# Visual Studio LightSwitch build output
**/*.HTMLClient/GeneratedArtifacts
**/*.DesktopClient/GeneratedArtifacts
**/*.DesktopClient/ModelManifest.xml
**/*.Server/GeneratedArtifacts
**/*.Server/ModelManifest.xml
_Pvt_Extensions
# Paket dependency manager
.paket/paket.exe
paket-files/
# FAKE - F# Make
.fake/
# JetBrains Rider
.idea/
*.sln.iml
# CodeRush
.cr/
# Python Tools for Visual Studio (PTVS)
__pycache__/
*.pyc
# Mike Phares
type-script-helper-1.1.6.vsix
type-script-helper-1.1.7.vsix
type-script-helper-1.1.8.vsix

13
YO-VSCode.sln Normal file
View File

@ -0,0 +1,13 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.28307.1169
MinimumVisualStudioVersion = 10.0.40219.1
Global
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {A47C35E0-F330-48D2-9FEE-B0B5C8396802}
EndGlobalSection
EndGlobal

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

4
type-script-helper/.gitignore vendored Normal file
View File

@ -0,0 +1,4 @@
out
node_modules
.vscode-test/
*.vsix

View 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
View 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}"
}
]
}

View 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
View 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
}
}
]
}

View File

@ -0,0 +1,10 @@
.vscode/**
.vscode-test/**
out/test/**
src/**
.gitignore
vsc-extension-quickstart.md
**/tsconfig.json
**/tslint.json
**/*.map
**/*.ts

View 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

View File

@ -0,0 +1,94 @@
# type-script-helper README
Helpers
## Features
See Contributions tab
## Requirements
None
## Extension Settings
None
## Known Issues
None
## Release Notes
npm install -g vsce
npm install typescript --save-dev
L:
cd "L:\GitHub\YO-VSCode\type-script-helper"
npm install typescript
npx tsc
L:
cd "L:\GitHub\YO-VSCode\type-script-helper"
yo code
Type Script Helper
(type-script-helper)
Modify .package
Add publisher
cd "L:\GitHub\YO-VSCode\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
### 1.2.4
-----------------------------------------------------------------------------------------------------------
## Search Google
### 1.2.8
-----------------------------------------------------------------------------------------------------------
## Search Google (Read Only Lines Helper)
### 1.2.9, 1.3.0, 1.3.1, 1.3.2
-----------------------------------------------------------------------------------------------------------
## Quick Fix - Camel Case Properties
## Quick Fix - CS0108 (Data Annotations)
## Quick Fix - Proper Case Properties
## Quick Fix - Public (Expression Body)
### 1.3.3, 1.3.4
-----------------------------------------------------------------------------------------------------------
## Quick Fix - Instance Field to Calisthenics

2322
type-script-helper/package-lock.json generated Normal file

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,155 @@
{
"name": "type-script-helper",
"displayName": "Type Script Helper",
"description": "Helper for VS Code in TypeScript",
"publisher": "IFX",
"repository": "https://github.com/mikepharesjr/YO-VSCode/tree/master/type-script-helper",
"version": "1.3.4",
"engines": {
"vscode": "^1.40.0"
},
"categories": [
"Other"
],
"main": "./out/extension.js",
"activationEvents": [
"onCommand:readOnlyLinesHelper.searchGoogle",
"onCommand:replaceLinesHelper.addCSharpComment",
"onCommand:replaceLinesHelper.addVBComment",
"onCommand:replaceLinesHelper.convertToRegularExpression",
"onCommand:replaceLinesHelper.cutEachLine",
"onCommand:replaceLinesHelper.expandSql",
"onCommand:replaceLinesHelper.listToListFamily",
"onCommand:replaceLinesHelper.listToListWrappedComma",
"onCommand:replaceLinesHelper.prettySql",
"onCommand:replaceLinesHelper.quickFixCamelCaseProperties",
"onCommand:replaceLinesHelper.quickFixCS0108",
"onCommand:replaceLinesHelper.quickFixInstanceFieldToCalisthenics",
"onCommand:replaceLinesHelper.quickFixProperCaseProperties",
"onCommand:replaceLinesHelper.quickFixPublic",
"onCommand:replaceLinesHelper.removeComment",
"onCommand:replaceLinesHelper.sortLength",
"onCommand:replaceLinesHelper.sortNormal",
"onCommand:replaceLinesHelper.unwrapSql",
"onCommand:replaceLinesHelper.wrapSqlCSharp",
"onCommand:replaceLinesHelper.wrapSqlVB"
],
"contributes": {
"commands": [
{
"command": "readOnlyLinesHelper.searchGoogle",
"title": "Search Google"
},
{
"command": "replaceLinesHelper.addCSharpComment",
"title": "Add C# Comment"
},
{
"command": "replaceLinesHelper.addVBComment",
"title": "Add VB Comment"
},
{
"command": "replaceLinesHelper.convertToRegularExpression",
"title": "Convert to Regular Expression"
},
{
"command": "replaceLinesHelper.cutEachLine",
"title": "Cut each line after |||"
},
{
"command": "replaceLinesHelper.expandSql",
"title": "Expand Sql"
},
{
"command": "replaceLinesHelper.listToListFamily",
"title": "List to list family (Kristy, Mike ...)"
},
{
"command": "replaceLinesHelper.listToListWrappedComma",
"title": "List to list wrapped comma"
},
{
"command": "replaceLinesHelper.prettySql",
"title": "Pretty Sql"
},
{
"command": "replaceLinesHelper.quickFixCamelCaseProperties",
"title": "Quick Fix - Camel Case Properties"
},
{
"command": "replaceLinesHelper.quickFixCS0108",
"title": "Quick Fix - CS0108 (Data Annotations)"
},
{
"command": "replaceLinesHelper.quickFixInstanceFieldToCalisthenics",
"title": "Quick Fix - Instance Field to Calisthenics"
},
{
"command": "replaceLinesHelper.quickFixProperCaseProperties",
"title": "Quick Fix - Proper Case Properties"
},
{
"command": "replaceLinesHelper.quickFixPublic",
"title": "Quick Fix - Public (Expression Body)"
},
{
"command": "replaceLinesHelper.removeComment",
"title": "Remove comment"
},
{
"command": "replaceLinesHelper.sortLength",
"title": "Sort by Length"
},
{
"command": "replaceLinesHelper.sortNormal",
"title": "My Sort lines (ascending, case sensitive)"
},
{
"command": "replaceLinesHelper.unwrapSql",
"title": "Un-wrap Sql"
},
{
"command": "replaceLinesHelper.wrapSqlCSharp",
"title": "Wrap Sql for C#"
},
{
"command": "replaceLinesHelper.wrapSqlVB",
"title": "Wrap Sql for VB"
}
],
"keybindings": [
{
"command": "replaceLinesHelper.unwrapSql",
"key": "shift + f9",
"when": "editorTextFocus"
}
],
"menus": {
"editor/context": [
{
"command": "replaceLinesHelper.unwrapSql",
"when": "editorTextFocus",
"group": "replaceLinesHelper@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",
"tslint": "^5.20.0",
"typescript": "^3.9.10",
"vscode-test": "^1.2.2"
}
}

View File

@ -0,0 +1,55 @@
// 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 replaceLinesHelper from './replaceLinesHelper';
import * as readOnlyLinesHelper from './readOnlyLinesHelper';
// 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('readOnlyLinesHelper.searchGoogle', readOnlyLinesHelper.searchGoogle),
vscode.commands.registerCommand('replaceLinesHelper.addCSharpComment', replaceLinesHelper.addCSharpComment),
vscode.commands.registerCommand('replaceLinesHelper.addVBComment', replaceLinesHelper.addVBComment),
vscode.commands.registerCommand('replaceLinesHelper.convertToRegularExpression', replaceLinesHelper.convertToRegularExpression),
vscode.commands.registerCommand('replaceLinesHelper.cutEachLine', replaceLinesHelper.cutEachLine),
vscode.commands.registerCommand('replaceLinesHelper.expandSql', replaceLinesHelper.expandSql),
vscode.commands.registerCommand('replaceLinesHelper.listToListFamily', replaceLinesHelper.listToListFamily),
vscode.commands.registerCommand('replaceLinesHelper.listToListWrappedComma', replaceLinesHelper.listToListWrappedComma),
vscode.commands.registerCommand('replaceLinesHelper.prettySql', replaceLinesHelper.prettySql),
vscode.commands.registerCommand('replaceLinesHelper.quickFixCamelCaseProperties', replaceLinesHelper.quickFixCamelCaseProperties),
vscode.commands.registerCommand('replaceLinesHelper.quickFixCS0108', replaceLinesHelper.quickFixCS0108),
vscode.commands.registerCommand('replaceLinesHelper.quickFixInstanceFieldToCalisthenics', replaceLinesHelper.quickFixInstanceFieldToCalisthenics),
vscode.commands.registerCommand('replaceLinesHelper.quickFixProperCaseProperties', replaceLinesHelper.quickFixProperCaseProperties),
vscode.commands.registerCommand('replaceLinesHelper.quickFixPublic', replaceLinesHelper.quickFixPublic),
vscode.commands.registerCommand('replaceLinesHelper.removeComment', replaceLinesHelper.removeComment),
vscode.commands.registerCommand('replaceLinesHelper.sortLength', replaceLinesHelper.sortLength),
vscode.commands.registerCommand('replaceLinesHelper.sortNormal', replaceLinesHelper.sortNormal),
vscode.commands.registerCommand('replaceLinesHelper.unwrapSql', replaceLinesHelper.unwrapSql),
vscode.commands.registerCommand('replaceLinesHelper.wrapSqlCSharp', replaceLinesHelper.wrapSqlCSharp),
vscode.commands.registerCommand('replaceLinesHelper.wrapSqlVB', replaceLinesHelper.wrapSqlVB)
];
commands.forEach(command => context.subscriptions.push(command));
}
// this method is called when your extension is deactivated
export function deactivate() {}

View File

@ -0,0 +1,51 @@
import * as vscode from 'vscode';
enum LinesAction {
searchGoogle
}
function searchGoogleLogic(text: string, lines: string[]): void {
if (text.length > 0) {
vscode.env.openExternal(
vscode.Uri.parse(`https://www.google.com/search?q=${text.trim()}`)
)
}
else if (lines.length > 0) {
vscode.env.openExternal(
vscode.Uri.parse(`https://www.google.com/search?q=${lines[0].trim()}`)
)
}
}
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 linesFunction(linesAction: LinesAction): Thenable<boolean> | undefined {
const textEditor = vscode.window.activeTextEditor;
if (!textEditor) {
return undefined;
}
let text = '';
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 range = new vscode.Range(selection.start, selection.end)
text = textEditor.document.getText(range);
}
let lines: string[] = getLines(textEditor, startLine, endLine);
switch (linesAction) {
case LinesAction.searchGoogle: { searchGoogleLogic(text, lines); break; }
default: { throw new Error(); }
}
return undefined;
}
export const searchGoogle = () => linesFunction(LinesAction.searchGoogle);

View File

@ -0,0 +1,414 @@
import * as vscode from 'vscode';
type ArrayTransformer = (lines: string[]) => string[];
type SortingAlgorithm = (a: string, b: string) => number;
enum LinesAction {
addCSharpComment,
addVBComment,
convertToRegularExpression,
cutEachLine,
expandSql,
listToListFamily,
listToListWrappedComma,
prettySql,
quickFixCamelCaseProperties,
quickFixCS0108,
quickFixInstanceFieldToCalisthenics,
quickFixProperCaseProperties,
quickFixPublic,
pdsfToFixedWidth,
removeComment,
sortLength,
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('\\|').
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 listToListFamilyLogic(lines: string[]): void {
for (let i = 0; i < lines.length; ++i) {
lines[i] = "Kristy" + lines[i].trim() + "Mike" + lines[i].trim() + "Jason" + lines[i].trim() + "Mackenzie" + lines[i].trim() + "Logan" + lines[i].trim() + "Lilly" + lines[i].trim() + "Chelsea" + lines[i].trim() + "Piper" + lines[i].trim();
}
}
function listToListWrappedCommaLogic(lines: string[]): void {
for (let i = 0; i < lines.length; ++i) {
lines[i] = "'" + lines[i].trim() + "',";
}
}
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 camelCase(str: string) {
return str.replace(/(?:^\w|[A-Z]|\b\w|\s+)/g, function(match, index) {
if (+match === 0) return "";
return index === 0 ? match.toLowerCase() : match.toUpperCase();
});
}
function toCapitalizedWords(name: string) {
let words = name.match(/[A-Za-z][a-z]*|[0-9]+/g) || [];
return words.map(capitalize).join(" ");
}
function capitalize(word: string) {
return word.charAt(0).toUpperCase() + word.substring(1);
}
function quickFixCamelCasePropertiesLogic(lines: string[]): void {
for (let i = 0; i < lines.length; ++i) {
let segments = lines[i].trim().split(' ');
if(segments.length < 2 || segments.length > 3)
continue;
let leftPadding = lines[i].substring(0, lines[i].indexOf(segments[0]));
if (segments.length === 2) segments = ('protected ' + lines[i].trim()).split(' ');
let camelCased = camelCase(segments[2]);
lines[i] = leftPadding + segments[0] + ' ' + segments[1] + ' ' + camelCased;
}
removeBlanks(lines);
}
function quickFixCS0108Logic(lines: string[]): void {
for (let i = 0; i < lines.length; ++i) {
let segments = lines[i].trim().split(' ');
if(segments.length < 2 || segments.length > 3)
continue;
let leftPadding = lines[i].substring(0, lines[i].indexOf(segments[0]));
if (segments.length === 2) segments = ('protected ' + lines[i].trim()).split(' ');
let camelCased = camelCase(segments[2]);
let properCased = camelCased.substring(0, 1).toUpperCase() + camelCased.substring(1, camelCased.length - 1);
let capitalizedWords = toCapitalizedWords(properCased);
lines[i] = leftPadding + '[Display(Name = "' + capitalizedWords + '"), Required] public new ' + segments[1] + ' ' + properCased + ' { get; set; }';
}
removeBlanks(lines);
}
function quickFixInstanceFieldToCalisthenicsLogic(lines: string[]): void {
for (let i = 0; i < lines.length; ++i) {
let segments = lines[i].trim().split(' ');
if(segments.length !== 2)
continue;
let leftPadding = lines[i].substring(0, lines[i].indexOf(segments[0]));
let type = segments[0];
let name = segments[1].split(';')[0];
let singularName = name;
if(name[name.length - 1] === 's') {
if(name[name.length - 2] === 'e') {
if(name[name.length - 3] === 'i') {
singularName = name.substring(0, singularName.length - 3) + 'y';
}
else
singularName = name.substring(0, singularName.length - 2);
}
else
singularName = name.substring(0, singularName.length - 1);
}
segments = type.split('<');
if(segments.length === 2)
lines[i] = leftPadding + 'public ' + segments[0] + '<' + singularName + '> ' + name + ' { get; } //' + segments[1].split('>')[0];
else {
segments = type.split('[');
if(segments.length === 2)
lines[i] = leftPadding + 'public ' + singularName + '[] ' + name + ' { get; } //' + segments[0];
else
lines[i] = leftPadding + 'public ' + singularName + ' ' + name + ' { get; } //' + type;
}
}
removeBlanks(lines);
}
function quickFixProperCasePropertiesLogic(lines: string[]): void {
for (let i = 0; i < lines.length; ++i) {
let segments = lines[i].trim().split(' ');
if(segments.length < 2 || segments.length > 3)
continue;
let leftPadding = lines[i].substring(0, lines[i].indexOf(segments[0]));
if (segments.length === 2) segments = ('protected ' + lines[i].trim()).split(' ');
let camelCased = camelCase(segments[2]);
let properCased = camelCased.substring(0, 1).toUpperCase() + camelCased.substring(1, camelCased.length - 1);
lines[i] = leftPadding + segments[0] + ' ' + segments[1] + ' ' + properCased + ';';
}
removeBlanks(lines);
}
function quickFixPublicLogic(lines: string[]): void {
for (let i = 0; i < lines.length; ++i) {
let segments = lines[i].trim().split(' ');
if(segments.length < 2 || segments.length > 3)
continue;
let leftPadding = lines[i].substring(0, lines[i].indexOf(segments[0]));
if (segments.length === 2) segments = ('protected ' + lines[i].trim()).split(' ');
let camelCased = camelCase(segments[2]);
let properCased = camelCased.substring(0, 1).toUpperCase() + camelCased.substring(1, camelCased.length - 1);
lines[i] = leftPadding + 'public ' + segments[1] + ' ' + properCased + ' => ' + camelCased;
}
removeBlanks(lines);
}
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 makeSorter(algorithm?: SortingAlgorithm): ArrayTransformer {
return function (lines: string[]): string[] {
return lines.sort(algorithm);
};
}
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 sortLengthLogic(lines: string[]): void {
lines.sort(function (a, b) {
// ASC -> a.length - b.length
// DESC -> b.length - a.length
return a.length - b.length || // sort by length, if equal then
a.localeCompare(b); // sort by dictionary order
});
removeBlanks(lines);
}
function cutEachLineLogic(lines: string[]): void {
for (let i = 0; i < lines.length; ++i) {
if (lines[i].length > 0 && lines[i].indexOf("|||") > 0) {
lines[i] = lines[i].substr(0, lines[i].indexOf("|||"));
}
lines[i] = lines[i].trim();
}
removeBlanks(lines);
}
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.cutEachLine: { cutEachLineLogic(lines); break; }
case LinesAction.expandSql: { expandSqlLogic(lines); break; }
case LinesAction.listToListFamily: { listToListFamilyLogic(lines); break; }
case LinesAction.listToListWrappedComma: { listToListWrappedCommaLogic(lines); break; }
case LinesAction.prettySql: { prettySqlLogic(lines); break; }
case LinesAction.quickFixCamelCaseProperties: { quickFixCamelCasePropertiesLogic(lines); break; }
case LinesAction.quickFixCS0108: { quickFixCS0108Logic(lines); break; }
case LinesAction.quickFixInstanceFieldToCalisthenics: { quickFixInstanceFieldToCalisthenicsLogic(lines); break; }
case LinesAction.quickFixProperCaseProperties: { quickFixProperCasePropertiesLogic(lines); break; }
case LinesAction.quickFixPublic: { quickFixPublicLogic(lines); break; }
case LinesAction.removeComment: { removeCommentLogic(lines); break; }
case LinesAction.sortLength: { sortLengthLogic(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 cutEachLine = () => linesFunction(LinesAction.cutEachLine);
export const expandSql = () => linesFunction(LinesAction.expandSql);
export const listToListFamily = () => linesFunction(LinesAction.listToListFamily);
export const listToListWrappedComma = () => linesFunction(LinesAction.listToListWrappedComma);
export const prettySql = () => linesFunction(LinesAction.prettySql);
export const quickFixCamelCaseProperties = () => linesFunction(LinesAction.quickFixCamelCaseProperties);
export const quickFixCS0108 = () => linesFunction(LinesAction.quickFixCS0108);
export const quickFixInstanceFieldToCalisthenics = () => linesFunction(LinesAction.quickFixInstanceFieldToCalisthenics);
export const quickFixProperCaseProperties = () => linesFunction(LinesAction.quickFixProperCaseProperties);
export const quickFixPublic = () => linesFunction(LinesAction.quickFixPublic);
export const pdsfToFixedWidth = () => linesFunction(LinesAction.pdsfToFixedWidth);
export const removeComment = () => linesFunction(LinesAction.removeComment);
export const sortLength = () => linesFunction(LinesAction.sortLength);
export const sortNormal = () => linesFunction(LinesAction.sortNormal);
export const unwrapSql = () => linesFunction(LinesAction.unwrapSql);
export const wrapSqlCSharp = () => linesFunction(LinesAction.wrapSqlCSharp);
export const wrapSqlVB = () => linesFunction(LinesAction.wrapSqlVB);

View 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();

View 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));
});
});

View 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);
}
});
});
}

View File

@ -0,0 +1,22 @@
{
"compilerOptions": {
"module": "commonjs",
"target": "es6",
"outDir": "out",
"lib": [
"es6"
],
"sourceMap": true,
"rootDir": "src",
"resolveJsonModule": true,
"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"
]
}

View 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"
}

View 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 doesnt 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).