From b2f0b3488555c4ef9fef25bd2f4dcd623803f0a0 Mon Sep 17 00:00:00 2001 From: Zeff Svoboda Date: Sun, 21 May 2017 21:41:36 -0700 Subject: [PATCH 1/3] Add custom delay command. --- extension.js | 54 ++++++++++++++++++++++++++++++++-------------------- package.json | 3 --- 2 files changed, 33 insertions(+), 24 deletions(-) diff --git a/extension.js b/extension.js index 8d0e940..b21f8d2 100644 --- a/extension.js +++ b/extension.js @@ -1,5 +1,4 @@ const vscode = require('vscode'); -const PromiseSeries = require('promise-series'); var activeContext; var disposables = []; @@ -14,33 +13,46 @@ function activate(context) { } exports.activate = activate; -function deactivate() { -} +function deactivate() {} exports.deactivate = deactivate; +function executeDelayCommand(action) { + return new Promise(resolve => { + const milliseconds = Array.isArray(action.args) ? action.args[0] : 0; + setTimeout(() => resolve(), milliseconds); + }); +} + +function executeCommand(action) { + // support objects so that we can pass arguments from user settings to the commands + if (typeof action === 'object') { + if (action.command === '$delay') { + return executeDelayCommand(action); + } else { + return vscode.commands.executeCommand(action.command, action.args); + } + } else { + // support commands as strings (no args) + return vscode.commands.executeCommand(action); + } +} + function loadMacros(context) { const settings = vscode.workspace.getConfiguration('macros'); - const macros = Object.keys(settings).filter((prop) => { + const macros = Object.keys(settings).filter(prop => { return prop !== 'has' && prop !== 'get' && prop !== 'update'; }); - macros.forEach((name) => { - const disposable = vscode.commands.registerCommand(`macros.${name}`, function () { - const series = new PromiseSeries(); - settings[name].forEach((action) => { - series.add(() => { - // support objects so that we can pass arguments from user settings to the commands - if (typeof action === "object"){ - vscode.commands.executeCommand(action.command, action.args); - } - // support commands as strings (no args) - else{ - vscode.commands.executeCommand(action); - } - }) - }) - return series.run(); - }) + macros.forEach(name => { + const disposable = vscode.commands.registerCommand( + `macros.${name}`, + function() { + return settings[name].reduce( + (promise, action) => promise.then(() => executeCommand(action)), + Promise.resolve() + ); + } + ); context.subscriptions.push(disposable); disposables.push(disposable); }); diff --git a/package.json b/package.json index 9221b03..961e9b0 100644 --- a/package.json +++ b/package.json @@ -31,8 +31,5 @@ "eslint": "^3.6.0", "@types/node": "^6.0.40", "@types/mocha": "^2.2.32" - }, - "dependencies": { - "promise-series": "^1.0.0" } } \ No newline at end of file From d884f40a3686454be0781b0d03c9abf41175c5ca Mon Sep 17 00:00:00 2001 From: Zeff Svoboda Date: Sun, 21 May 2017 21:49:26 -0700 Subject: [PATCH 2/3] Add configuration properties documentation. --- package.json | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index 961e9b0..466c2ed 100644 --- a/package.json +++ b/package.json @@ -18,7 +18,13 @@ "contributes": { "configuration": { "type": "object", - "title": "Macros configuration" + "title": "Macros configuration", + "properties": { + "macros": { + "type": "object", + "description": "The root element to define macros in." + } + } } }, "scripts": { From 88704802607bfce62c94f3bee303096d244e917f Mon Sep 17 00:00:00 2001 From: Zeff Svoboda Date: Sun, 21 May 2017 22:15:39 -0700 Subject: [PATCH 3/3] Update delay command to match normal args format. --- extension.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/extension.js b/extension.js index b21f8d2..af90804 100644 --- a/extension.js +++ b/extension.js @@ -18,8 +18,7 @@ exports.deactivate = deactivate; function executeDelayCommand(action) { return new Promise(resolve => { - const milliseconds = Array.isArray(action.args) ? action.args[0] : 0; - setTimeout(() => resolve(), milliseconds); + setTimeout(() => resolve(), action.args && action.args.milliseconds); }); }