Skip to content

Commit 945b126

Browse files
rjmholtTylerLeonhardt
authored andcommitted
Display PowerShell execution status in status bar. (#1227)
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.
1 parent 6c1e30e commit 945b126

File tree

1 file changed

+65
-0
lines changed

1 file changed

+65
-0
lines changed

src/features/Console.ts

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ import { IFeature } from "../feature";
99

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

1315
export const ShowChoicePromptRequestType =
1416
new RequestType<IShowChoicePromptRequestArgs,
@@ -27,6 +29,12 @@ export interface IOutputNotificationBody {
2729
output: string;
2830
}
2931

32+
interface IExecutionStatusDetails {
33+
executionOptions: IExecutionOptions;
34+
executionStatus: ExecutionStatus;
35+
hadErrors: boolean;
36+
}
37+
3038
interface IChoiceDetails {
3139
label: string;
3240
helpMessage: string;
@@ -55,6 +63,21 @@ interface IShowInputPromptResponseBody {
5563
promptCancelled: boolean;
5664
}
5765

66+
enum ExecutionStatus {
67+
Pending,
68+
Running,
69+
Failed,
70+
Aborted,
71+
Completed,
72+
}
73+
74+
interface IExecutionOptions {
75+
writeOutputToHost: boolean;
76+
writeErrorsToHost: boolean;
77+
addToHistory: boolean;
78+
interruptCommandPrompt: boolean;
79+
}
80+
5881
function showChoicePrompt(
5982
promptDetails: IShowChoicePromptRequestArgs,
6083
client: LanguageClient): Thenable<IShowChoicePromptResponseBody> {
@@ -175,6 +198,7 @@ function onInputEntered(responseText: string): IShowInputPromptResponseBody {
175198
export class ConsoleFeature implements IFeature {
176199
private commands: vscode.Disposable[];
177200
private languageClient: LanguageClient;
201+
private resolveStatusBarPromise: (value?: {} | PromiseLike<{}>) => void;
178202

179203
constructor() {
180204
this.commands = [
@@ -207,6 +231,8 @@ export class ConsoleFeature implements IFeature {
207231
}
208232

209233
public dispose() {
234+
// Make sure we cancel any status bar
235+
this.clearStatusBar();
210236
this.commands.forEach((command) => command.dispose());
211237
}
212238

@@ -220,5 +246,44 @@ export class ConsoleFeature implements IFeature {
220246
this.languageClient.onRequest(
221247
ShowInputPromptRequestType,
222248
(promptDetails) => showInputPrompt(promptDetails, this.languageClient));
249+
250+
// Set up status bar alerts for when PowerShell is executing a script
251+
this.languageClient.onNotification(
252+
ExecutionStatusChangedNotificationType,
253+
(executionStatusDetails) => {
254+
switch (executionStatusDetails.executionStatus) {
255+
// If execution has changed to running, make a notification
256+
case ExecutionStatus.Running:
257+
this.showExecutionStatus("PowerShell");
258+
break;
259+
260+
// If the execution has stopped, destroy the previous notification
261+
case ExecutionStatus.Completed:
262+
case ExecutionStatus.Aborted:
263+
case ExecutionStatus.Failed:
264+
this.clearStatusBar();
265+
break;
266+
}
267+
});
268+
269+
}
270+
271+
private showExecutionStatus(message: string) {
272+
vscode.window.withProgress({
273+
location: vscode.ProgressLocation.Window,
274+
}, (progress) => {
275+
return new Promise((resolve, reject) => {
276+
this.clearStatusBar();
277+
278+
this.resolveStatusBarPromise = resolve;
279+
progress.report({ message });
280+
});
281+
});
282+
}
283+
284+
private clearStatusBar() {
285+
if (this.resolveStatusBarPromise) {
286+
this.resolveStatusBarPromise();
287+
}
223288
}
224289
}

0 commit comments

Comments
 (0)