Skip to content

Commit

Permalink
Merge pull request #568 from daviwil/fix-401-421
Browse files Browse the repository at this point in the history
Fix #401 and #421
  • Loading branch information
daviwil authored Mar 16, 2017
2 parents a86354d + c2eb462 commit 899377a
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 12 deletions.
38 changes: 26 additions & 12 deletions scripts/Start-EditorServices.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -65,24 +65,38 @@ param(
$ConfirmInstall
)

function WriteSessionFile($sessionInfo) {
ConvertTo-Json -InputObject $sessionInfo -Compress | Set-Content -Force -Path "$SessionDetailsPath" -ErrorAction Stop
function ExitWithError($errorString) {

Write-Host -ForegroundColor Red "`n`n$errorString"

# Sleep for a while to make sure the user has time to see and copy the
# error message
Start-Sleep -Seconds 300

exit 1;
}

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

# Notify the client that the services have started
WriteSessionFile $resultDetails
ExitWithError "Unsupported PowerShell version $($PSVersionTable.PSVersion), language features are disabled."
}

Write-Host "Unsupported PowerShell version $($PSVersionTable.PSVersion), language features are disabled.`n"
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()
}

exit 0;
ExitWithError "PowerShell is configured with an unsupported LanguageMode (ConstrainedLanguage), language features are disabled."
}

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

Write-Error ("`r`nCaught error while waiting for EditorServicesHost to complete:`r`n" + $errorString)
ExitWithError ("Caught error while waiting for EditorServicesHost to complete:`r`n" + $errorString)
}
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 899377a

Please sign in to comment.