Skip to content

Commit

Permalink
Extensions Refactor. Add test to ensure all keybindings have handlers
Browse files Browse the repository at this point in the history
  • Loading branch information
jpoon committed Nov 29, 2015
1 parent 105b6a9 commit 33e0c21
Show file tree
Hide file tree
Showing 3 changed files with 97 additions and 76 deletions.
149 changes: 74 additions & 75 deletions extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,89 +14,88 @@ var modeHandler;
export function activate(context: vscode.ExtensionContext) {
modeHandler = new ModeHandler();

// 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 "vim" is now active!');

var cmdLineDisposable = vscode.commands.registerCommand('extension.showCmdLine', () => {
showCmdLine();
});
registerCommand(context, 'extension.showCmdLine', () => showCmdLine());

vscode.commands.registerCommand('extension.vim_esc', () => handleKeyEvent("esc"));
vscode.commands.registerCommand('extension.vim_colon', () => handleKeyEvent(":"));
vscode.commands.registerCommand('extension.vim_space', () => handleKeyEvent("space"));
registerCommand(context, 'extension.vim_esc', () => handleKeyEvent("esc"));
registerCommand(context, 'extension.vim_colon', () => handleKeyEvent(":"));
registerCommand(context, 'extension.vim_space', () => handleKeyEvent("space"));

vscode.commands.registerCommand('extension.vim_a', () => handleKeyEvent("a"));
vscode.commands.registerCommand('extension.vim_b', () => handleKeyEvent("b"));
vscode.commands.registerCommand('extension.vim_c', () => handleKeyEvent("c"));
vscode.commands.registerCommand('extension.vim_d', () => handleKeyEvent("d"));
vscode.commands.registerCommand('extension.vim_e', () => handleKeyEvent("e"));
vscode.commands.registerCommand('extension.vim_f', () => handleKeyEvent("f"));
vscode.commands.registerCommand('extension.vim_g', () => handleKeyEvent("g"));
vscode.commands.registerCommand('extension.vim_h', () => handleKeyEvent("h"));
vscode.commands.registerCommand('extension.vim_i', () => handleKeyEvent("i"));
vscode.commands.registerCommand('extension.vim_j', () => handleKeyEvent("j"));
vscode.commands.registerCommand('extension.vim_k', () => handleKeyEvent("k"));
vscode.commands.registerCommand('extension.vim_l', () => handleKeyEvent("l"));
vscode.commands.registerCommand('extension.vim_m', () => handleKeyEvent("m"));
vscode.commands.registerCommand('extension.vim_n', () => handleKeyEvent("n"));
vscode.commands.registerCommand('extension.vim_o', () => handleKeyEvent("o"));
vscode.commands.registerCommand('extension.vim_p', () => handleKeyEvent("p"));
vscode.commands.registerCommand('extension.vim_q', () => handleKeyEvent("q"));
vscode.commands.registerCommand('extension.vim_r', () => handleKeyEvent("r"));
vscode.commands.registerCommand('extension.vim_s', () => handleKeyEvent("s"));
vscode.commands.registerCommand('extension.vim_t', () => handleKeyEvent("t"));
vscode.commands.registerCommand('extension.vim_u', () => handleKeyEvent("u"));
vscode.commands.registerCommand('extension.vim_v', () => handleKeyEvent("v"));
vscode.commands.registerCommand('extension.vim_w', () => handleKeyEvent("w"));
vscode.commands.registerCommand('extension.vim_x', () => handleKeyEvent("x"));
vscode.commands.registerCommand('extension.vim_y', () => handleKeyEvent("y"));
vscode.commands.registerCommand('extension.vim_z', () => handleKeyEvent("z"));
registerCommand(context, 'extension.vim_a', () => handleKeyEvent("a"));
registerCommand(context, 'extension.vim_b', () => handleKeyEvent("b"));
registerCommand(context, 'extension.vim_c', () => handleKeyEvent("c"));
registerCommand(context, 'extension.vim_d', () => handleKeyEvent("d"));
registerCommand(context, 'extension.vim_e', () => handleKeyEvent("e"));
registerCommand(context, 'extension.vim_f', () => handleKeyEvent("f"));
registerCommand(context, 'extension.vim_g', () => handleKeyEvent("g"));
registerCommand(context, 'extension.vim_h', () => handleKeyEvent("h"));
registerCommand(context, 'extension.vim_i', () => handleKeyEvent("i"));
registerCommand(context, 'extension.vim_j', () => handleKeyEvent("j"));
registerCommand(context, 'extension.vim_k', () => handleKeyEvent("k"));
registerCommand(context, 'extension.vim_l', () => handleKeyEvent("l"));
registerCommand(context, 'extension.vim_m', () => handleKeyEvent("m"));
registerCommand(context, 'extension.vim_n', () => handleKeyEvent("n"));
registerCommand(context, 'extension.vim_o', () => handleKeyEvent("o"));
registerCommand(context, 'extension.vim_p', () => handleKeyEvent("p"));
registerCommand(context, 'extension.vim_q', () => handleKeyEvent("q"));
registerCommand(context, 'extension.vim_r', () => handleKeyEvent("r"));
registerCommand(context, 'extension.vim_s', () => handleKeyEvent("s"));
registerCommand(context, 'extension.vim_t', () => handleKeyEvent("t"));
registerCommand(context, 'extension.vim_u', () => handleKeyEvent("u"));
registerCommand(context, 'extension.vim_v', () => handleKeyEvent("v"));
registerCommand(context, 'extension.vim_w', () => handleKeyEvent("w"));
registerCommand(context, 'extension.vim_x', () => handleKeyEvent("x"));
registerCommand(context, 'extension.vim_y', () => handleKeyEvent("y"));
registerCommand(context, 'extension.vim_z', () => handleKeyEvent("z"));

vscode.commands.registerCommand('extension.vim_A', () => handleKeyEvent("A"));
vscode.commands.registerCommand('extension.vim_B', () => handleKeyEvent("B"));
vscode.commands.registerCommand('extension.vim_C', () => handleKeyEvent("C"));
vscode.commands.registerCommand('extension.vim_D', () => handleKeyEvent("D"));
vscode.commands.registerCommand('extension.vim_E', () => handleKeyEvent("E"));
vscode.commands.registerCommand('extension.vim_F', () => handleKeyEvent("F"));
vscode.commands.registerCommand('extension.vim_G', () => handleKeyEvent("G"));
vscode.commands.registerCommand('extension.vim_H', () => handleKeyEvent("H"));
vscode.commands.registerCommand('extension.vim_I', () => handleKeyEvent("I"));
vscode.commands.registerCommand('extension.vim_J', () => handleKeyEvent("J"));
vscode.commands.registerCommand('extension.vim_K', () => handleKeyEvent("K"));
vscode.commands.registerCommand('extension.vim_L', () => handleKeyEvent("L"));
vscode.commands.registerCommand('extension.vim_M', () => handleKeyEvent("M"));
vscode.commands.registerCommand('extension.vim_N', () => handleKeyEvent("N"));
vscode.commands.registerCommand('extension.vim_O', () => handleKeyEvent("O"));
vscode.commands.registerCommand('extension.vim_P', () => handleKeyEvent("P"));
vscode.commands.registerCommand('extension.vim_Q', () => handleKeyEvent("Q"));
vscode.commands.registerCommand('extension.vim_R', () => handleKeyEvent("R"));
vscode.commands.registerCommand('extension.vim_S', () => handleKeyEvent("S"));
vscode.commands.registerCommand('extension.vim_T', () => handleKeyEvent("T"));
vscode.commands.registerCommand('extension.vim_U', () => handleKeyEvent("U"));
vscode.commands.registerCommand('extension.vim_V', () => handleKeyEvent("V"));
vscode.commands.registerCommand('extension.vim_W', () => handleKeyEvent("W"));
vscode.commands.registerCommand('extension.vim_X', () => handleKeyEvent("X"));
vscode.commands.registerCommand('extension.vim_Y', () => handleKeyEvent("Y"));
vscode.commands.registerCommand('extension.vim_Z', () => handleKeyEvent("Z"));
registerCommand(context, 'extension.vim_A', () => handleKeyEvent("A"));
registerCommand(context, 'extension.vim_B', () => handleKeyEvent("B"));
registerCommand(context, 'extension.vim_C', () => handleKeyEvent("C"));
registerCommand(context, 'extension.vim_D', () => handleKeyEvent("D"));
registerCommand(context, 'extension.vim_E', () => handleKeyEvent("E"));
registerCommand(context, 'extension.vim_F', () => handleKeyEvent("F"));
registerCommand(context, 'extension.vim_G', () => handleKeyEvent("G"));
registerCommand(context, 'extension.vim_H', () => handleKeyEvent("H"));
registerCommand(context, 'extension.vim_I', () => handleKeyEvent("I"));
registerCommand(context, 'extension.vim_J', () => handleKeyEvent("J"));
registerCommand(context, 'extension.vim_K', () => handleKeyEvent("K"));
registerCommand(context, 'extension.vim_L', () => handleKeyEvent("L"));
registerCommand(context, 'extension.vim_M', () => handleKeyEvent("M"));
registerCommand(context, 'extension.vim_N', () => handleKeyEvent("N"));
registerCommand(context, 'extension.vim_O', () => handleKeyEvent("O"));
registerCommand(context, 'extension.vim_P', () => handleKeyEvent("P"));
registerCommand(context, 'extension.vim_Q', () => handleKeyEvent("Q"));
registerCommand(context, 'extension.vim_R', () => handleKeyEvent("R"));
registerCommand(context, 'extension.vim_S', () => handleKeyEvent("S"));
registerCommand(context, 'extension.vim_T', () => handleKeyEvent("T"));
registerCommand(context, 'extension.vim_U', () => handleKeyEvent("U"));
registerCommand(context, 'extension.vim_V', () => handleKeyEvent("V"));
registerCommand(context, 'extension.vim_W', () => handleKeyEvent("W"));
registerCommand(context, 'extension.vim_X', () => handleKeyEvent("X"));
registerCommand(context, 'extension.vim_Y', () => handleKeyEvent("Y"));
registerCommand(context, 'extension.vim_Z', () => handleKeyEvent("Z"));

vscode.commands.registerCommand('extension.vim_0', () => handleKeyEvent("0"));
vscode.commands.registerCommand('extension.vim_1', () => handleKeyEvent("1"));
vscode.commands.registerCommand('extension.vim_2', () => handleKeyEvent("2"));
vscode.commands.registerCommand('extension.vim_3', () => handleKeyEvent("3"));
vscode.commands.registerCommand('extension.vim_4', () => handleKeyEvent("4"));
vscode.commands.registerCommand('extension.vim_5', () => handleKeyEvent("5"));
vscode.commands.registerCommand('extension.vim_6', () => handleKeyEvent("6"));
vscode.commands.registerCommand('extension.vim_7', () => handleKeyEvent("7"));
vscode.commands.registerCommand('extension.vim_8', () => handleKeyEvent("8"));
vscode.commands.registerCommand('extension.vim_9', () => handleKeyEvent("9"));
registerCommand(context, 'extension.vim_0', () => handleKeyEvent("0"));
registerCommand(context, 'extension.vim_1', () => handleKeyEvent("1"));
registerCommand(context, 'extension.vim_2', () => handleKeyEvent("2"));
registerCommand(context, 'extension.vim_3', () => handleKeyEvent("3"));
registerCommand(context, 'extension.vim_4', () => handleKeyEvent("4"));
registerCommand(context, 'extension.vim_5', () => handleKeyEvent("5"));
registerCommand(context, 'extension.vim_6', () => handleKeyEvent("6"));
registerCommand(context, 'extension.vim_7', () => handleKeyEvent("7"));
registerCommand(context, 'extension.vim_8', () => handleKeyEvent("8"));
registerCommand(context, 'extension.vim_9', () => handleKeyEvent("9"));

vscode.commands.registerCommand('extension.vim_ctrl_[', () => handleKeyEvent("ctrl+["));
registerCommand(context, 'extension.vim_ctrl_[', () => handleKeyEvent("ctrl+["));

vscode.commands.registerCommand('extension.vim_<', () => handleKeyEvent("<"));
vscode.commands.registerCommand('extension.vim_>', () => handleKeyEvent(">"));

context.subscriptions.push(cmdLineDisposable);
registerCommand(context, 'extension.vim_<', () => handleKeyEvent("<"));
registerCommand(context, 'extension.vim_>', () => handleKeyEvent(">"));
}

