Skip to content

Commit c2eb462

Browse files
committed
Fix #421: Unsupported PowerShell LanguageMode should be reported
This change adds an additional check in the Start-EditorServices.ps1 script to see whether the LanguageMode has been locked to an unsupported mode like ConstrainedLanguage. The language server cannot be loaded and used in this case so the user should be notified.
1 parent 306a520 commit c2eb462

File tree

3 files changed

+15
-0
lines changed

3 files changed

+15
-0
lines changed

scripts/Start-EditorServices.ps1

+10
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,16 @@ function WriteSessionFile($sessionInfo) {
8989
ConvertTo-Json -InputObject $sessionInfo -Compress | Set-Content -Force -Path "$SessionDetailsPath" -ErrorAction Stop
9090
}
9191

92+
if ($host.Runspace.LanguageMode -eq 'ConstrainedLanguage') {
93+
WriteSessionFile @{
94+
"status" = "failed"
95+
"reason" = "languageMode"
96+
"detail" = $host.Runspace.LanguageMode.ToString()
97+
}
98+
99+
ExitWithError "PowerShell is configured with an unsupported LanguageMode (ConstrainedLanguage), language features are disabled."
100+
}
101+
92102
# Are we running in PowerShell 5 or later?
93103
$isPS5orLater = $PSVersionTable.PSVersion.Major -ge 5
94104

src/session.ts

+4
Original file line numberDiff line numberDiff line change
@@ -327,6 +327,10 @@ export class SessionManager {
327327
this.setSessionFailure(
328328
`PowerShell language features are only supported on PowerShell version 3 and above. The current version is ${sessionDetails.powerShellVersion}.`)
329329
}
330+
else if (sessionDetails.reason === "languageMode") {
331+
this.setSessionFailure(
332+
`PowerShell language features are disabled due to an unsupported LanguageMode: ${sessionDetails.detail}`);
333+
}
330334
else {
331335
this.setSessionFailure(`PowerShell could not be started for an unknown reason '${sessionDetails.reason}'`)
332336
}

src/utils.ts

+1
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ export function getPipePath(pipeName: string) {
5757
export interface EditorServicesSessionDetails {
5858
status: string;
5959
reason: string;
60+
detail: string;
6061
powerShellVersion: string;
6162
channel: string;
6263
languageServicePort: number;

0 commit comments

Comments
 (0)