Skip to content

Commit f5b45b3

Browse files
Handle busy notification for all PowerShell tasks (#4193)
1 parent 274e892 commit f5b45b3

File tree

3 files changed

+35
-41
lines changed

3 files changed

+35
-41
lines changed

src/features/Console.ts

+1-28
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,9 @@ import { ICheckboxQuickPickItem, showCheckboxQuickPick } from "../controls/check
1010
import { Logger } from "../logging";
1111
import Settings = require("../settings");
1212
import { LanguageClientConsumer } from "../languageClientConsumer";
13-
import { SessionManager } from "../session";
1413

1514
export const EvaluateRequestType = new RequestType<IEvaluateRequestArguments, void, void>("evaluate");
1615
export const OutputNotificationType = new NotificationType<IOutputNotificationBody>("output");
17-
export const ExecutionStatusChangedNotificationType =
18-
new NotificationType<ExecutionStatus>("powerShell/executionStatusChanged");
1916

2017
export const ShowChoicePromptRequestType =
2118
new RequestType<IShowChoicePromptRequestArgs,
@@ -62,13 +59,6 @@ interface IShowInputPromptResponseBody {
6259
promptCancelled: boolean;
6360
}
6461

65-
enum ExecutionStatus {
66-
Pending,
67-
Running,
68-
Failed,
69-
Aborted,
70-
Completed,
71-
}
7262

7363
function showChoicePrompt(
7464
promptDetails: IShowChoicePromptRequestArgs,
@@ -182,9 +172,8 @@ function onInputEntered(responseText: string): IShowInputPromptResponseBody {
182172
export class ConsoleFeature extends LanguageClientConsumer {
183173
private commands: vscode.Disposable[];
184174
private handlers: vscode.Disposable[];
185-
private resolveStatusBarPromise: (value?: {} | PromiseLike<{}>) => void;
186175

187-
constructor(private log: Logger, private sessionManager: SessionManager) {
176+
constructor(private log: Logger) {
188177
super();
189178
this.commands = [
190179
vscode.commands.registerCommand("PowerShell.RunSelection", async () => {
@@ -242,22 +231,6 @@ export class ConsoleFeature extends LanguageClientConsumer {
242231
this.languageClient.onRequest(
243232
ShowInputPromptRequestType,
244233
(promptDetails) => showInputPrompt(promptDetails)),
245-
246-
// Set up status bar alerts for when PowerShell is executing a script.
247-
this.languageClient.onNotification(
248-
ExecutionStatusChangedNotificationType,
249-
(executionStatusDetails) => {
250-
switch (executionStatusDetails) {
251-
case ExecutionStatus.Running:
252-
this.sessionManager.setSessionBusyStatus();
253-
break;
254-
case ExecutionStatus.Completed:
255-
case ExecutionStatus.Aborted:
256-
case ExecutionStatus.Failed:
257-
this.sessionManager.setSessionRunningStatus();
258-
break;
259-
}
260-
})
261234
]
262235
}
263236
}

src/main.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ export async function activate(context: vscode.ExtensionContext): Promise<IPower
149149

150150
// Features and command registrations that require language client
151151
languageClientConsumers = [
152-
new ConsoleFeature(logger, sessionManager),
152+
new ConsoleFeature(logger),
153153
new ExpandAliasFeature(logger),
154154
new GetCommandsFeature(logger),
155155
new ShowHelpFeature(logger),

src/session.ts

+33-12
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,9 @@ export type IReadSessionFileCallback = (details: IEditorServicesSessionDetails)
7373
export const SendKeyPressNotificationType =
7474
new NotificationType<void>("powerShell/sendKeyPress");
7575

76+
export const ExecutionBusyStatusNotificationType =
77+
new NotificationType<boolean>("powerShell/executionBusyStatus");
78+
7679
export const PowerShellVersionRequestType =
7780
new RequestType0<IPowerShellVersionDetails, void>(
7881
"powerShell/getVersion");
@@ -530,7 +533,7 @@ Type 'help' to get help.
530533
this.languageServerProcess.onExited(
531534
async () => {
532535
if (this.sessionStatus === SessionStatus.Running) {
533-
this.setSessionStatus("Session Exited", SessionStatus.Failed);
536+
this.setSessionStatus("Session Exited!", SessionStatus.Failed);
534537
await this.promptForRestart();
535538
}
536539
});
@@ -658,6 +661,14 @@ Type 'help' to get help.
658661
this.languageClient.onNotification(
659662
SendKeyPressNotificationType,
660663
() => { this.languageServerProcess.sendKeyPress(); }),
664+
665+
this.languageClient.onNotification(
666+
ExecutionBusyStatusNotificationType,
667+
(isBusy: boolean) => {
668+
if (isBusy) { this.setSessionBusyStatus(); }
669+
else { this.setSessionRunningStatus(); }
670+
}
671+
),
661672
]
662673

663674
try {
@@ -668,7 +679,7 @@ Type 'help' to get help.
668679
}
669680

670681
this.versionDetails = await this.languageClient.sendRequest(PowerShellVersionRequestType);
671-
this.setSessionRunningStatus(); // This requires the version details to be set.
682+
this.setSessionRunningStatus();
672683
this.sendTelemetryEvent("powershellVersionCheck", { powershellVersion: this.versionDetails.version });
673684

674685
// We haven't "started" until we're done getting the version information.
@@ -716,11 +727,26 @@ Type 'help' to get help.
716727
this.languageStatusItem = vscode.languages.createLanguageStatusItem("powershell", this.documentSelector);
717728
this.languageStatusItem.command = { title: statusTitle, command: this.ShowSessionMenuCommandName };
718729
this.languageStatusItem.text = "$(terminal-powershell)";
730+
this.languageStatusItem.detail = "PowerShell";
719731
}
720732

721733
private setSessionStatus(statusText: string, status: SessionStatus): void {
722734
this.sessionStatus = status;
723-
this.languageStatusItem.detail = "PowerShell " + statusText;
735+
this.languageStatusItem.detail = "PowerShell";
736+
737+
if (this.versionDetails !== undefined) {
738+
const version = this.versionDetails.architecture === "x86"
739+
? `${this.versionDetails.displayVersion} (${this.versionDetails.architecture})`
740+
: this.versionDetails.displayVersion;
741+
742+
this.languageStatusItem.text = "$(terminal-powershell) " + version;
743+
this.languageStatusItem.detail += " " + version;
744+
}
745+
746+
if (statusText) {
747+
this.languageStatusItem.detail += ": " + statusText;
748+
}
749+
724750
switch (status) {
725751
case SessionStatus.Running:
726752
case SessionStatus.NeverStarted:
@@ -745,21 +771,16 @@ Type 'help' to get help.
745771

746772
}
747773

748-
public setSessionRunningStatus(): void {
749-
const version = this.versionDetails.architecture === "x86"
750-
? `${this.versionDetails.displayVersion} (${this.versionDetails.architecture})`
751-
: this.versionDetails.displayVersion;
752-
753-
this.languageStatusItem.text = "$(terminal-powershell) " + version;
754-
this.setSessionStatus(version, SessionStatus.Running);
774+
private setSessionRunningStatus(): void {
775+
this.setSessionStatus("", SessionStatus.Running);
755776
}
756777

757-
public setSessionBusyStatus(): void {
778+
private setSessionBusyStatus(): void {
758779
this.setSessionStatus("Executing...", SessionStatus.Busy);
759780
}
760781

761782
private async setSessionFailure(message: string, ...additionalMessages: string[]) {
762-
this.setSessionStatus("Initialization Error", SessionStatus.Failed);
783+
this.setSessionStatus("Initialization Error!", SessionStatus.Failed);
763784
await this.log.writeAndShowError(message, ...additionalMessages);
764785
}
765786

0 commit comments

Comments
 (0)