-
Notifications
You must be signed in to change notification settings - Fork 237
Adds ability to use separate pipes for reading and writing #785
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
Changes from all commits
9db4d7e
ea65162
8d20b53
c47e80b
4e747a1
0189966
569c223
93a391f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,7 +15,7 @@ | |
# Services GitHub repository: | ||
# | ||
# https://github.com/PowerShell/PowerShellEditorServices/blob/master/module/PowerShellEditorServices/Start-EditorServices.ps1 | ||
|
||
[CmdletBinding(DefaultParameterSetName="NamedPipe")] | ||
param( | ||
[Parameter(Mandatory=$true)] | ||
[ValidateNotNullOrEmpty()] | ||
|
@@ -65,14 +65,37 @@ param( | |
[switch] | ||
$ConfirmInstall, | ||
|
||
[Parameter(ParameterSetName="Stdio",Mandatory=$true)] | ||
[switch] | ||
$Stdio, | ||
|
||
[Parameter(ParameterSetName="NamedPipe")] | ||
[string] | ||
$LanguageServicePipeName = $null, | ||
|
||
[Parameter(ParameterSetName="NamedPipe")] | ||
[string] | ||
$DebugServicePipeName = $null, | ||
|
||
[Parameter(ParameterSetName="NamedPipeSimplex")] | ||
[switch] | ||
$SplitInOutPipes, | ||
|
||
[Parameter(ParameterSetName="NamedPipeSimplex")] | ||
[string] | ||
$LanguageServiceInPipeName, | ||
|
||
[Parameter(ParameterSetName="NamedPipeSimplex")] | ||
[string] | ||
$DebugServicePipeName = $null | ||
$LanguageServiceOutPipeName, | ||
|
||
[Parameter(ParameterSetName="NamedPipeSimplex")] | ||
[string] | ||
$DebugServiceInPipeName = $null, | ||
|
||
[Parameter(ParameterSetName="NamedPipeSimplex")] | ||
[string] | ||
$DebugServiceOutPipeName = $null | ||
) | ||
|
||
$DEFAULT_USER_MODE = "600" | ||
|
@@ -173,8 +196,7 @@ function New-NamedPipeName { | |
|
||
# We try 10 times to find a valid pipe name | ||
for ($i = 0; $i -lt 10; $i++) { | ||
# add a guid to make the pipe unique | ||
$PipeName = "PSES_$([guid]::NewGuid())" | ||
$PipeName = "PSES_$([System.IO.Path]::GetRandomFileName())" | ||
TylerLeonhardt marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
if ((Test-NamedPipeName -PipeName $PipeName)) { | ||
return $PipeName | ||
|
@@ -246,6 +268,37 @@ function Set-NamedPipeMode { | |
LogSection "Console Encoding" | ||
Log $OutputEncoding | ||
|
||
function Test-NamedPipeName-OrCreate-IfNull { | ||
param( | ||
[string] | ||
$PipeName | ||
) | ||
if (-not $PipeName) { | ||
$PipeName = New-NamedPipeName | ||
} | ||
else { | ||
if (-not (Test-NamedPipeName -PipeName $PipeName)) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So what happens when Test-NamedPipeName equals I feel as if the Test & Create part should be two separate functions. Separation of concerns There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The function will fail and abort with the error if the supplied by the user pipe name is not a valid name. If a valid name was supplied it just returns this pipe name. If no pipe name was provided it creates it. |
||
ExitWithError "Pipe name supplied is already taken: $PipeName" | ||
} | ||
} | ||
return $PipeName | ||
} | ||
|
||
function Set-PipeFileResult { | ||
param ( | ||
[Hashtable] | ||
$ResultTable, | ||
[string] | ||
$PipeNameKey, | ||
[string] | ||
$PipeNameValue | ||
) | ||
$ResultTable[$PipeNameKey] = Get-NamedPipePath -PipeName $PipeNameValue | ||
if ($IsLinux -or $IsMacOS) { | ||
Set-NamedPipeMode -PipeFile $ResultTable[$PipeNameKey] | ||
} | ||
} | ||
|
||
# Add BundledModulesPath to $env:PSModulePath | ||
if ($BundledModulesPath) { | ||
$env:PSModulePath = $env:PSModulePath.TrimEnd([System.IO.Path]::PathSeparator) + [System.IO.Path]::PathSeparator + $BundledModulesPath | ||
|
@@ -266,81 +319,93 @@ try { | |
|
||
Microsoft.PowerShell.Core\Import-Module PowerShellEditorServices -ErrorAction Stop | ||
|
||
# Locate available port numbers for services | ||
# There could be only one service on Stdio channel | ||
|
||
$languageServiceTransport = $null | ||
$debugServiceTransport = $null | ||
|
||
if ($Stdio.IsPresent) { | ||
$languageServiceTransport = "Stdio" | ||
$debugServiceTransport = "Stdio" | ||
} | ||
else { | ||
$languageServiceTransport = "NamedPipe" | ||
$debugServiceTransport = "NamedPipe" | ||
if (-not $LanguageServicePipeName) { | ||
$LanguageServicePipeName = New-NamedPipeName | ||
} | ||
else { | ||
if (-not (Test-NamedPipeName -PipeName $LanguageServicePipeName)) { | ||
ExitWithError "Pipe name supplied is already taken: $LanguageServicePipeName" | ||
} | ||
} | ||
if (-not $DebugServicePipeName) { | ||
$DebugServicePipeName = New-NamedPipeName | ||
} | ||
else { | ||
if (-not (Test-NamedPipeName -PipeName $DebugServicePipeName)) { | ||
ExitWithError "Pipe name supplied is already taken: $DebugServicePipeName" | ||
} | ||
} | ||
} | ||
|
||
if ($EnableConsoleRepl) { | ||
Write-Host "PowerShell Integrated Console`n" | ||
} | ||
|
||
# Create the Editor Services host | ||
Log "Invoking Start-EditorServicesHost" | ||
$editorServicesHost = | ||
Start-EditorServicesHost ` | ||
-HostName $HostName ` | ||
-HostProfileId $HostProfileId ` | ||
-HostVersion $HostVersion ` | ||
-LogPath $LogPath ` | ||
-LogLevel $LogLevel ` | ||
-AdditionalModules $AdditionalModules ` | ||
-LanguageServiceNamedPipe $LanguageServicePipeName ` | ||
-DebugServiceNamedPipe $DebugServicePipeName ` | ||
-Stdio:$Stdio.IsPresent` | ||
-BundledModulesPath $BundledModulesPath ` | ||
-EnableConsoleRepl:$EnableConsoleRepl.IsPresent ` | ||
-DebugServiceOnly:$DebugServiceOnly.IsPresent ` | ||
-WaitForDebugger:$WaitForDebugger.IsPresent | ||
|
||
# TODO: Verify that the service is started | ||
Log "Start-EditorServicesHost returned $editorServicesHost" | ||
|
||
$resultDetails = @{ | ||
"status" = "started"; | ||
"languageServiceTransport" = $languageServiceTransport; | ||
"debugServiceTransport" = $debugServiceTransport; | ||
"status" = "not started"; | ||
"languageServiceTransport" = $PSCmdlet.ParameterSetName; | ||
"debugServiceTransport" = $PSCmdlet.ParameterSetName; | ||
}; | ||
|
||
if ($LanguageServicePipeName) { | ||
$resultDetails["languageServicePipeName"] = Get-NamedPipePath -PipeName $LanguageServicePipeName | ||
if ($IsLinux -or $IsMacOS) { | ||
Set-NamedPipeMode -PipeFile $resultDetails["languageServicePipeName"] | ||
# Create the Editor Services host | ||
Log "Invoking Start-EditorServicesHost" | ||
# There could be only one service on Stdio channel | ||
# Locate available port numbers for services | ||
switch ($PSCmdlet.ParameterSetName) { | ||
"Stdio" { | ||
$editorServicesHost = Start-EditorServicesHost ` | ||
-HostName $HostName ` | ||
-HostProfileId $HostProfileId ` | ||
-HostVersion $HostVersion ` | ||
-LogPath $LogPath ` | ||
-LogLevel $LogLevel ` | ||
-AdditionalModules $AdditionalModules ` | ||
-Stdio ` | ||
-BundledModulesPath $BundledModulesPath ` | ||
-EnableConsoleRepl:$EnableConsoleRepl.IsPresent ` | ||
-DebugServiceOnly:$DebugServiceOnly.IsPresent ` | ||
-WaitForDebugger:$WaitForDebugger.IsPresent | ||
break | ||
} | ||
} | ||
if ($DebugServicePipeName) { | ||
$resultDetails["debugServicePipeName"] = Get-NamedPipePath -PipeName $DebugServicePipeName | ||
if ($IsLinux -or $IsMacOS) { | ||
Set-NamedPipeMode -PipeFile $resultDetails["debugServicePipeName"] | ||
"NamedPipeSimplex" { | ||
$LanguageServiceInPipeName = Test-NamedPipeName-OrCreate-IfNull $LanguageServiceInPipeName | ||
$LanguageServiceOutPipeName = Test-NamedPipeName-OrCreate-IfNull $LanguageServiceOutPipeName | ||
$DebugServiceInPipeName = Test-NamedPipeName-OrCreate-IfNull $DebugServiceInPipeName | ||
$DebugServiceOutPipeName = Test-NamedPipeName-OrCreate-IfNull $DebugServiceOutPipeName | ||
|
||
$editorServicesHost = Start-EditorServicesHost ` | ||
-HostName $HostName ` | ||
-HostProfileId $HostProfileId ` | ||
-HostVersion $HostVersion ` | ||
-LogPath $LogPath ` | ||
-LogLevel $LogLevel ` | ||
-AdditionalModules $AdditionalModules ` | ||
-LanguageServiceInNamedPipe $LanguageServiceInPipeName ` | ||
-LanguageServiceOutNamedPipe $LanguageServiceOutPipeName ` | ||
-DebugServiceInNamedPipe $DebugServiceInPipeName ` | ||
-DebugServiceOutNamedPipe $DebugServiceOutPipeName ` | ||
-BundledModulesPath $BundledModulesPath ` | ||
-EnableConsoleRepl:$EnableConsoleRepl.IsPresent ` | ||
-DebugServiceOnly:$DebugServiceOnly.IsPresent ` | ||
-WaitForDebugger:$WaitForDebugger.IsPresent | ||
|
||
Set-PipeFileResult $resultDetails "languageServiceReadPipeName" $LanguageServiceInPipeName | ||
Set-PipeFileResult $resultDetails "languageServiceWritePipeName" $LanguageServiceOutPipeName | ||
Set-PipeFileResult $resultDetails "debugServiceReadPipeName" $DebugServiceInPipeName | ||
Set-PipeFileResult $resultDetails "debugServiceWritePipeName" $DebugServiceOutPipeName | ||
break | ||
} | ||
Default { | ||
$LanguageServicePipeName = Test-NamedPipeName-OrCreate-IfNull $LanguageServicePipeName | ||
$DebugServicePipeName = Test-NamedPipeName-OrCreate-IfNull $DebugServicePipeName | ||
|
||
$editorServicesHost = Start-EditorServicesHost ` | ||
-HostName $HostName ` | ||
-HostProfileId $HostProfileId ` | ||
-HostVersion $HostVersion ` | ||
-LogPath $LogPath ` | ||
-LogLevel $LogLevel ` | ||
-AdditionalModules $AdditionalModules ` | ||
-LanguageServiceNamedPipe $LanguageServicePipeName ` | ||
-DebugServiceNamedPipe $DebugServicePipeName ` | ||
-BundledModulesPath $BundledModulesPath ` | ||
-EnableConsoleRepl:$EnableConsoleRepl.IsPresent ` | ||
-DebugServiceOnly:$DebugServiceOnly.IsPresent ` | ||
-WaitForDebugger:$WaitForDebugger.IsPresent | ||
|
||
Set-PipeFileResult $resultDetails "languageServicePipeName" $LanguageServicePipeName | ||
Set-PipeFileResult $resultDetails "debugServicePipeName" $DebugServicePipeName | ||
break | ||
} | ||
} | ||
|
||
# TODO: Verify that the service is started | ||
Log "Start-EditorServicesHost returned $editorServicesHost" | ||
|
||
$resultDetails["status"] = "started" | ||
|
||
# Notify the client that the services have started | ||
WriteSessionFile $resultDetails | ||
|
||
|
Uh oh!
There was an error while loading. Please reload this page.