From 7aa99f69705f68d4aacc42e9da0cabd3ff4603c0 Mon Sep 17 00:00:00 2001 From: AZMCode Date: Mon, 23 Aug 2021 10:27:50 -0400 Subject: [PATCH 1/2] Implementation of Feature Request in Issue #50 --- src/command.ts | 2 +- src/extension.ts | 6 +++--- src/multiCommand.ts | 6 ++++-- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/src/command.ts b/src/command.ts index 7cbfaa2..1c07813 100644 --- a/src/command.ts +++ b/src/command.ts @@ -6,7 +6,7 @@ export class Command { private readonly args: object | null ) {} - public execute() { + public execute(): Thenable{ if (this.args === null) { return vscode.commands.executeCommand(this.exe); } else { diff --git a/src/extension.ts b/src/extension.ts index 38f88ee..0c239e4 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -109,12 +109,12 @@ export function activate(context: vscode.ExtensionContext) { async (args = {}) => { try { if (args.command) { - await vscode.commands.executeCommand(args.command); + return await vscode.commands.executeCommand(args.command); } else if (args.sequence) { const multiCommand = createMultiCommand("", args); - await multiCommand.execute(); + return await multiCommand.execute(); } else { - await pickMultiCommand(); + return await pickMultiCommand(); } } catch (e) { vscode.window.showErrorMessage(`${e.message}`); diff --git a/src/multiCommand.ts b/src/multiCommand.ts index 5031206..a155c47 100644 --- a/src/multiCommand.ts +++ b/src/multiCommand.ts @@ -9,11 +9,13 @@ export class MultiCommand { readonly sequence: Array ) {} - public async execute() { + public async execute(): Promise> { + let lastOutput; for (let command of this.sequence) { - await command.execute(); + lastOutput = command.execute(); await delay(this.interval || 0); } + return lastOutput; } } From 9cd98e920077ea67529dee919b52d9f739a59153 Mon Sep 17 00:00:00 2001 From: AZMCode Date: Mon, 23 Aug 2021 10:52:58 -0400 Subject: [PATCH 2/2] Bug in previous version of PR. The double `await`s are necessary since the MultiCommand::execute() method is both async and is carrying a Thenable from the child command, which also needs to be unwrapped to mimick the return value correctly. --- src/extension.ts | 8 ++++---- src/multiCommand.ts | 5 +++-- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/src/extension.ts b/src/extension.ts index 0c239e4..69ee1bd 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -89,7 +89,7 @@ function refreshUserCommands(context: vscode.ExtensionContext) { context.subscriptions.push( vscode.commands.registerCommand(key, async () => { - await multiCommand.execute(); + await await multiCommand.execute(); }) ); }); @@ -112,9 +112,9 @@ export function activate(context: vscode.ExtensionContext) { return await vscode.commands.executeCommand(args.command); } else if (args.sequence) { const multiCommand = createMultiCommand("", args); - return await multiCommand.execute(); + return await await multiCommand.execute(); } else { - return await pickMultiCommand(); + return await await pickMultiCommand(); } } catch (e) { vscode.window.showErrorMessage(`${e.message}`); @@ -126,7 +126,7 @@ export function activate(context: vscode.ExtensionContext) { // this method is called when your extension is deactivated export function deactivate() {} -export async function pickMultiCommand() { +export async function pickMultiCommand(): Promise | undefined> { const picks = multiCommands.map((multiCommand) => { return { label: multiCommand.label || multiCommand.id, diff --git a/src/multiCommand.ts b/src/multiCommand.ts index a155c47..21b1f39 100644 --- a/src/multiCommand.ts +++ b/src/multiCommand.ts @@ -9,12 +9,13 @@ export class MultiCommand { readonly sequence: Array ) {} - public async execute(): Promise> { - let lastOutput; + public async execute(): Promise | unknown> { + let lastOutput: Thenable | undefined; for (let command of this.sequence) { lastOutput = command.execute(); await delay(this.interval || 0); } + return lastOutput; } }