Skip to content

Add status bar notification when PowerShell is running #1227

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
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
65 changes: 65 additions & 0 deletions src/features/Console.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import { IFeature } from "../feature";

export const EvaluateRequestType = new RequestType<IEvaluateRequestArguments, void, void, void>("evaluate");
export const OutputNotificationType = new NotificationType<IOutputNotificationBody, void>("output");
export const ExecutionStatusChangedNotificationType =
new NotificationType<IExecutionStatusDetails, void>("powerShell/executionStatusChanged");

export const ShowChoicePromptRequestType =
new RequestType<IShowChoicePromptRequestArgs,
Expand All @@ -27,6 +29,12 @@ export interface IOutputNotificationBody {
output: string;
}

interface IExecutionStatusDetails {
executionOptions: IExecutionOptions;
executionStatus: ExecutionStatus;
hadErrors: boolean;
}

interface IChoiceDetails {
label: string;
helpMessage: string;
Expand Down Expand Up @@ -55,6 +63,21 @@ interface IShowInputPromptResponseBody {
promptCancelled: boolean;
}

enum ExecutionStatus {
Pending,
Running,
Failed,
Aborted,
Completed,
}

interface IExecutionOptions {
writeOutputToHost: boolean;
writeErrorsToHost: boolean;
addToHistory: boolean;
interruptCommandPrompt: boolean;
}

function showChoicePrompt(
promptDetails: IShowChoicePromptRequestArgs,
client: LanguageClient): Thenable<IShowChoicePromptResponseBody> {
Expand Down Expand Up @@ -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 = [
Expand Down Expand Up @@ -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());
}

Expand All @@ -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();
}
}
}