Skip to content
Open
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
53 changes: 32 additions & 21 deletions extension.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
const vscode = require('vscode');
const PromiseSeries = require('promise-series');

var activeContext;
var disposables = [];
Expand All @@ -14,33 +13,45 @@ function activate(context) {
}
exports.activate = activate;

function deactivate() {
}
function deactivate() {}
exports.deactivate = deactivate;

function executeDelayCommand(action) {
return new Promise(resolve => {
setTimeout(() => resolve(), action.args && action.args.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);
});
Expand Down
11 changes: 7 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand All @@ -31,8 +37,5 @@
"eslint": "^3.6.0",
"@types/node": "^6.0.40",
"@types/mocha": "^2.2.32"
},
"dependencies": {
"promise-series": "^1.0.0"
}
}