Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add uppercase option #7

Merged
merged 6 commits into from
Jul 10, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@
],
"stopOnEntry": false,
"sourceMaps": true,
"outDir": "out/src",
"outFiles": [
"${workspaceRoot}/out/**/*.js"
],
"preLaunchTask": "npm"
},
{
Expand All @@ -25,7 +27,9 @@
],
"stopOnEntry": false,
"sourceMaps": true,
"outDir": "out/test",
"outFiles": [
"${workspaceRoot}/out/**/*.js"
],
"preLaunchTask": "npm"
}
]
Expand Down
2 changes: 1 addition & 1 deletion .vscode/tasks.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@
"--loglevel",
"silent"
],
"isWatching": true,
"isBackground": true,
"problemMatcher": "$tsc-watch"
}
6 changes: 5 additions & 1 deletion gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
var gulp = require('gulp');
var clean = require('gulp-clean');
var merge = require('gulp-merge');
var sourcemaps = require('gulp-sourcemaps');
var svgmin = require('gulp-svgmin');
var ts = require('gulp-typescript');

Expand All @@ -33,8 +34,11 @@ gulp.task('compile', function() {
.pipe(svgmin())
.pipe(gulp.dest('out/res/')),
project.src()
.pipe(sourcemaps.init())
.pipe(ts(project))
.js.pipe(gulp.dest('out'))
.js
.pipe(sourcemaps.write('./', { sourceRoot: '../' }))
.pipe(gulp.dest('out'))
);
});

