Skip to content

Commit 899377a

Browse files
authored
Merge pull request #568 from daviwil/fix-401-421
Fix #401 and #421
2 parents a86354d + c2eb462 commit 899377a

File tree

3 files changed

+31
-12
lines changed

3 files changed

+31
-12
lines changed

scripts/Start-EditorServices.ps1

+26-12
Original file line numberDiff line numberDiff line change
@@ -65,24 +65,38 @@ param(
6565
$ConfirmInstall
6666
)
6767

68-
function WriteSessionFile($sessionInfo) {
69-
ConvertTo-Json -InputObject $sessionInfo -Compress | Set-Content -Force -Path "$SessionDetailsPath" -ErrorAction Stop
68+
function ExitWithError($errorString) {
69+
70+
Write-Host -ForegroundColor Red "`n`n$errorString"
71+
72+
# Sleep for a while to make sure the user has time to see and copy the
73+
# error message
74+
Start-Sleep -Seconds 300
75+
76+
exit 1;
7077
}
7178

7279
# Are we running in PowerShell 2 or earlier?
7380
if ($PSVersionTable.PSVersion.Major -le 2) {
74-
$resultDetails = @{
75-
"status" = "failed"
76-
"reason" = "unsupported"
77-
"powerShellVersion" = $PSVersionTable.PSVersion.ToString()
78-
};
81+
# No ConvertTo-Json on PSv2 and below, so write out the JSON manually
82+
"{`"status`": `"failed`", `"reason`": `"unsupported`", `"powerShellVersion`": `"$($PSVersionTable.PSVersion.ToString())`"}" |
83+
Set-Content -Force -Path "$SessionDetailsPath" -ErrorAction Stop
7984

80-
# Notify the client that the services have started
81-
WriteSessionFile $resultDetails
85+
ExitWithError "Unsupported PowerShell version $($PSVersionTable.PSVersion), language features are disabled."
86+
}
8287

83-
Write-Host "Unsupported PowerShell version $($PSVersionTable.PSVersion), language features are disabled.`n"
88+
function WriteSessionFile($sessionInfo) {
89+
ConvertTo-Json -InputObject $sessionInfo -Compress | Set-Content -Force -Path "$SessionDetailsPath" -ErrorAction Stop
90+
}
91+
92+
if ($host.Runspace.LanguageMode -eq 'ConstrainedLanguage') {
93+
WriteSessionFile @{
94+
"status" = "failed"
95+
"reason" = "languageMode"
96+
"detail" = $host.Runspace.LanguageMode.ToString()
97+
}
8498

85-
exit 0;
99+
ExitWithError "PowerShell is configured with an unsupported LanguageMode (ConstrainedLanguage), language features are disabled."
86100
}
87101

88102
# Are we running in PowerShell 5 or later?
@@ -240,5 +254,5 @@ catch [System.Exception] {
240254
$e = $e.InnerException;
241255
}
242256

243-
Write-Error ("`r`nCaught error while waiting for EditorServicesHost to complete:`r`n" + $errorString)
257+
ExitWithError ("Caught error while waiting for EditorServicesHost to complete:`r`n" + $errorString)
244258
}

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)