diff --git a/scripts/Start-EditorServices.ps1 b/scripts/Start-EditorServices.ps1 index f434acba7f..94d72a59d7 100644 --- a/scripts/Start-EditorServices.ps1 +++ b/scripts/Start-EditorServices.ps1 @@ -54,13 +54,27 @@ param( $ConfirmInstall ) +# Are we running in PowerShell 2 or earlier? +if ($PSVersionTable.PSVersion.Major -le 2) { + $resultDetails = @{ + "status" = "failed" + "reason" = "unsupported" + "powerShellVersion" = $PSVersionTable.PSVersion.ToString() + }; + + # Notify the client that the services have started + Write-Output (ConvertTo-Json -InputObject $resultDetails -Compress) + + exit 0; +} + # Are we running in PowerShell 5 or later? $isPS5orLater = $PSVersionTable.PSVersion.Major -ge 5 # If PSReadline is present in the session, remove it so that runspace # management is easier -if ((Get-Module PSReadline).Count -ne 0) { - Remove-Module PSReadline +if ((Get-Module PSReadline).Count -gt 0) { + Remove-Module PSReadline -ErrorAction SilentlyContinue } # This variable will be assigned later to contain information about diff --git a/src/session.ts b/src/session.ts index af3f6f7bac..300bdda8a2 100644 --- a/src/session.ts +++ b/src/session.ts @@ -246,6 +246,15 @@ export class SessionManager { // Start the language service client this.startLanguageClient(sessionDetails.languageServicePort); } + else if (response["status"] === "failed") { + if (response["reason"] === "unsupported") { + this.setSessionFailure( + `PowerShell language features are only supported on PowerShell version 3 and above. The current version is ${response["powerShellVersion"]}.`) + } + else { + this.setSessionFailure(`PowerShell could not be started for an unknown reason '${response["reason"]}'`) + } + } else { // TODO: Handle other response cases } @@ -354,7 +363,6 @@ export class SessionManager { }, (reason) => { this.setSessionFailure("Could not start language service: ", reason); - this.updateExtensionFeatures(undefined); }); this.languageServerClient.start(); @@ -362,7 +370,6 @@ export class SessionManager { catch (e) { this.setSessionFailure("The language service could not be started: ", e); - this.updateExtensionFeatures(undefined); } } @@ -511,15 +518,34 @@ export class SessionManager { } private showSessionMenu() { - var menuItems: SessionMenuItem[] = [ - new SessionMenuItem( - `Current session: PowerShell ${this.versionDetails.displayVersion} (${this.versionDetails.architecture}) ${this.versionDetails.edition} Edition [${this.versionDetails.version}]`, - () => { vscode.commands.executeCommand("PowerShell.ShowLogs"); }), + var menuItems: SessionMenuItem[] = []; - new SessionMenuItem( - "Restart Current Session", - () => { this.restartSession(); }), - ]; + if (this.sessionStatus === SessionStatus.Initializing || + this.sessionStatus === SessionStatus.NotStarted || + this.sessionStatus === SessionStatus.Stopping) { + + // Don't show a menu for these states + return; + } + + if (this.sessionStatus === SessionStatus.Running) { + menuItems = [ + new SessionMenuItem( + `Current session: PowerShell ${this.versionDetails.displayVersion} (${this.versionDetails.architecture}) ${this.versionDetails.edition} Edition [${this.versionDetails.version}]`, + () => { vscode.commands.executeCommand("PowerShell.ShowLogs"); }), + + new SessionMenuItem( + "Restart Current Session", + () => { this.restartSession(); }), + ]; + } + else if (this.sessionStatus === SessionStatus.Failed) { + menuItems = [ + new SessionMenuItem( + `Session initialization failed, click here to show PowerShell extension logs`, + () => { vscode.commands.executeCommand("PowerShell.ShowLogs"); }), + ]; + } if (this.isWindowsOS) { var item32 =