Skip to content

Commit 1a1b6e0

Browse files
authored
Merge pull request #406 from PowerShell/daviwil/fix-401
Fix #401: Session startup should indicate if PS version is unsupported
2 parents e41652b + 3b4ba8e commit 1a1b6e0

File tree

2 files changed

+52
-12
lines changed

2 files changed

+52
-12
lines changed

scripts/Start-EditorServices.ps1

+16-2
Original file line numberDiff line numberDiff line change
@@ -54,13 +54,27 @@ param(
5454
$ConfirmInstall
5555
)
5656

57+
# Are we running in PowerShell 2 or earlier?
58+
if ($PSVersionTable.PSVersion.Major -le 2) {
59+
$resultDetails = @{
60+
"status" = "failed"
61+
"reason" = "unsupported"
62+
"powerShellVersion" = $PSVersionTable.PSVersion.ToString()
63+
};
64+
65+
# Notify the client that the services have started
66+
Write-Output (ConvertTo-Json -InputObject $resultDetails -Compress)
67+
68+
exit 0;
69+
}
70+
5771
# Are we running in PowerShell 5 or later?
5872
$isPS5orLater = $PSVersionTable.PSVersion.Major -ge 5
5973

6074
# If PSReadline is present in the session, remove it so that runspace
6175
# management is easier
62-
if ((Get-Module PSReadline).Count -ne 0) {
63-
Remove-Module PSReadline
76+
if ((Get-Module PSReadline).Count -gt 0) {
77+
Remove-Module PSReadline -ErrorAction SilentlyContinue
6478
}
6579

6680
# This variable will be assigned later to contain information about

src/session.ts

+36-10
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,15 @@ export class SessionManager {
246246
// Start the language service client
247247
this.startLanguageClient(sessionDetails.languageServicePort);
248248
}
249+
else if (response["status"] === "failed") {
250+
if (response["reason"] === "unsupported") {
251+
this.setSessionFailure(
252+
`PowerShell language features are only supported on PowerShell version 3 and above. The current version is ${response["powerShellVersion"]}.`)
253+
}
254+
else {
255+
this.setSessionFailure(`PowerShell could not be started for an unknown reason '${response["reason"]}'`)
256+
}
257+
}
249258
else {
250259
// TODO: Handle other response cases
251260
}
@@ -354,15 +363,13 @@ export class SessionManager {
354363
},
355364
(reason) => {
356365
this.setSessionFailure("Could not start language service: ", reason);
357-
this.updateExtensionFeatures(undefined);
358366
});
359367

360368
this.languageServerClient.start();
361369
}
362370
catch (e)
363371
{
364372
this.setSessionFailure("The language service could not be started: ", e);
365-
this.updateExtensionFeatures(undefined);
366373
}
367374
}
368375

@@ -511,15 +518,34 @@ export class SessionManager {
511518
}
512519

513520
private showSessionMenu() {
514-
var menuItems: SessionMenuItem[] = [
515-
new SessionMenuItem(
516-
`Current session: PowerShell ${this.versionDetails.displayVersion} (${this.versionDetails.architecture}) ${this.versionDetails.edition} Edition [${this.versionDetails.version}]`,
517-
() => { vscode.commands.executeCommand("PowerShell.ShowLogs"); }),
521+
var menuItems: SessionMenuItem[] = [];
518522

519-
new SessionMenuItem(
520-
"Restart Current Session",
521-
() => { this.restartSession(); }),
522-
];
523+
if (this.sessionStatus === SessionStatus.Initializing ||
524+
this.sessionStatus === SessionStatus.NotStarted ||
525+
this.sessionStatus === SessionStatus.Stopping) {
526+
527+
// Don't show a menu for these states
528+
return;
529+
}
530+
531+
if (this.sessionStatus === SessionStatus.Running) {
532+
menuItems = [
533+
new SessionMenuItem(
534+
`Current session: PowerShell ${this.versionDetails.displayVersion} (${this.versionDetails.architecture}) ${this.versionDetails.edition} Edition [${this.versionDetails.version}]`,
535+
() => { vscode.commands.executeCommand("PowerShell.ShowLogs"); }),
536+
537+
new SessionMenuItem(
538+
"Restart Current Session",
539+
() => { this.restartSession(); }),
540+
];
541+
}
542+
else if (this.sessionStatus === SessionStatus.Failed) {
543+
menuItems = [
544+
new SessionMenuItem(
545+
`Session initialization failed, click here to show PowerShell extension logs`,
546+
() => { vscode.commands.executeCommand("PowerShell.ShowLogs"); }),
547+
];
548+
}
523549

524550
if (this.isWindowsOS) {
525551
var item32 =

0 commit comments

Comments
 (0)