Expand Down
21 changes: 21 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,26 @@
"description": "Insert a GUID at the current position."
}
],
"configuration": {
"title": "Insert GUID configuration",
"properties": {
"insertGuid.showLowercase": {
"type": "boolean",
"default": true,
"description": "Show lowercase GUIDs (with and without braces) when presenting possible GUID formats to insert."
},
"insertGuid.showUppercase": {
"type": "boolean",
"default": false,
"description": "Show uppercase GUIDs (with and without braces) when presenting possible GUID formats to insert."
},
"insertGuid.showCodeSnippets": {
"type": "boolean",
"default": true,
"description": "Show code snippets for C++ when presenting possible GUID formats to insert."
}
}
},
"keybindings": [
{
"command": "guid.insert",
Expand Down Expand Up @@ -49,6 +69,7 @@
"gulp-clean": "^0.3.1",
"gulp-merge": "^0.1.1",
"gulp-svgmin": "^1.2.1",
"gulp-sourcemaps": "^2.6.0",
"gulp-typescript": "^2.10.0",
"tsd": "^0.6.5",
"typescript": "^1.6.2",
Expand Down
45 changes: 36 additions & 9 deletions src/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,8 @@ export class GuidCommands {

// Use placeholder token that completely selects with double click.
private static _NAME : string = '__NAME__';
private static _formats : GuidPickFormat[] = [

private static _basicFormats : GuidPickFormat[] = [
{
format: (g) => {
return g.toString();
Expand All @@ -88,7 +89,9 @@ export class GuidCommands {
format: (g) => {
return g.toString('braced');
}
},
}
];
private static _codeSnippets : GuidPickFormat[] = [
{
named: true,
format: (g) => {
Expand Down Expand Up @@ -121,8 +124,12 @@ export class GuidCommands {
* @param edit {vscode.TextEditorEdit} A text edit builder for the intended change.
*/
static insertCommand(textEditor : vscode.TextEditor, edit : vscode.TextEditorEdit) {
let g = new Guid();
let items = GuidCommands.getQuickPickItems(g);
const g = new Guid();
const settings = vscode.workspace.getConfiguration('insertGuid');
const showLowercase = settings.get<boolean>('showLowercase');
const showUppercase = settings.get<boolean>('showUppercase');
const showCodeSnippets = settings.get<boolean>('showCodeSnippets');
const items = GuidCommands.getQuickPickItems(g, showLowercase, showUppercase, showCodeSnippets);

// Prompt the user for a format.
vscode.window.showQuickPick<GuidPickItem>(items)
Expand Down Expand Up @@ -153,15 +160,35 @@ export class GuidCommands {
/**
* Gets an array of items to display in the Quick Pick window.
* @param guid The GUID to render in each Quick Pick item.
* @param showLowercase Indicates whether lowercase options should be included in the array.
* @param showUppercase Indicates whether uppercase options should be included in the array.
* @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.
*/
static getQuickPickItems(guid : Guid) : GuidPickItem[] {
static getQuickPickItems(guid : Guid, showLowercase : boolean, showUppercase : boolean, showCodeSnippets : boolean) : GuidPickItem[] {
let items : GuidPickItem[] = [];
let nextIndex = 0;

GuidCommands._formats.forEach((format, index) => {
let item = new GuidPickItem(index + 1, guid, format);
items.push(item);
});
if (showLowercase || (!showUppercase && !showCodeSnippets)) {
for (const format of GuidCommands._basicFormats) {
const item = new GuidPickItem(++nextIndex, guid, format);
items.push(item);
}
}
if (showUppercase) {
for (const lowercaseFormat of GuidCommands._basicFormats) {
const item = new GuidPickItem(++nextIndex, guid, {
format: g => lowercaseFormat.format(g).toUpperCase()
});
items.push(item);
}
}
if (showCodeSnippets) {
for (const format of GuidCommands._codeSnippets) {
const item = new GuidPickItem(++nextIndex, guid, format);
items.push(item);
}
}

return items;
}
Expand Down
143 changes: 135 additions & 8 deletions test/commands.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ import {Guid} from '../src/guid';
import {GuidCommands} from '../src/commands';

suite('GuidCommands', () => {
test('quick pick 1 is simple string', () => {
test('quick pick 1 is simple string with default options', () => {
var g = Guid.parse('12341234-1234-1234-1234-123412341234');
var items = GuidCommands.getQuickPickItems(g);
var items = GuidCommands.getQuickPickItems(g, true, false, true);

assert.equal(items.length, 4);

Expand All @@ -38,9 +38,9 @@ suite('GuidCommands', () => {
assert.equal(item.text, '12341234-1234-1234-1234-123412341234');
});

test('quick pick 2 is registry string', () => {
test('quick pick 2 is registry string with default options', () => {
var g = Guid.parse('12341234-1234-1234-1234-123412341234');
var items = GuidCommands.getQuickPickItems(g);
var items = GuidCommands.getQuickPickItems(g, true, false, true);

assert.equal(items.length, 4);

Expand All @@ -50,9 +50,9 @@ suite('GuidCommands', () => {
assert.equal(item.text, '{12341234-1234-1234-1234-123412341234}');
});

test('quick pick 3 is C structure', () => {
test('quick pick 3 is C structure with default options', () => {
var g = Guid.parse('12341234-1234-1234-1234-123412341234');
var items = GuidCommands.getQuickPickItems(g);
var items = GuidCommands.getQuickPickItems(g, true, false, true);

assert.equal(items.length, 4);

Expand All @@ -67,9 +67,9 @@ suite('GuidCommands', () => {
);
});

test('quick pick 4 is C macro', () => {
test('quick pick 4 is C macro with default options', () => {
var g = Guid.parse('12341234-1234-1234-1234-123412341234');
var items = GuidCommands.getQuickPickItems(g);
var items = GuidCommands.getQuickPickItems(g, true, false, true);

assert.equal(items.length, 4);

Expand All @@ -83,4 +83,131 @@ suite('GuidCommands', () => {
'DEFINE_GUID(__NAME__, 0x12341234, 0x1234, 0x1234, 0x12, 0x34, 0x12, 0x34, 0x12, 0x34, 0x12, 0x34);\n'
);
});

test('quick pick items are correct when all settings are true', () => {
const g = Guid.parse('12341234-dead-beef-1234-123412341234');
const items = GuidCommands.getQuickPickItems(g, true, true, true);

assert.equal(items.length, 6);

const item1 = items[0];
assert.strictEqual(item1.label, '1');
assert.equal(item1.description, '12341234-dead-beef-1234-123412341234');
assert.equal(item1.text, '12341234-dead-beef-1234-123412341234');

const item2 = items[1];
assert.strictEqual(item2.label, '2');
assert.equal(item2.description, '{12341234-dead-beef-1234-123412341234}');
assert.equal(item2.text, '{12341234-dead-beef-1234-123412341234}');

const item3 = items[2];
assert.strictEqual(item3.label, '3');
assert.equal(item3.description, '12341234-DEAD-BEEF-1234-123412341234');
assert.equal(item3.text, '12341234-DEAD-BEEF-1234-123412341234');

const item4 = items[3];
assert.strictEqual(item4.label, '4');
assert.equal(item4.description, '{12341234-DEAD-BEEF-1234-123412341234}');
assert.equal(item4.text, '{12341234-DEAD-BEEF-1234-123412341234}');

const item5 = items[4];
assert.strictEqual(item5.label, '5');
assert.equal(item5.description,
'static const struct GUID __NAME__ = {0x12341234, 0xdead, 0xbeef, {0x12, 0x34, 0x12, 0x34, 0x12, 0x34, 0x12, 0x34}};'
);
assert.equal(item5.text,
'// {12341234-1234-1234-1234-123412341234}\n' +
'static const struct GUID __NAME__ = {0x12341234, 0xdead, 0xbeef, {0x12, 0x34, 0x12, 0x34, 0x12, 0x34, 0x12, 0x34}};\n'
);

const item6 = items[5];
assert.strictEqual(item5.label, '6');
assert.equal(item6.description,
'DEFINE_GUID(__NAME__, 0x12341234, 0xdead, 0xbeef, 0x12, 0x34, 0x12, 0x34, 0x12, 0x34, 0x12, 0x34);'
);
assert.equal(item6.text,
'// {12341234-1234-1234-1234-123412341234}\n' +
'DEFINE_GUID(__NAME__, 0x12341234, 0xdead, 0xbeef, 0x12, 0x34, 0x12, 0x34, 0x12, 0x34, 0x12, 0x34);\n'
);
});

test('quick pick items are correct with only lowercase enabled', () => {
const g = Guid.parse('12341234-dead-beef-1234-123412341234');
const items = GuidCommands.getQuickPickItems(g, true, false, false);

assert.equal(items.length, 2);

const item1 = items[0];
assert.strictEqual(item1.label, '1');
assert.equal(item1.description, '12341234-dead-beef-1234-123412341234');
assert.equal(item1.text, '12341234-dead-beef-1234-123412341234');

const item2 = items[1];
assert.strictEqual(item2.label, '2');
assert.equal(item2.description, '{12341234-dead-beef-1234-123412341234}');
assert.equal(item2.text, '{12341234-dead-beef-1234-123412341234}');
});

test('quick pick items are correct with only uppercase enabled', () => {
const g = Guid.parse('12341234-dead-beef-1234-123412341234');
const items = GuidCommands.getQuickPickItems(g, false, true, false);

assert.equal(items.length, 2);

const item1 = items[0];
assert.strictEqual(item1.label, '1');
assert.equal(item1.description, '12341234-DEAD-BEEF-1234-123412341234');
assert.equal(item1.text, '12341234-DEAD-BEEF-1234-123412341234');

const item2 = items[1];
assert.strictEqual(item2.label, '2');
assert.equal(item2.description, '{12341234-DEAD-BEEF-1234-123412341234}');
assert.equal(item2.text, '{12341234-DEAD-BEEF-1234-123412341234}');
});


test('quick pick items are correct with only code snippets enabled', () => {
const g = Guid.parse('12341234-dead-beef-1234-123412341234');
const items = GuidCommands.getQuickPickItems(g, false, true, false);

assert.equal(items.length, 2);

const item1 = items[0];
assert.strictEqual(item1.label, '5');
assert.equal(item1.description,
'static const struct GUID __NAME__ = {0x12341234, 0xdead, 0xbeef, {0x12, 0x34, 0x12, 0x34, 0x12, 0x34, 0x12, 0x34}};'
);
assert.equal(item1.text,
'// {12341234-1234-1234-1234-123412341234}\n' +
'static const struct GUID __NAME__ = {0x12341234, 0xdead, 0xbeef, {0x12, 0x34, 0x12, 0x34, 0x12, 0x34, 0x12, 0x34}};\n'
);

const item2 = items[1];
assert.strictEqual(item1.label, '6');
assert.equal(item2.description,
'DEFINE_GUID(__NAME__, 0x12341234, 0xdead, 0xbeef, 0x12, 0x34, 0x12, 0x34, 0x12, 0x34, 0x12, 0x34);'
);
assert.equal(item2.text,
'// {12341234-1234-1234-1234-123412341234}\n' +
'DEFINE_GUID(__NAME__, 0x12341234, 0xdead, 0xbeef, 0x12, 0x34, 0x12, 0x34, 0x12, 0x34, 0x12, 0x34);\n'
);
});

test('quick pick items are correct with no code snippets enabled', () => {
var g = Guid.parse('12341234-1234-1234-1234-123412341234');
var items = GuidCommands.getQuickPickItems(g, false, false, false);

assert.equal(items.length, 2);

// with all options set to false, only the lowercase options are shown
const item1 = items[0];
assert.strictEqual(item1.label, '1');
assert.equal(item1.description, '12341234-dead-beef-1234-123412341234');
assert.equal(item1.text, '12341234-dead-beef-1234-123412341234');

const item2 = items[1];
assert.strictEqual(item2.label, '2');
assert.equal(item2.description, '{12341234-dead-beef-1234-123412341234}');
assert.equal(item2.text, '{12341234-dead-beef-1234-123412341234}');
});
});