Skip to content

Commit

Permalink
Merge pull request PowerShell#406 from PowerShell/daviwil/fix-401
Browse files Browse the repository at this point in the history
Fix PowerShell#401: Session startup should indicate if PS version is unsupported
  • Loading branch information
daviwil authored Dec 19, 2016
2 parents e41652b + 3b4ba8e commit 1a1b6e0
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 12 deletions.
18 changes: 16 additions & 2 deletions scripts/Start-EditorServices.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
46 changes: 36 additions & 10 deletions src/session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -354,15 +363,13 @@ export class SessionManager {
},
(reason) => {
this.setSessionFailure("Could not start language service: ", reason);
this.updateExtensionFeatures(undefined);
});

this.languageServerClient.start();
}
catch (e)
{
this.setSessionFailure("The language service could not be started: ", e);
this.updateExtensionFeatures(undefined);
}
}

Expand Down Expand Up @@ -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 =
Expand Down

0 comments on commit 1a1b6e0

Please sign in to comment.