diff --git a/scripts/Start-EditorServices.ps1 b/scripts/Start-EditorServices.ps1 index 9f96d917d4..ce2545d0fa 100644 --- a/scripts/Start-EditorServices.ps1 +++ b/scripts/Start-EditorServices.ps1 @@ -89,6 +89,16 @@ function WriteSessionFile($sessionInfo) { ConvertTo-Json -InputObject $sessionInfo -Compress | Set-Content -Force -Path "$SessionDetailsPath" -ErrorAction Stop } +if ($host.Runspace.LanguageMode -eq 'ConstrainedLanguage') { + WriteSessionFile @{ + "status" = "failed" + "reason" = "languageMode" + "detail" = $host.Runspace.LanguageMode.ToString() + } + + ExitWithError "PowerShell is configured with an unsupported LanguageMode (ConstrainedLanguage), language features are disabled." +} + # Are we running in PowerShell 5 or later? $isPS5orLater = $PSVersionTable.PSVersion.Major -ge 5 diff --git a/src/session.ts b/src/session.ts index fad251e751..fdb9d1e48f 100644 --- a/src/session.ts +++ b/src/session.ts @@ -327,6 +327,10 @@ export class SessionManager { this.setSessionFailure( `PowerShell language features are only supported on PowerShell version 3 and above. The current version is ${sessionDetails.powerShellVersion}.`) } + else if (sessionDetails.reason === "languageMode") { + this.setSessionFailure( + `PowerShell language features are disabled due to an unsupported LanguageMode: ${sessionDetails.detail}`); + } else { this.setSessionFailure(`PowerShell could not be started for an unknown reason '${sessionDetails.reason}'`) } diff --git a/src/utils.ts b/src/utils.ts index 0db0a5619b..6dcb0bbf18 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -57,6 +57,7 @@ export function getPipePath(pipeName: string) { export interface EditorServicesSessionDetails { status: string; reason: string; + detail: string; powerShellVersion: string; channel: string; languageServicePort: number;