Skip to content

Commit

Permalink
Fix #421: Unsupported PowerShell LanguageMode should be reported
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
daviwil committed Mar 16, 2017
1 parent 306a520 commit c2eb462
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 0 deletions.
10 changes: 10 additions & 0 deletions scripts/Start-EditorServices.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 4 additions & 0 deletions src/session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}'`)
}
Expand Down
1 change: 1 addition & 0 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ export function getPipePath(pipeName: string) {
export interface EditorServicesSessionDetails {
status: string;
reason: string;
detail: string;
powerShellVersion: string;
channel: string;
languageServicePort: number;
Expand Down

0 comments on commit c2eb462

Please sign in to comment.