Skip to content

Fix #401 and #421 #568

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 16, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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