From 13ef63bd110253a056485f203cb82c399ecd689c Mon Sep 17 00:00:00 2001 From: Robert Holt Date: Mon, 12 Mar 2018 15:49:49 -0700 Subject: [PATCH] Display PowerShell execution status in status bar. Add a notification listener for execution status events from the Language Server (Running, Completed, etc) and alter the status bar to inform the user when PowerShell is executing a script. --- src/features/Console.ts | 65 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) diff --git a/src/features/Console.ts b/src/features/Console.ts index ae1f6f87e6..29a7eda457 100644 --- a/src/features/Console.ts +++ b/src/features/Console.ts @@ -9,6 +9,8 @@ import { IFeature } from "../feature"; export const EvaluateRequestType = new RequestType("evaluate"); export const OutputNotificationType = new NotificationType("output"); +export const ExecutionStatusChangedNotificationType = + new NotificationType("powerShell/executionStatusChanged"); export const ShowChoicePromptRequestType = new RequestType { @@ -175,6 +198,7 @@ function onInputEntered(responseText: string): IShowInputPromptResponseBody { export class ConsoleFeature implements IFeature { private commands: vscode.Disposable[]; private languageClient: LanguageClient; + private resolveStatusBarPromise: (value?: {} | PromiseLike<{}>) => void; constructor() { this.commands = [ @@ -207,6 +231,8 @@ export class ConsoleFeature implements IFeature { } public dispose() { + // Make sure we cancel any status bar + this.clearStatusBar(); this.commands.forEach((command) => command.dispose()); } @@ -220,5 +246,44 @@ export class ConsoleFeature implements IFeature { this.languageClient.onRequest( ShowInputPromptRequestType, (promptDetails) => showInputPrompt(promptDetails, this.languageClient)); + + // Set up status bar alerts for when PowerShell is executing a script + this.languageClient.onNotification( + ExecutionStatusChangedNotificationType, + (executionStatusDetails) => { + switch (executionStatusDetails.executionStatus) { + // If execution has changed to running, make a notification + case ExecutionStatus.Running: + this.showExecutionStatus("PowerShell"); + break; + + // If the execution has stopped, destroy the previous notification + case ExecutionStatus.Completed: + case ExecutionStatus.Aborted: + case ExecutionStatus.Failed: + this.clearStatusBar(); + break; + } + }); + + } + + private showExecutionStatus(message: string) { + vscode.window.withProgress({ + location: vscode.ProgressLocation.Window, + }, (progress) => { + return new Promise((resolve, reject) => { + this.clearStatusBar(); + + this.resolveStatusBarPromise = resolve; + progress.report({ message }); + }); + }); + } + + private clearStatusBar() { + if (this.resolveStatusBarPromise) { + this.resolveStatusBarPromise(); + } } }