diff --git a/extension/src/Template/TaskRunner.ts b/extension/src/Template/TaskRunner.ts index c0c95355d..abdc2ab61 100644 --- a/extension/src/Template/TaskRunner.ts +++ b/extension/src/Template/TaskRunner.ts @@ -39,19 +39,22 @@ export class TaskRunner { if (this.isReloadingCommand(task.command)) { this.deleteTaskFile(task); } - await vscode.commands.executeCommand(task.command).then( - () => { - /** - * NOTE: We have no guarantee that this will trigger when running arbitrary commands. - * - * Commands triggering reload should be added to TaskRunner.reloadingCommands. - */ - this.deleteTaskFile(task); - }, - (reason) => { - throw new Error(reason); - } - ); + + await vscode.commands + .executeCommand(task.command, task.arguments ?? []) + .then( + () => { + /** + * NOTE: We have no guarantee that this will trigger when running arbitrary commands. + * + * Commands triggering reload should be added to TaskRunner.reloadingCommands. + */ + this.deleteTaskFile(task); + }, + (reason) => { + throw new Error(reason); + } + ); if (task.reloadWindow) { await vscode.commands.executeCommand(this.reloadingCommands.reloadWindow); } diff --git a/extension/src/Template/TaskRunnerItem.ts b/extension/src/Template/TaskRunnerItem.ts index c65c653dd..11fc4047e 100644 --- a/extension/src/Template/TaskRunnerItem.ts +++ b/extension/src/Template/TaskRunnerItem.ts @@ -1,7 +1,22 @@ +import { Position, Uri } from "vscode"; + export interface TaskRunnerItem { description: string; command: string; + arguments?: CommandParameter[]; openFile?: string; taskPath?: string; reloadWindow?: boolean; } + +// Allowed arguments types for vscode.commands.executeCommand +type CommandParameter = + | string + | boolean + | number + | undefined + | null + | Position + | Range + | Uri + | Location; diff --git a/extension/src/test/TaskRunner.test.ts b/extension/src/test/TaskRunner.test.ts index 04c4d75be..0e73d0674 100644 --- a/extension/src/test/TaskRunner.test.ts +++ b/extension/src/test/TaskRunner.test.ts @@ -152,4 +152,17 @@ suite("Task Runner Tests", function () { await taskRunner.executeAll(); }, "Unexpected rejection of promise."); }); + + test("Task with parameters", async function () { + const task: TaskRunnerItem = { + description: "Diff files.", + command: "vscode.openIssueReporter", + arguments: ["nabsolutions.nab-al-tools"], + }; + const taskRunner = new TaskRunner([]); + + await assert.doesNotReject(async () => { + await taskRunner.execute(task); + }, "Unexpected rejection of promise."); + }); }); diff --git a/extension/syntaxes/templateSettingsSyntax.json b/extension/syntaxes/templateSettingsSyntax.json index 598727441..0eea74d61 100644 --- a/extension/syntaxes/templateSettingsSyntax.json +++ b/extension/syntaxes/templateSettingsSyntax.json @@ -254,6 +254,10 @@ "type": "string", "minLength": 1 }, + "arguments": { + "description": "Specifies arguments passed with the command to vscode.commands.executeCommand. Note that not all commands support arguments.", + "type": "array" + }, "openFile": { "description": "Specifies a file path to be opened before running the task. The path should be relative to the workspace root.", "type": "string"