diff --git a/.vscodeignore b/.vscodeignore index 443e05b..5baf067 100644 --- a/.vscodeignore +++ b/.vscodeignore @@ -11,7 +11,6 @@ **/*.zip node_modules/** out/** -out/test/** package-lock.json res/*.svg src/** diff --git a/README.md b/README.md index db10d3d..3a6a6bc 100644 --- a/README.md +++ b/README.md @@ -51,20 +51,21 @@ You can set different configuration options to control the format of GUIDs that * insertGuid.showUppercase: Show uppercase GUIDs (with and without braces) when presenting possible GUID formats to insert. The default is `false`. * insertGuid.showCodeSnippets: Show code snippets for C++ when presenting possible GUID formats to insert. The default is `true`. * insertGuid.pasteAutomatically: When not empty, paste the GUID in a specified format without showing selection menu. The default is "". The formatting options are: - * `{b}|{B}` inserts a braced string in lowercase `{b}` or uppercase `{B}` e.g., `{880c86bc-384c-4cce-9e9a-4f760ca755c4}` - * `{d}|{D}` inserts a hyphenated string in lowercase `{d}` or uppercase `{D}` e.g., `880c86bc-384c-4cce-9e9a-4f760ca755c4` - * `{n}|{N}` inserts an unformatted string in lowercase `{n}` or uppercase `{N}` e.g., `880c86bc384c4cce9e9a4f760ca755c4` - * `{x}|{X}` inserts a struct-formatted string in lowercase `{x}` or uppercase `{X}` e.g., `{0x880c86bc,0x384c,0x4cce,{0x9e,0x9a,0x4f,0x76,0x0c,0xa7,0x55,0xc4}}` - * `{x0}|{X0}` inserts the first four bytes as a hexadecimal string in lowercase `{x0}` or uppercase `{X0}` e.g., `0x880c86bc` - * `{x1}|{X1}` and `{x2}|{X2}` insert the second and third two bytes as a hexadecimal string in lowercase `{x1}` and `{x2}`, or uppercase `{X1}` and `{X2}` e.g., `0x384c` and `0x4cce` - * `{x3}|{X3}` through `{x10}|{X10}` insert the subsequent bytes individually as a hexadecimal string in lowercase `{x3}` or uppercase `{X3}` e.g., `0x9e` through `0xc4`. - * `{nl}` inserts a new line - * All other characters will be interpreted literally e.g., `new GUID("{D}")` inserts `new GUID("880C86BC-384C-4CCE-9E9A-4F760CA755C4")` + * `{b}` or `{B}` inserts a braced string in lowercase `{b}` or uppercase `{B}` e.g., `{880c86bc-384c-4cce-9e9a-4f760ca755c4}` + * `{d}` or `{D}` inserts a hyphenated string in lowercase `{d}` or uppercase `{D}` e.g., `880c86bc-384c-4cce-9e9a-4f760ca755c4` + * `{n}` or `{N}` inserts an unformatted string in lowercase `{n}` or uppercase `{N}` e.g., `880c86bc384c4cce9e9a4f760ca755c4` + * `{x}` or `{X}` inserts a struct-formatted string in lowercase `{x}` or uppercase `{X}` e.g., `{0x880c86bc,0x384c,0x4cce,{0x9e,0x9a,0x4f,0x76,0x0c,0xa7,0x55,0xc4}}` + * `{x0}` or `{X0}` inserts the first four bytes as a hexadecimal string in lowercase `{x0}` or uppercase `{X0}` e.g., `0x880c86bc` + * `{x1}` or `{X1}`, and `{x2}` or `{X2}` insert the second and third two bytes as a hexadecimal string in lowercase `{x1}` and `{x2}`, or uppercase `{X1}` and `{X2}` e.g., `0x384c` and `0x4cce` + * `{x3}` or `{X3}` through `{x10}` or `{X10}` insert the subsequent bytes individually as a hexadecimal string in lowercase `{x3}` or uppercase `{X3}` e.g., `0x9e` through `0xc4`. + * `\n` or `{nl}` inserts a new line + + All other characters will be interpreted literally e.g., `new GUID("{D}")` inserts `new GUID("880C86BC-384C-4CCE-9E9A-4F760CA755C4")` For example, to generate a `GUID` for the [windows](https://crates.io/crates/windows) crate, you could define: ```json - "const G: ::windows::core::GUID = ::windows::core::GUID {{nl} data1: 0x{x0},{nl} data2: 0x{x1},{nl} data3: 0x{x2},{nl} data4: [0x{x3}, 0x{x4}, 0x{x5}, 0x{x6}, 0x{x7}, 0x{x8}, 0x{x9}, 0x{x10}],{nl}};" + "const G: ::windows::core::GUID = ::windows::core::GUID {\n data1: 0x{x0},\n data2: 0x{x1},\n data3: 0x{x2},\n data4: [0x{x3}, 0x{x4}, 0x{x5}, 0x{x6}, 0x{x7}, 0x{x8}, 0x{x9}, 0x{x10}],\n};" ``` Which would insert a `GUID` like: diff --git a/package.json b/package.json index b3d850e..ed39854 100644 --- a/package.json +++ b/package.json @@ -29,25 +29,43 @@ "configuration": { "title": "Insert GUID", "properties": { + "insertGuid.formats": { + "type": "array", + "items": { + "type": "string" + }, + "minItems": 1, + "uniqueItems": true, + "default": null, + "order": 0, + "markdownDescription": "An array of string formats to display in a quick pick menu. Each line contains format specifiers from the list below:\n* `{b}` or `{B}` inserts a braced string in lowercase `{b}` or uppercase `{B}` e.g., `{880c86bc-384c-4cce-9e9a-4f760ca755c4}`\n* `{d}` or `{D}` inserts a hyphenated string in lowercase `{d}` or uppercase `{D}` e.g., `880c86bc-384c-4cce-9e9a-4f760ca755c4`\n* `{n}` or `{N}` inserts an unformatted string in lowercase `{n}` or uppercase `{N}` e.g., `880c86bc384c4cce9e9a4f760ca755c4`\n* `{x}` or `{X}` inserts a struct-formatted string in lowercase `{x}` or uppercase `{X}` e.g., `{0x880c86bc,0x384c,0x4cce,{0x9e,0x9a,0x4f,0x76,0x0c,0xa7,0x55\nxc4}}`\n* `{x0}` or `{X0}` inserts the first four bytes as a hexadecimal string in lowercase `{x0}` or uppercase `{X0}` e.g., `0x880c86bc`\n* `{x1}` or `{X1}`, and `{x2}` or `{X2}` insert the second and third two bytes as a hexadecimal string in lowercase `{x1}` and `{x2}`, or uppercase `{X1}` nd \n{X2}` e.g., `0x384c` and `0x4cce`\n* `{x3}` or `{X3}` through `{x10}` or `{X10}` insert the subsequent bytes individually as a hexadecimal string in lowercase `{x3}` or uppercase `{X3}` e.g.,\n0x9e` through `0xc4`.\n* `\\n` or `{nl}` inserts a new line\n\nAll other characters will be interpreted literally e.g., `new GUID(\"{D}\")` inserts `new GUID(\"880C86BC-384C-4CCE-9E9A-4F760CA755C4\")`" + }, "insertGuid.showLowercase": { "type": "boolean", "default": true, - "description": "Show lowercase GUIDs (with and without braces) when presenting possible GUID formats to insert." + "order": 1, + "description": "Show lowercase GUIDs (with and without braces) when presenting possible GUID formats to insert.", + "deprecationMessage": "Add desired lowercase formats to `#insertGuid.formats#`. This setting will be removed in a future version." }, "insertGuid.showUppercase": { "type": "boolean", "default": false, - "description": "Show uppercase GUIDs (with and without braces) when presenting possible GUID formats to insert." + "order": 2, + "description": "Show uppercase GUIDs (with and without braces) when presenting possible GUID formats to insert.", + "deprecationMessage": "Add desired uppercase formats to `#insertGuid.formats#`. This setting will be removed in a future version." }, "insertGuid.showCodeSnippets": { "type": "boolean", "default": true, - "description": "Show code snippets for C++ when presenting possible GUID formats to insert." + "order": 3, + "description": "Show code snippets for C++ when presenting possible GUID formats to insert.", + "deprecationMessage": "Add desired snippet formats to `#insertGuid.formats#`. This setting will be removed in a future version." }, "insertGuid.pasteAutomatically": { "type": "string", "default": "", - "markdownDescription": "Paste GUID without prompting using the specified format:\n* `{b}|{B}` inserts a braced string in lowercase `{b}` or uppercase `{B}` e.g., `{880c86bc-384c-4cce-9e9a-4f760ca755c4}`\n* `{d}|{D}` inserts a hyphenated string in lowercase `{d}` or uppercase `{D}` e.g., `880c86bc-384c-4cce-9e9a-4f760ca755c4`\n* `{n}|{N}` inserts an unformatted string in lowercase `{n}` or uppercase `{N}` e.g., `880c86bc384c4cce9e9a4f760ca755c4`\n* `{x}|{X}` inserts a struct-formatted string in lowercase `{x}` or uppercase `{X}` e.g., `{0x880c86bc,0x384c,0x4cce,{0x9e,0x9a,0x4f,0x76,0x0c,0xa7,0x55,0xc4}}`\n* `{x0}|{X0}` inserts the first four bytes as a hexadecimal string in lowercase `{x0}` or uppercase `{X0}` e.g., `0x880c86bc`\n* `{x1}|{X1}` and `{x2}|{X2}` insert the second and third two bytes as a hexadecimal string in lowercase `{x1}` and `{x2}`, or uppercase `{X1}` and `{X2}` e.g., `0x384c` and `0x4cce`\n* `{x3}|{X3}` through `{x10}|{X10}` insert the subsequent bytes individually as a hexadecimal string in lowercase `{x3}` or uppercase `{X3}` e.g., `0x9e` through `0xc4`.\n* `{nl}` inserts a new line\n* All other characters will be interpreted literally e.g., `new GUID(\"{D}\")` inserts `new GUID(\"880C86BC-384C-4CCE-9E9A-4F760CA755C4\")`" + "order": 4, + "markdownDescription": "Paste GUID without prompting using format specifiers described on `#insertGuid.formats#`." } } }, @@ -66,11 +84,6 @@ } ] }, - "activationEvents": [ - "onCommand:guid.insert", - "onCommand:guid.insertMany", - "onCommand:guid.insertEmpty" - ], "icon": "res/logo.png", "galleryBanner": { "color": "#252526", @@ -93,13 +106,13 @@ "watch": "webpack --watch", "watch-test": "tsc -p . -w", "pretest": "npm run compile-test", - "test": "node ./out/test/runTest.js", + "test": "node ./out/src/test/runTest.js", "package": "webpack --mode production --devtool hidden-source-map", "preversion": "npm test", "vscode:prepublish": "npm run package" }, "engines": { - "vscode": "^1.30.0" + "vscode": "^1.75.0" }, "dependencies": { "buffer": "^6.0.3", diff --git a/src/commands.ts b/src/commands.ts index dff3664..f4818d7 100644 --- a/src/commands.ts +++ b/src/commands.ts @@ -23,6 +23,7 @@ import * as vscode from 'vscode'; import * as util from 'util'; import { Guid } from './guid'; +import getSettings, { Settings } from './settings'; enum FormatType { LOWERCASE, @@ -50,10 +51,17 @@ class GuidPickItem implements vscode.QuickPickItem { private _guid: Guid; private readonly _format: GuidPickFormat; - constructor(index: number, guid: Guid, format: GuidPickFormat) { + constructor(index: number, guid: Guid, format: GuidPickFormat | string) { this._index = index; this._guid = guid; - this._format = format; + if (typeof format === 'string') { + this._format = { + format: (g) => g.format(format), + type: FormatType.CUSTOM, + }; + } else { + this._format = format; + } } get label(): string { @@ -192,16 +200,27 @@ export function insertEmptyCommand(textEditor: vscode.TextEditor, edit: vscode.T async function insertCommandImpl(textEditor: vscode.TextEditor, edit: vscode.TextEditorEdit, type: GuidGenerateType): Promise { const g = type === GuidGenerateType.EMPTY ? Guid.EMPTY : new Guid(); - const settings = vscode.workspace.getConfiguration('insertGuid'); - const showLowercase = settings.get('showLowercase', true); - const showUppercase = settings.get('showUppercase', false); - const showCodeSnippets = settings.get('showCodeSnippets', true); - const pasteAutomatically = settings.get('pasteAutomatically', ''); + const settings = getSettings(); + const formats = settings.formats; + const pasteAutomatically = settings.pasteAutomatically; + + let item: GuidPickItem; + if (formats !== null) { + const items: GuidPickItem[] = []; + let nextIndex = 0; - const items = getQuickPickItems(g, showLowercase, showUppercase, showCodeSnippets); - let item = items[0]; + for (const format of formats) { + items.push(new GuidPickItem(++nextIndex, g, format)); + } - if (pasteAutomatically !== '') { + const selection = await vscode.window.showQuickPick(items) + if (selection == null) { + // Selection canceled. + return + } + + item = selection + } else if (pasteAutomatically !== null) { // Format with the specified string and insert without user selection const customFormatter = { format: (g: Guid) => g.format(pasteAutomatically), @@ -210,6 +229,7 @@ async function insertCommandImpl(textEditor: vscode.TextEditor, edit: vscode.Tex item = new GuidPickItem(-1, g, customFormatter) } else { // Let user select format + const items = getQuickPickItems(g, settings); const selection = await vscode.window.showQuickPick(items) if (selection == null) { // Selection canceled. @@ -239,6 +259,8 @@ async function insertCommandImpl(textEditor: vscode.TextEditor, edit: vscode.Tex }); } +export type QuickPickSettings = Pick; + /** * Gets an array of items to display in the Quick Pick window. * @param guid The GUID to render in each Quick Pick item. @@ -247,14 +269,14 @@ async function insertCommandImpl(textEditor: vscode.TextEditor, edit: vscode.Tex * @param showCodeSnippets Indicates whether code snippet options should be included in the array. * @returns An array of items to display in the Quick Pick window. */ -export function getQuickPickItems(guid: Guid, showLowercase: boolean, showUppercase: boolean, showCodeSnippets: boolean): GuidPickItem[] { +export function getQuickPickItems(guid: Guid, settings: QuickPickSettings): GuidPickItem[] { const items: GuidPickItem[] = []; let nextIndex = 0; for (const format of FORMATS) { - if (((showLowercase || (!showUppercase && !showCodeSnippets)) && format.type === FormatType.LOWERCASE) || - (showUppercase && format.type === FormatType.UPPERCASE) || - (showCodeSnippets && format.type === FormatType.SNIPPET)) { + if (((settings.showLowercase || (!settings.showUppercase && !settings.showCodeSnippets)) && format.type === FormatType.LOWERCASE) || + (settings.showUppercase && format.type === FormatType.UPPERCASE) || + (settings.showCodeSnippets && format.type === FormatType.SNIPPET)) { const item = new GuidPickItem(++nextIndex, guid, format); items.push(item); } diff --git a/src/guid.ts b/src/guid.ts index 634572b..ec840e0 100644 --- a/src/guid.ts +++ b/src/guid.ts @@ -112,7 +112,7 @@ export class Guid { const fn = replacements[replacement] ret = ret.replace(replacement, fn(this)); } - return ret.replace(/\{nl\}/g, '\n'); + return ret.replace(/\{nl\}|\\n/g, '\n'); } /** diff --git a/src/settings.ts b/src/settings.ts new file mode 100644 index 0000000..7f56ead --- /dev/null +++ b/src/settings.ts @@ -0,0 +1,104 @@ +// The MIT License (MIT) +// +// Copyright (c) Heath Stewart +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in all +// copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. + +import { WorkspaceConfiguration, workspace } from 'vscode'; + +export interface Settings { + showLowercase: boolean + showUppercase: boolean + showCodeSnippets: boolean + pasteAutomatically: string + formats: string[] | null +}; + +export const DEFAULTS: Settings = { + showLowercase: true, + showUppercase: false, + showCodeSnippets: true, + pasteAutomatically: '', + formats: null, +}; + +// Use placeholder token that completely selects with double click. +const NAME_PLACEHOLDER: string = '__NAME__'; +const FORMATS: Array<{ format: string, type: 'LOWERCASE' | 'UPPERCASE' | 'SNIPPET' }> = [ + { + format: '{d}', + type: 'LOWERCASE', + }, + { + format: '{b}', + type: 'LOWERCASE', + }, + { + format: `// {b}\nstatic const struct GUID ${NAME_PLACEHOLDER} = {x}\n`, + type: 'SNIPPET', + }, + // TODO +]; + +class SettingsImpl implements Settings { + private readonly _settings: WorkspaceConfiguration; + constructor() { + this._settings = workspace.getConfiguration('insertGuid'); + } + + get showLowercase(): boolean { + return this._settings.get('showLowercase', DEFAULTS.showLowercase); + } + + get showUppercase(): boolean { + return this._settings.get('showUppercase', DEFAULTS.showUppercase); + } + + get showCodeSnippets(): boolean { + return this._settings.get('showCodeSnippets', DEFAULTS.showCodeSnippets); + } + + get pasteAutomatically(): string { + return this._settings.get('pasteAutomatically', DEFAULTS.pasteAutomatically); + } + + get formats(): string[] | null { + let formats = this._settings.get('formats'); + if (formats !== undefined && formats.length > 0) { + return formats; + } + + formats = new Array(); + for (const format of FORMATS) { + if (format.type === 'LOWERCASE' && this.showLowercase) { + formats.push(format.format); + } else if (format.type === 'UPPERCASE' && this.showUppercase) { + formats.push(format.format); + } else if (format.type === 'SNIPPET' && this.showCodeSnippets) { + formats.push(format.format); + } + } + + return formats; + } + + // TODO: Write migration route during start up to populate `formats` using `WorkspaceConfiguration.update`. +}; + +export default (): Settings => new SettingsImpl(); diff --git a/src/test/suite/commands.test.ts b/src/test/suite/commands.test.ts index a6bd8c5..eb80f18 100644 --- a/src/test/suite/commands.test.ts +++ b/src/test/suite/commands.test.ts @@ -22,12 +22,19 @@ import * as assert from 'assert'; import { Guid } from '../../guid'; -import { getQuickPickItems } from '../../commands'; +import { QuickPickSettings, getQuickPickItems } from '../../commands'; +import { DEFAULTS } from '../../settings'; + +const DEFAULT_OPTIONS: QuickPickSettings = { + showLowercase: DEFAULTS.showLowercase, + showUppercase: DEFAULTS.showUppercase, + showCodeSnippets: DEFAULTS.showCodeSnippets, +}; suite('Commands', () => { test('quick pick 1 is simple string with default options', () => { const g = new Guid('12341234-1234-1234-1234-123412341234'); - const items = getQuickPickItems(g, true, false, true); + const items = getQuickPickItems(g, DEFAULT_OPTIONS); assert.strictEqual(items.length, 6); @@ -39,7 +46,7 @@ suite('Commands', () => { test('quick pick 2 is registry string with default options', () => { const g = new Guid('12341234-1234-1234-1234-123412341234'); - const items = getQuickPickItems(g, true, false, true); + const items = getQuickPickItems(g, DEFAULT_OPTIONS); assert.strictEqual(items.length, 6); @@ -51,7 +58,7 @@ suite('Commands', () => { test('quick pick 3 is C structure with default options', () => { const g = new Guid('12341234-1234-1234-1234-123412341234'); - const items = getQuickPickItems(g, true, false, true); + const items = getQuickPickItems(g, DEFAULT_OPTIONS); assert.strictEqual(items.length, 6); @@ -68,7 +75,7 @@ suite('Commands', () => { test('quick pick 4 is C macro with default options', () => { const g = new Guid('12341234-1234-1234-1234-123412341234'); - const items = getQuickPickItems(g, true, false, true); + const items = getQuickPickItems(g, DEFAULT_OPTIONS); assert.strictEqual(items.length, 6); @@ -85,7 +92,7 @@ suite('Commands', () => { test('quick pick 5 is simple non-hyphenated string with default options', () => { const g = new Guid('12341234-1234-1234-1234-123412341234'); - const items = getQuickPickItems(g, true, false, true); + const items = getQuickPickItems(g, DEFAULT_OPTIONS); assert.strictEqual(items.length, 6); @@ -97,7 +104,7 @@ suite('Commands', () => { test('quick pick 6 is struct-like GUID', () => { const g = new Guid('12341234-1234-1234-1234-123412341234'); - const items = getQuickPickItems(g, true, false, true); + const items = getQuickPickItems(g, DEFAULT_OPTIONS); assert.strictEqual(items.length, 6); @@ -109,7 +116,7 @@ suite('Commands', () => { test('quick pick items are correct when all settings are true', () => { const g = new Guid('12341234-dead-beef-1234-123412341234'); - const items = getQuickPickItems(g, true, true, true); + const items = getQuickPickItems(g, { showLowercase: true, showUppercase: true, showCodeSnippets: true }); assert.strictEqual(items.length, 9); @@ -166,7 +173,7 @@ suite('Commands', () => { test('quick pick items are correct with only lowercase enabled', () => { const g = new Guid('12341234-dead-beef-1234-123412341234'); - const items = getQuickPickItems(g, true, false, false); + const items = getQuickPickItems(g, { showLowercase: true, showUppercase: false, showCodeSnippets: false }); assert.strictEqual(items.length, 3); @@ -188,7 +195,7 @@ suite('Commands', () => { test('quick pick items are correct with only uppercase enabled', () => { const g = new Guid('12341234-dead-beef-1234-123412341234'); - const items = getQuickPickItems(g, false, true, false); + const items = getQuickPickItems(g, { showLowercase: false, showUppercase: true, showCodeSnippets: false }); assert.strictEqual(items.length, 3); @@ -210,7 +217,7 @@ suite('Commands', () => { test('quick pick items are correct with only code snippets enabled', () => { const g = new Guid('12341234-dead-beef-1234-123412341234'); - const items = getQuickPickItems(g, false, false, true); + const items = getQuickPickItems(g, { showLowercase: false, showUppercase: false, showCodeSnippets: true }); assert.strictEqual(items.length, 3); @@ -237,7 +244,7 @@ suite('Commands', () => { test('quick pick items are correct with no code snippets enabled', () => { const g = new Guid('12341234-dead-beef-1234-123412341234'); - const items = getQuickPickItems(g, false, false, false); + const items = getQuickPickItems(g, { showLowercase: false, showUppercase: false, showCodeSnippets: false }); assert.strictEqual(items.length, 3); diff --git a/src/test/suite/guid.test.ts b/src/test/suite/guid.test.ts index 6e752ac..26653b5 100644 --- a/src/test/suite/guid.test.ts +++ b/src/test/suite/guid.test.ts @@ -129,7 +129,7 @@ suite('Guid', () => { test('returns proper string with format specifiers replaced', () => { const g = new Guid('9f0a1b2c-4e5f-6a7b-8c9d-0e1f2a3b4c5d'); - const format = 'const G: ::windows::core::GUID = ::windows::core::GUID {{nl} data1: 0x{x0},{nl} data2: 0x{x1},{nl} data3: 0x{x2},{nl} data4: [0x{x3}, 0x{x4}, 0x{x5}, 0x{x6}, 0x{x7}, 0x{x8}, 0x{x9}, 0x{x10}],{nl}};'; + const format = 'const G: ::windows::core::GUID = ::windows::core::GUID {\n data1: 0x{x0},{nl} data2: 0x{x1},\n data3: 0x{x2},{nl} data4: [0x{x3}, 0x{x4}, 0x{x5}, 0x{x6}, 0x{x7}, 0x{x8}, 0x{x9}, 0x{x10}],\n};'; const expected = `const G: ::windows::core::GUID = ::windows::core::GUID { data1: 0x9f0a1b2c, data2: 0x4e5f, diff --git a/src/test/suite/settings.test.ts b/src/test/suite/settings.test.ts new file mode 100644 index 0000000..09ddb58 --- /dev/null +++ b/src/test/suite/settings.test.ts @@ -0,0 +1,36 @@ +// The MIT License (MIT) +// +// Copyright (c) Heath Stewart +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in all +// copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. + +import * as assert from 'assert'; +import { contributes } from '../../../package.json'; +import { DEFAULTS } from '../../settings'; + +suite('Settings', () => { + test('DEFAULTS matches package.json configuration defaults', () => { + const properties = contributes.configuration.properties; + assert.strictEqual(properties['insertGuid.showLowercase'].default, DEFAULTS.showLowercase); + assert.strictEqual(properties['insertGuid.showUppercase'].default, DEFAULTS.showUppercase); + assert.strictEqual(properties['insertGuid.showCodeSnippets'].default, DEFAULTS.showCodeSnippets); + assert.strictEqual(properties['insertGuid.pasteAutomatically'].default, DEFAULTS.pasteAutomatically); + assert.strictEqual(properties['insertGuid.formats'].default, DEFAULTS.formats); + }) +}); diff --git a/tsconfig.json b/tsconfig.json index 4e7ccd4..8de07f2 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -7,11 +7,19 @@ ], "strict": true, "sourceMap": true, - "rootDir": "src", + "rootDirs": [ + "src", + "." + ], "outDir": "out", + "resolveJsonModule": true, "removeComments": true, "noUnusedLocals": true }, + "include": [ + "src/**/*", + "package.json" + ], "exclude": [ "node_modules", ".vscode-test",