diff --git a/src/features/Console.ts b/src/features/Console.ts index 1a80cf9b52..673c79108b 100644 --- a/src/features/Console.ts +++ b/src/features/Console.ts @@ -10,11 +10,12 @@ 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("evaluate"); export const OutputNotificationType = new NotificationType("output"); export const ExecutionStatusChangedNotificationType = - new NotificationType("powerShell/executionStatusChanged"); + new NotificationType("powerShell/executionStatusChanged"); export const ShowChoicePromptRequestType = new RequestType { @@ -196,7 +184,7 @@ export class ConsoleFeature extends LanguageClientConsumer { private handlers: vscode.Disposable[]; private resolveStatusBarPromise: (value?: {} | PromiseLike<{}>) => void; - constructor(private log: Logger) { + constructor(private log: Logger, private sessionManager: SessionManager) { super(); this.commands = [ vscode.commands.registerCommand("PowerShell.RunSelection", async () => { @@ -236,8 +224,6 @@ export class ConsoleFeature extends LanguageClientConsumer { } public dispose() { - // Make sure we cancel any status bar - this.clearStatusBar(); for (const command of this.commands) { command.dispose(); } @@ -257,44 +243,21 @@ export class ConsoleFeature extends LanguageClientConsumer { ShowInputPromptRequestType, (promptDetails) => showInputPrompt(promptDetails)), - // TODO: We're not receiving these events from the server any more. // 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 + switch (executionStatusDetails) { case ExecutionStatus.Running: - this.showExecutionStatus("PowerShell"); + this.sessionManager.setSessionBusyStatus(); break; - - // If the execution has stopped, destroy the previous notification case ExecutionStatus.Completed: case ExecutionStatus.Aborted: case ExecutionStatus.Failed: - this.clearStatusBar(); + this.sessionManager.setSessionRunningStatus(); 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(); - } - } } diff --git a/src/main.ts b/src/main.ts index 98f4a06305..d5dfd9ba74 100644 --- a/src/main.ts +++ b/src/main.ts @@ -3,7 +3,6 @@ "use strict"; -import path = require("path"); import vscode = require("vscode"); import TelemetryReporter from "@vscode/extension-telemetry"; import { DocumentSelector } from "vscode-languageclient"; @@ -150,7 +149,7 @@ export async function activate(context: vscode.ExtensionContext): Promise( "powerShell/getVersion"); -export const RunspaceChangedEventType = - new NotificationType( - "powerShell/runspaceChanged"); - export class SessionManager implements Middleware { public HostName: string; public HostVersion: string; @@ -502,21 +499,6 @@ Type 'help' to get help. } } - private setStatusBarVersionString(runspaceDetails: IRunspaceDetails) { - const psVersion = runspaceDetails.powerShellVersion; - - let versionString = - this.versionDetails.architecture === "x86" - ? `${psVersion.displayVersion} (${psVersion.architecture})` - : psVersion.displayVersion; - - if (runspaceDetails.runspaceType !== RunspaceType.Local) { - versionString += ` [${runspaceDetails.connectionString}]`; - } - - this.setSessionVersion(versionString); - } - private registerCommands(): void { this.registeredCommands = [ vscode.commands.registerCommand("PowerShell.RestartSession", async () => { await this.restartSession(); }), @@ -676,11 +658,6 @@ Type 'help' to get help. this.languageClient.onNotification( SendKeyPressNotificationType, () => { this.languageServerProcess.sendKeyPress(); }), - - // TODO: I'm not sure we're still receiving these notifications... - this.languageClient.onNotification( - RunspaceChangedEventType, - (runspaceDetails) => { this.setStatusBarVersionString(runspaceDetails); }), ] try { @@ -691,13 +668,9 @@ Type 'help' to get help. } this.versionDetails = await this.languageClient.sendRequest(PowerShellVersionRequestType); - + this.setSessionRunningStatus(); // This requires the version details to be set. this.sendTelemetryEvent("powershellVersionCheck", { powershellVersion: this.versionDetails.version }); - this.setSessionVersion(this.versionDetails.architecture === "x86" - ? `${this.versionDetails.displayVersion} (${this.versionDetails.architecture})` - : this.versionDetails.displayVersion); - // We haven't "started" until we're done getting the version information. this.started = true; @@ -753,30 +726,38 @@ Type 'help' to get help. case SessionStatus.NeverStarted: case SessionStatus.NotStarted: this.languageStatusItem.busy = false; - // @ts-ignore + this.languageStatusItem.severity = vscode.LanguageStatusSeverity.Information; + break; + case SessionStatus.Busy: + this.languageStatusItem.busy = true; this.languageStatusItem.severity = vscode.LanguageStatusSeverity.Information; break; case SessionStatus.Initializing: case SessionStatus.Stopping: this.languageStatusItem.busy = true; - // @ts-ignore this.languageStatusItem.severity = vscode.LanguageStatusSeverity.Warning; break; case SessionStatus.Failed: this.languageStatusItem.busy = false; - // @ts-ignore this.languageStatusItem.severity = vscode.LanguageStatusSeverity.Error; break; } } - private setSessionVersion(version: string): void { - // TODO: Accept a VersionDetails object instead of a string. + 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); } + public setSessionBusyStatus(): void { + this.setSessionStatus("Executing...", SessionStatus.Busy); + } + private async setSessionFailure(message: string, ...additionalMessages: string[]) { this.setSessionStatus("Initialization Error", SessionStatus.Failed); await this.log.writeAndShowError(message, ...additionalMessages);