This commit is contained in:
Niels Kooiman
2020-02-13 10:17:38 +01:00
commit 6fd3ed82c2
12 changed files with 680 additions and 0 deletions

6
.gitignore vendored Normal file
View File

@@ -0,0 +1,6 @@
.DS_Store
npm-debug.log
Thumbs.db
/node_modules/
/out/
/.vs/

22
.vscode/launch.json vendored Normal file
View File

@@ -0,0 +1,22 @@
// 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": "Extension",
"type": "extensionHost",
"request": "launch",
"runtimeExecutable": "${execPath}",
"args": [
"--extensionDevelopmentPath=${workspaceFolder}"
],
"outFiles": [
"${workspaceFolder}/out/**/*.js"
],
"preLaunchTask": "npm: watch"
}
]
}

3
.vscode/settings.json vendored Normal file
View File

@@ -0,0 +1,3 @@
{
"editor.insertSpaces": false
}

20
.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
}
}
]
}

28
README.md Normal file
View File

@@ -0,0 +1,28 @@
# Document Editing Sample
This is an example that shows you how to create a command which makes changes to the document in the active editor.
## Demo
![demo](demo.gif)
## VS Code API
### `vscode` module
- [`commands.registerCommand`](https://code.visualstudio.com/api/references/vscode-api#commands.registerCommand)
- [`window.activeTextEditor`](https://code.visualstudio.com/api/references/vscode-api#window.activeTextEditor)
- [`TextDocument.getText`](https://code.visualstudio.com/api/references/vscode-api#TextDocument.getText)
- [`TextEditor.edit`](https://code.visualstudio.com/api/references/vscode-api#TextEditor.edit)
- [`TextEditorEdit`](https://code.visualstudio.com/api/references/vscode-api#TextEditorEdit)
### Contribution Points
- [`contributes.commands`](https://code.visualstudio.com/api/references/contribution-points#contributes.commands)
## Running the Sample
- Run `npm install` in terminal to install dependencies
- Run the `Run Extension` target in the Debug View. This will:
- Start a task `npm: watch` to compile the code
- Run the extension in a new VS Code window

BIN
demo.gif Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 312 KiB

323
package-lock.json generated Normal file
View File

@@ -0,0 +1,323 @@
{
"name": "reverseword",
"version": "0.0.1",
"lockfileVersion": 1,
"requires": true,
"dependencies": {
"@babel/code-frame": {
"version": "7.0.0",
"resolved": "https://registry.npmjs.org/@babel/code-frame/-/code-frame-7.0.0.tgz",
"integrity": "sha512-OfC2uemaknXr87bdLUkWog7nYuliM9Ij5HUcajsVcMCpQrcLmtxRbVFTIqmcSkSeYRBFBRxs2FiUqFJDLdiebA==",
"dev": true,
"requires": {
"@babel/highlight": "^7.0.0"
}
},
"@babel/highlight": {
"version": "7.0.0",
"resolved": "https://registry.npmjs.org/@babel/highlight/-/highlight-7.0.0.tgz",
"integrity": "sha512-UFMC4ZeFC48Tpvj7C8UgLvtkaUuovQX+5xNWrsIoMG8o2z+XFKjKaN9iVmS84dPwVN00W4wPmqvYoZF3EGAsfw==",
"dev": true,
"requires": {
"chalk": "^2.0.0",
"esutils": "^2.0.2",
"js-tokens": "^4.0.0"
}
},
"@types/node": {
"version": "6.14.4",
"resolved": "https://registry.npmjs.org/@types/node/-/node-6.14.4.tgz",
"integrity": "sha512-UqB7h2dVJr/KdZXRMJIhNUWT0HXVe9UNvfLCOsqiSGKAVaAp0QniYHlU9yegxyG6Ug2rc7VdAD4hYj3VghqvAw==",
"dev": true
},
"@types/vscode": {
"version": "1.33.0",
"resolved": "https://registry.npmjs.org/@types/vscode/-/vscode-1.33.0.tgz",
"integrity": "sha512-JSmGiValbrcG5g20jjCfKakLiuWyrcjVezj+SEAEZ4klXQktE5EtowuGlkLVqbkiBK4iY5wy/4yW8OjecuHnjQ==",
"dev": true
},
"ansi-styles": {
"version": "3.2.1",
"resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-3.2.1.tgz",
"integrity": "sha512-VT0ZI6kZRdTh8YyJw3SMbYm/u+NqfsAxEpWO0Pf9sq8/e94WxxOpPKx9FR1FlyCtOVDNOQ+8ntlqFxiRc+r5qA==",
"dev": true,
"requires": {
"color-convert": "^1.9.0"
}
},
"argparse": {
"version": "1.0.10",
"resolved": "https://registry.npmjs.org/argparse/-/argparse-1.0.10.tgz",
"integrity": "sha512-o5Roy6tNG4SL/FOkCAN6RzjiakZS25RLYFrcMttJqbdd8BWrnA+fGz57iN5Pb06pvBGvl5gQ0B48dJlslXvoTg==",
"dev": true,
"requires": {
"sprintf-js": "~1.0.2"
}
},
"balanced-match": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.0.tgz",
"integrity": "sha1-ibTRmasr7kneFk6gK4nORi1xt2c=",
"dev": true
},
"brace-expansion": {
"version": "1.1.11",
"resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.11.tgz",
"integrity": "sha512-iCuPHDFgrHX7H2vEI/5xpz07zSHB00TpugqhmYtVmMO6518mCuRMoOYFldEBl0g187ufozdaHgWKcYFb61qGiA==",
"dev": true,
"requires": {
"balanced-match": "^1.0.0",
"concat-map": "0.0.1"
}
},
"builtin-modules": {
"version": "1.1.1",
"resolved": "https://registry.npmjs.org/builtin-modules/-/builtin-modules-1.1.1.tgz",
"integrity": "sha1-Jw8HbFpywC9bZaR9+Uxf46J4iS8=",
"dev": true
},
"chalk": {
"version": "2.4.2",
"resolved": "https://registry.npmjs.org/chalk/-/chalk-2.4.2.tgz",
"integrity": "sha512-Mti+f9lpJNcwF4tWV8/OrTTtF1gZi+f8FqlyAdouralcFWFQWF2+NgCHShjkCb+IFBLq9buZwE1xckQU4peSuQ==",
"dev": true,
"requires": {
"ansi-styles": "^3.2.1",
"escape-string-regexp": "^1.0.5",
"supports-color": "^5.3.0"
}
},
"color-convert": {
"version": "1.9.3",
"resolved": "https://registry.npmjs.org/color-convert/-/color-convert-1.9.3.tgz",
"integrity": "sha512-QfAUtd+vFdAtFQcC8CCyYt1fYWxSqAiK2cSD6zDB8N3cpsEBAvRxp9zOGg6G/SHHJYAT88/az/IuDGALsNVbGg==",
"dev": true,
"requires": {
"color-name": "1.1.3"
}
},
"color-name": {
"version": "1.1.3",
"resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.3.tgz",
"integrity": "sha1-p9BVi9icQveV3UIyj3QIMcpTvCU=",
"dev": true
},
"commander": {
"version": "2.20.0",
"resolved": "https://registry.npmjs.org/commander/-/commander-2.20.0.tgz",
"integrity": "sha512-7j2y+40w61zy6YC2iRNpUe/NwhNyoXrYpHMrSunaMG64nRnaf96zO/KMQR4OyN/UnE5KLyEBnKHd4aG3rskjpQ==",
"dev": true
},
"concat-map": {
"version": "0.0.1",
"resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz",
"integrity": "sha1-2Klr13/Wjfd5OnMDajug1UBdR3s=",
"dev": true
},
"diff": {
"version": "3.5.0",
"resolved": "https://registry.npmjs.org/diff/-/diff-3.5.0.tgz",
"integrity": "sha512-A46qtFgd+g7pDZinpnwiRJtxbC1hpgf0uzP3iG89scHk0AUC7A1TGxf5OiiOUv/JMZR8GOt8hL900hV0bOy5xA==",
"dev": true
},
"escape-string-regexp": {
"version": "1.0.5",
"resolved": "https://registry.npmjs.org/escape-string-regexp/-/escape-string-regexp-1.0.5.tgz",
"integrity": "sha1-G2HAViGQqN/2rjuyzwIAyhMLhtQ=",
"dev": true
},
"esprima": {
"version": "4.0.1",
"resolved": "https://registry.npmjs.org/esprima/-/esprima-4.0.1.tgz",
"integrity": "sha512-eGuFFw7Upda+g4p+QHvnW0RyTX/SVeJBDM/gCtMARO0cLuT2HcEKnTPvhjV6aGeqrCB/sbNop0Kszm0jsaWU4A==",
"dev": true
},
"esutils": {
"version": "2.0.2",
"resolved": "https://registry.npmjs.org/esutils/-/esutils-2.0.2.tgz",
"integrity": "sha1-Cr9PHKpbyx96nYrMbepPqqBLrJs=",
"dev": true
},
"fs.realpath": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz",
"integrity": "sha1-FQStJSMVjKpA20onh8sBQRmU6k8=",
"dev": true
},
"glob": {
"version": "7.1.4",
"resolved": "https://registry.npmjs.org/glob/-/glob-7.1.4.tgz",
"integrity": "sha512-hkLPepehmnKk41pUGm3sYxoFs/umurYfYJCerbXEyFIWcAzvpipAgVkBqqT9RBKMGjnq6kMuyYwha6csxbiM1A==",
"dev": true,
"requires": {
"fs.realpath": "^1.0.0",
"inflight": "^1.0.4",
"inherits": "2",
"minimatch": "^3.0.4",
"once": "^1.3.0",
"path-is-absolute": "^1.0.0"
}
},
"has-flag": {
"version": "3.0.0",
"resolved": "https://registry.npmjs.org/has-flag/-/has-flag-3.0.0.tgz",
"integrity": "sha1-tdRU3CGZriJWmfNGfloH87lVuv0=",
"dev": true
},
"inflight": {
"version": "1.0.6",
"resolved": "https://registry.npmjs.org/inflight/-/inflight-1.0.6.tgz",
"integrity": "sha1-Sb1jMdfQLQwJvJEKEHW6gWW1bfk=",
"dev": true,
"requires": {
"once": "^1.3.0",
"wrappy": "1"
}
},
"inherits": {
"version": "2.0.3",
"resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.3.tgz",
"integrity": "sha1-Yzwsg+PaQqUC9SRmAiSA9CCCYd4=",
"dev": true
},
"js-tokens": {
"version": "4.0.0",
"resolved": "https://registry.npmjs.org/js-tokens/-/js-tokens-4.0.0.tgz",
"integrity": "sha512-RdJUflcE3cUzKiMqQgsCu06FPu9UdIJO0beYbPhHN4k6apgJtifcoCtT9bcxOpYBtpD2kCM6Sbzg4CausW/PKQ==",
"dev": true
},
"js-yaml": {
"version": "3.13.1",
"resolved": "https://registry.npmjs.org/js-yaml/-/js-yaml-3.13.1.tgz",
"integrity": "sha512-YfbcO7jXDdyj0DGxYVSlSeQNHbD7XPWvrVWeVUujrQEoZzWJIRrCPoyk6kL6IAjAG2IolMK4T0hNUe0HOUs5Jw==",
"dev": true,
"requires": {
"argparse": "^1.0.7",
"esprima": "^4.0.0"
}
},
"minimatch": {
"version": "3.0.4",
"resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.0.4.tgz",
"integrity": "sha512-yJHVQEhyqPLUTgt9B83PXu6W3rx4MvvHvSUvToogpwoGDOUQ+yDrR0HRot+yOCdCO7u4hX3pWft6kWBBcqh0UA==",
"dev": true,
"requires": {
"brace-expansion": "^1.1.7"
}
},
"minimist": {
"version": "0.0.8",
"resolved": "http://registry.npmjs.org/minimist/-/minimist-0.0.8.tgz",
"integrity": "sha1-hX/Kv8M5fSYluCKCYuhqp6ARsF0=",
"dev": true
},
"mkdirp": {
"version": "0.5.1",
"resolved": "http://registry.npmjs.org/mkdirp/-/mkdirp-0.5.1.tgz",
"integrity": "sha1-MAV0OOrGz3+MR2fzhkjWaX11yQM=",
"dev": true,
"requires": {
"minimist": "0.0.8"
}
},
"once": {
"version": "1.4.0",
"resolved": "https://registry.npmjs.org/once/-/once-1.4.0.tgz",
"integrity": "sha1-WDsap3WWHUsROsF9nFC6753Xa9E=",
"dev": true,
"requires": {
"wrappy": "1"
}
},
"path-is-absolute": {
"version": "1.0.1",
"resolved": "http://registry.npmjs.org/path-is-absolute/-/path-is-absolute-1.0.1.tgz",
"integrity": "sha1-F0uSaHNVNP+8es5r9TpanhtcX18=",
"dev": true
},
"path-parse": {
"version": "1.0.6",
"resolved": "https://registry.npmjs.org/path-parse/-/path-parse-1.0.6.tgz",
"integrity": "sha512-GSmOT2EbHrINBf9SR7CDELwlJ8AENk3Qn7OikK4nFYAu3Ote2+JYNVvkpAEQm3/TLNEJFD/xZJjzyxg3KBWOzw==",
"dev": true
},
"resolve": {
"version": "1.10.1",
"resolved": "https://registry.npmjs.org/resolve/-/resolve-1.10.1.tgz",
"integrity": "sha512-KuIe4mf++td/eFb6wkaPbMDnP6kObCaEtIDuHOUED6MNUo4K670KZUHuuvYPZDxNF0WVLw49n06M2m2dXphEzA==",
"dev": true,
"requires": {
"path-parse": "^1.0.6"
}
},
"semver": {
"version": "5.7.0",
"resolved": "https://registry.npmjs.org/semver/-/semver-5.7.0.tgz",
"integrity": "sha512-Ya52jSX2u7QKghxeoFGpLwCtGlt7j0oY9DYb5apt9nPlJ42ID+ulTXESnt/qAQcoSERyZ5sl3LDIOw0nAn/5DA==",
"dev": true
},
"sprintf-js": {
"version": "1.0.3",
"resolved": "https://registry.npmjs.org/sprintf-js/-/sprintf-js-1.0.3.tgz",
"integrity": "sha1-BOaSb2YolTVPPdAVIDYzuFcpfiw=",
"dev": true
},
"supports-color": {
"version": "5.5.0",
"resolved": "https://registry.npmjs.org/supports-color/-/supports-color-5.5.0.tgz",
"integrity": "sha512-QjVjwdXIt408MIiAqCX4oUKsgU2EqAGzs2Ppkm4aQYbjm+ZEWEcW4SfFNTr4uMNZma0ey4f5lgLrkB0aX0QMow==",
"dev": true,
"requires": {
"has-flag": "^3.0.0"
}
},
"tslib": {
"version": "1.9.3",
"resolved": "https://registry.npmjs.org/tslib/-/tslib-1.9.3.tgz",
"integrity": "sha512-4krF8scpejhaOgqzBEcGM7yDIEfi0/8+8zDRZhNZZ2kjmHJ4hv3zCbQWxoJGz1iw5U0Jl0nma13xzHXcncMavQ==",
"dev": true
},
"tslint": {
"version": "5.16.0",
"resolved": "https://registry.npmjs.org/tslint/-/tslint-5.16.0.tgz",
"integrity": "sha512-UxG2yNxJ5pgGwmMzPMYh/CCnCnh0HfPgtlVRDs1ykZklufFBL1ZoTlWFRz2NQjcoEiDoRp+JyT0lhBbbH/obyA==",
"dev": true,
"requires": {
"@babel/code-frame": "^7.0.0",
"builtin-modules": "^1.1.1",
"chalk": "^2.3.0",
"commander": "^2.12.1",
"diff": "^3.2.0",
"glob": "^7.1.1",
"js-yaml": "^3.13.0",
"minimatch": "^3.0.4",
"mkdirp": "^0.5.1",
"resolve": "^1.3.2",
"semver": "^5.3.0",
"tslib": "^1.8.0",
"tsutils": "^2.29.0"
}
},
"tsutils": {
"version": "2.29.0",
"resolved": "https://registry.npmjs.org/tsutils/-/tsutils-2.29.0.tgz",
"integrity": "sha512-g5JVHCIJwzfISaXpXE1qvNalca5Jwob6FjI4AoPlqMusJ6ftFE7IkkFoMhVLRgK+4Kx3gkzb8UZK5t5yTTvEmA==",
"dev": true,
"requires": {
"tslib": "^1.8.1"
}
},
"typescript": {
"version": "3.5.1",
"resolved": "https://registry.npmjs.org/typescript/-/typescript-3.5.1.tgz",
"integrity": "sha512-64HkdiRv1yYZsSe4xC1WVgamNigVYjlssIoaH2HcZF0+ijsk5YK2g0G34w9wJkze8+5ow4STd22AynfO6ZYYLw==",
"dev": true
},
"wrappy": {
"version": "1.0.2",
"resolved": "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz",
"integrity": "sha1-tSQ9jz7BqjXxNkYFvA0QNuMKtp8=",
"dev": true
}
}
}

87
package.json Normal file
View File

@@ -0,0 +1,87 @@
{
"name": "solidt-escaper",
"displayName": "Escape & code transform",
"description": "Escape & code transform",
"version": "0.0.1",
"publisher": "cogibucks",
"engines": {
"vscode": "^1.32.0"
},
"categories": [
"Other"
],
"activationEvents": [
"onCommand:extension.escapeDoubleQuote",
"onCommand:extension.escapeSingleQuote",
"onCommand:extension.unescapeDoubleQuote",
"onCommand:extension.unescapeSingleQuote",
"onCommand:extension.buildStringDoubleQuote",
"onCommand:extension.buildStringSingleQuote",
"onCommand:extension.buildStringJavascript",
"onCommand:extension.buildStringCsharp",
"onCommand:extension.reverseBuildStringDoubleQuote",
"onCommand:extension.reverseBuildStringSingleQuote",
"onCommand:extension.createCsharpAutoProperty"
],
"main": "./out/extension",
"contributes": {
"commands": [
{
"command": "extension.escapeDoubleQuote",
"title": "Solidt: Escape (double quotes)"
},
{
"command": "extension.escapeSingleQuote",
"title": "Solidt: Escape (single quotes)"
},
{
"command": "extension.unescapeDoubleQuote",
"title": "Solidt: Unescape (double quotes)"
},
{
"command": "extension.unescapeSingleQuote",
"title": "Solidt: Unescape (single quotes)"
},
{
"command": "extension.buildStringDoubleQuote",
"title": "Solidt: BuildString (double quotes)"
},
{
"command": "extension.buildStringSingleQuote",
"title": "Solidt: BuildString (single quotes)"
},
{
"command": "extension.buildStringJavascript",
"title": "Solidt: BuildString (Javascript)"
},
{
"command": "extension.buildStringSingleQuote",
"title": "Solidt: BuildString (C#)"
},
{
"command": "extension.reverseBuildStringDoubleQuote",
"title": "Solidt: Reverse BuildString (double quotes)"
},
{
"command": "extension.reverseBuildStringSingleQuote",
"title": "Solidt: Reverse BuildString (single quotes)"
},
{
"command": "extension.createCsharpAutoProperty",
"title": "Solidt: Create autoproperty (C#)"
}
]
},
"scripts": {
"vscode:prepublish": "npm run compile",
"compile": "tsc -p ./",
"lint": "tslint ./src/*.ts",
"watch": "tsc -watch -p ./"
},
"devDependencies": {
"@types/node": "^6.0.40",
"tslint": "^5.16.0",
"typescript": "^3.5.1",
"@types/vscode": "^1.32.0"
}
}

116
src/escape.ts Normal file
View File

@@ -0,0 +1,116 @@
const slash = "\\";
const slashslash = "\\\\";
function getEscapeChars(quote: string, doubleEscape: boolean) : { [key: string]: string } {
const chars = {
"\b": "\\b",
"\n": "\\n",
"\t": "\\t",
"\r": "\\r",
"\f": "\\f",
slash: slashslash
};
if (doubleEscape) {
(chars as any)[quote] = quote + quote;
} else {
(chars as any)[quote] = slash + quote;
}
return chars;
}
function getUnescapeChars(quote: string, doubleEscape: boolean) : { [key: string]: string } {
const chars = {
"\\b": "\b",
"\\n": "\n",
"\\t": "\t",
"\\r": "\r",
"\\f": "\f",
slashslash: slash
};
if (doubleEscape) {
(chars as any)[quote + quote] = quote;
} else {
(chars as any)[slash + quote] = quote;
}
return chars;
}
export function escapeStr(str: string, quote: string, doubleEscape: boolean): string {
let res = "";
const chars = getEscapeChars(quote, doubleEscape)
for (const c of String(str)) {
if (c in chars) {
res += chars[c];
} else {
res += c;
}
}
return res;
}
export function unescapeStr(str: string, quote: string, doubleEscape: boolean): string {
const chars = getUnescapeChars(quote, doubleEscape);
let res = String(str).replace(/(\\.)/gm, (group) => {
if (group in chars) {
return chars[group];
}
return group;
});
if (doubleEscape)
res = res.replace(quote + quote, quote);
return res;
}
export function buildString(text: string, quote: string, doubleEscape: boolean): string {
var lines = text.split('\n');
return lines.map(l => '\t' + quote + escapeStr(l, quote, doubleEscape) + quote).join(",\n");
};
export function buildStringCsharp(text: string): string {
const prefix = "var str = string.Join(Environment.NewLine, new string[] {\n";
const postfix = "\n});";
return `${prefix}${buildString(text, '"', false)}${postfix}`;
};
export function buildStringJavascript(text: string): string {
const prefix = "var str = [\n";
const postfix = "\n].join('\\n');";
return `${prefix}${buildString(text, '"', false)}${postfix}`;
};
const getMatches = (re: RegExp, str: string): any[] => {
let match, matches = [];
while (match = re.exec(str)) {
matches.push(match);
}
return matches;
};
export function reverseBuildString(text: string, quote: string, doubleEscape: boolean): string {
let regEx = new RegExp(quote + "(.*[^"+ slashslash +"])" + quote, "gm");
if (doubleEscape) {
regEx = new RegExp(quote + "(.*[^" + quote + "])" + quote, "gm");
}
return getMatches(regEx, text)
.map(m => unescapeStr(m[1], quote, doubleEscape))
.join("\n");
};
function lowerFirst(input: string) {
return input.charAt(0).toLowerCase() + input.slice(1)
}
export function createCsharpAutoProperty(input: string)
{
const [type, name] = input.split(" ");
const pname = "_" + lowerFirst(name);
const output = [
`private ${type} ${pname};`,
`public ${type} ${name}`,
"{",
`\tget => ${pname};`,
`\tset => SetPropertyValue(nameof(${name}), ref ${pname}, value);`,
"}"
].join("\n");
return output;
};

58
src/extension.ts Normal file
View File

@@ -0,0 +1,58 @@
'use strict';
import * as vscode from 'vscode';
import { escapeStr, unescapeStr, buildString, reverseBuildString, buildStringJavascript, buildStringCsharp, createCsharpAutoProperty } from "./escape";
type Replacer = (a: string) => string;
function run(replacer: Replacer)
{
// Get the active text editor
let editor = vscode.window.activeTextEditor;
if (editor) {
let document = editor.document;
let selection = editor.selection;
let selectedText = document.getText(selection);
let result = replacer(selectedText)
editor.edit(editBuilder => {
editBuilder.replace(selection, result);
});
}
}
const escapeDoubleQuote = (str: string): string => escapeStr(str, '"', false);
const escapeSingleQuote = (str: string): string => escapeStr(str, "'", false);
// const escapeBackTic = (str: string): string => escapeStr(str, "`", false);
// const escapeDoubleQuoteDoubled = (str: string): string => escapeStr(str, '"', true);
// const escapeSingleQuoteDoubled = (str: string): string => escapeStr(str, "'", true);
const unescapeDoubleQuote = (str: string): string => unescapeStr(str, '"', false);
const unescapeSingleQuote = (str: string): string => unescapeStr(str, "'", false);
const buildStringDoubleQuote = (str: string): string => buildString(str, '"', false);
const buildStringSingleQuote = (str: string): string => buildString(str, "'", false);
const reverseBuildStringDoubleQuote = (str: string): string => reverseBuildString(str, '"', false);
const reverseBuildStringSingleQuote = (str: string): string => reverseBuildString(str, "'", false);
export function activate(context: vscode.ExtensionContext) {
context.subscriptions.push(vscode.commands.registerCommand('extension.escapeDoubleQuote', () => run(escapeDoubleQuote)));
context.subscriptions.push(vscode.commands.registerCommand('extension.escapeSingleQuote', () => run(escapeSingleQuote)));
context.subscriptions.push(vscode.commands.registerCommand('extension.unescapeDoubleQuote', () => run(unescapeDoubleQuote)));
context.subscriptions.push(vscode.commands.registerCommand('extension.unescapeSingleQuote', () => run(unescapeSingleQuote)));
context.subscriptions.push(vscode.commands.registerCommand('extension.buildStringDoubleQuote', () => run(buildStringDoubleQuote)));
context.subscriptions.push(vscode.commands.registerCommand('extension.buildStringSingleQuote', () => run(buildStringSingleQuote)));
context.subscriptions.push(vscode.commands.registerCommand('extension.buildStringJavascript', () => run(buildStringJavascript)));
context.subscriptions.push(vscode.commands.registerCommand('extension.buildStringCsharp', () => run(buildStringCsharp)));
context.subscriptions.push(vscode.commands.registerCommand('extension.reverseBuildStringDoubleQuote', () => run(reverseBuildStringDoubleQuote)));
context.subscriptions.push(vscode.commands.registerCommand('extension.reverseBuildStringSingleQuote', () => run(reverseBuildStringSingleQuote)));
context.subscriptions.push(vscode.commands.registerCommand('extension.createCsharpAutoProperty', () => run(createCsharpAutoProperty)));
}

11
tsconfig.json Normal file
View File

@@ -0,0 +1,11 @@
{
"compilerOptions": {
"module": "commonjs",
"target": "es6",
"outDir": "out",
"sourceMap": true,
"strict": true,
"rootDir": "src"
},
"exclude": ["node_modules", ".vscode-test"]
}

6
tslint.json Normal file
View File

@@ -0,0 +1,6 @@
{
"rules": {
"indent": [true, "tabs"],
"semicolon": [true, "always"]
}
}