function registerCommand(context: vscode.ExtensionContext, command: string, callback: (...args: any[]) => any) {
let disposable = vscode.commands.registerCommand(command, callback);
context.subscriptions.push(disposable);
}

function handleKeyEvent(key:string) {
Expand Down
1 change: 0 additions & 1 deletion gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ var paths = {
tests_ts: "test/**/*.ts",
tests_js: [
// test with dependencies on 'vscode' do not run
"out/test/extension.test.js",
"out/test/cmd_line/lexer.test.js",
"out/test/cmd_line/scanner.test.js",
]
Expand Down
23 changes: 23 additions & 0 deletions test/extension.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import * as assert from 'assert';
import * as vscode from 'vscode';

suite("setup", () => {
test("all keys have handlers", (done) => {
let pkg = require(__dirname + '/../../package.json');
assert.ok(pkg);

vscode.commands.getCommands()
.then(registeredCommands => {
let keybindings = pkg.contributes.keybindings;
assert.ok(pkg);

for (let i = 0; i < keybindings.length; i++) {
let keybinding = keybindings[i];

var found = registeredCommands.indexOf(keybinding.command) < -1;
assert.ok(found, "Missing handler for key=" + keybinding.key + ". Expected handler=" + keybinding.command);
}
})
.then(done, done);
});
});

0 comments on commit 33e0c21

Please sign in to comment.