Skip to content

Handle busy notification for all PowerShell tasks #4193

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 1 commit into from
Sep 30, 2022
Merged
Show file tree
Hide file tree
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
29 changes: 1 addition & 28 deletions src/features/Console.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,9 @@ import { ICheckboxQuickPickItem, showCheckboxQuickPick } from "../controls/check
import { Logger } from "../logging";
import Settings = require("../settings");
import { LanguageClientConsumer } from "../languageClientConsumer";
import { SessionManager } from "../session";

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

export const ShowChoicePromptRequestType =
new RequestType<IShowChoicePromptRequestArgs,
Expand Down Expand Up @@ -62,13 +59,6 @@ interface IShowInputPromptResponseBody {
promptCancelled: boolean;
}

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

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

constructor(private log: Logger, private sessionManager: SessionManager) {
constructor(private log: Logger) {
super();
this.commands = [
vscode.commands.registerCommand("PowerShell.RunSelection", async () => {
Expand Down Expand Up @@ -242,22 +231,6 @@ export class ConsoleFeature extends LanguageClientConsumer {
this.languageClient.onRequest(
ShowInputPromptRequestType,
(promptDetails) => showInputPrompt(promptDetails)),

// Set up status bar alerts for when PowerShell is executing a script.
this.languageClient.onNotification(
ExecutionStatusChangedNotificationType,
(executionStatusDetails) => {
switch (executionStatusDetails) {
case ExecutionStatus.Running:
this.sessionManager.setSessionBusyStatus();
break;
case ExecutionStatus.Completed:
case ExecutionStatus.Aborted:
case ExecutionStatus.Failed:
this.sessionManager.setSessionRunningStatus();
break;
}
})
]
}
}
2 changes: 1 addition & 1 deletion src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ export async function activate(context: vscode.ExtensionContext): Promise<IPower

// Features and command registrations that require language client
languageClientConsumers = [
new ConsoleFeature(logger, sessionManager),
new ConsoleFeature(logger),
new ExpandAliasFeature(logger),
new GetCommandsFeature(logger),
new ShowHelpFeature(logger),
Expand Down
45 changes: 33 additions & 12 deletions src/session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,9 @@ export type IReadSessionFileCallback = (details: IEditorServicesSessionDetails)
export const SendKeyPressNotificationType =
new NotificationType<void>("powerShell/sendKeyPress");

export const ExecutionBusyStatusNotificationType =
new NotificationType<boolean>("powerShell/executionBusyStatus");

export const PowerShellVersionRequestType =
new RequestType0<IPowerShellVersionDetails, void>(
"powerShell/getVersion");
Expand Down Expand Up @@ -530,7 +533,7 @@ Type 'help' to get help.
this.languageServerProcess.onExited(
async () => {
if (this.sessionStatus === SessionStatus.Running) {
this.setSessionStatus("Session Exited", SessionStatus.Failed);
this.setSessionStatus("Session Exited!", SessionStatus.Failed);
await this.promptForRestart();
}
});
Expand Down Expand Up @@ -658,6 +661,14 @@ Type 'help' to get help.
this.languageClient.onNotification(
SendKeyPressNotificationType,
() => { this.languageServerProcess.sendKeyPress(); }),

this.languageClient.onNotification(
ExecutionBusyStatusNotificationType,
(isBusy: boolean) => {
if (isBusy) { this.setSessionBusyStatus(); }
else { this.setSessionRunningStatus(); }
}
),
]

try {
Expand All @@ -668,7 +679,7 @@ Type 'help' to get help.
}

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

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

private setSessionStatus(statusText: string, status: SessionStatus): void {
this.sessionStatus = status;
this.languageStatusItem.detail = "PowerShell " + statusText;
this.languageStatusItem.detail = "PowerShell";

if (this.versionDetails !== undefined) {
const version = this.versionDetails.architecture === "x86"
? `${this.versionDetails.displayVersion} (${this.versionDetails.architecture})`
: this.versionDetails.displayVersion;

this.languageStatusItem.text = "$(terminal-powershell) " + version;
this.languageStatusItem.detail += " " + version;
}

if (statusText) {
this.languageStatusItem.detail += ": " + statusText;
}

switch (status) {
case SessionStatus.Running:
case SessionStatus.NeverStarted:
Expand All @@ -745,21 +771,16 @@ Type 'help' to get help.

}

public setSessionRunningStatus(): void {
const version = this.versionDetails.architecture === "x86"
? `${this.versionDetails.displayVersion} (${this.versionDetails.architecture})`
: this.versionDetails.displayVersion;

this.languageStatusItem.text = "$(terminal-powershell) " + version;
this.setSessionStatus(version, SessionStatus.Running);
private setSessionRunningStatus(): void {
this.setSessionStatus("", SessionStatus.Running);
}

public setSessionBusyStatus(): void {
private setSessionBusyStatus(): void {
this.setSessionStatus("Executing...", SessionStatus.Busy);
}

private async setSessionFailure(message: string, ...additionalMessages: string[]) {
this.setSessionStatus("Initialization Error", SessionStatus.Failed);
this.setSessionStatus("Initialization Error!", SessionStatus.Failed);
await this.log.writeAndShowError(message, ...additionalMessages);
}

Expand Down