Skip to content

Fix #401: Session startup should indicate if PS version is unsupported #406

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
Dec 19, 2016
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
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