-
Notifications
You must be signed in to change notification settings - Fork 223
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
PSReadLine integration (WIP) #671
Closed
SeeminglyScience
wants to merge
5
commits into
PowerShell:2.0.0
from
SeeminglyScience:integrate-psreadline
Closed
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
7ca8b9b
Add infrastructure for managing context
SeeminglyScience 59bfa3b
Console related classes changes
SeeminglyScience 21e6b5f
Rewrite command invocation operations for PSRL
SeeminglyScience fa2faba
Rewrite direct SessionStateProxy calls
SeeminglyScience 94cfdfd
Resolve merge conflicts
SeeminglyScience File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,198 @@ | ||
# PowerShell Editor Services Bootstrapper Script | ||
# ---------------------------------------------- | ||
# This script contains startup logic for the PowerShell Editor Services | ||
# module when launched by an editor. It handles the following tasks: | ||
# | ||
# - Verifying the existence of dependencies like PowerShellGet | ||
# - Verifying that the expected version of the PowerShellEditorServices module is installed | ||
# - Installing the PowerShellEditorServices module if confirmed by the user | ||
# - Finding unused TCP port numbers for the language and debug services to use | ||
# - Starting the language and debug services from the PowerShellEditorServices module | ||
# | ||
# NOTE: If editor integration authors make modifications to this | ||
# script, please consider contributing changes back to the | ||
# canonical version of this script at the PowerShell Editor | ||
# Services GitHub repository: | ||
# | ||
# https://github.com/PowerShell/PowerShellEditorServices/blob/master/module/Start-EditorServices.ps1 | ||
|
||
param( | ||
[Parameter(Mandatory=$true)] | ||
[ValidateNotNullOrEmpty()] | ||
[string] | ||
$EditorServicesVersion, | ||
|
||
[Parameter(Mandatory=$true)] | ||
[ValidateNotNullOrEmpty()] | ||
[string] | ||
$HostName, | ||
|
||
[Parameter(Mandatory=$true)] | ||
[ValidateNotNullOrEmpty()] | ||
[string] | ||
$HostProfileId, | ||
|
||
[Parameter(Mandatory=$true)] | ||
[ValidateNotNullOrEmpty()] | ||
[string] | ||
$HostVersion, | ||
|
||
[ValidateNotNullOrEmpty()] | ||
[string] | ||
$BundledModulesPath, | ||
|
||
[ValidateNotNullOrEmpty()] | ||
$LogPath, | ||
|
||
[ValidateSet("Normal", "Verbose", "Error","Diagnostic")] | ||
$LogLevel, | ||
|
||
[string[]] | ||
$FeatureFlags = @(), | ||
|
||
[switch] | ||
$WaitForDebugger, | ||
|
||
[switch] | ||
$ConfirmInstall | ||
) | ||
|
||
# This variable will be assigned later to contain information about | ||
# what happened while attempting to launch the PowerShell Editor | ||
# Services host | ||
$resultDetails = $null; | ||
|
||
function Test-ModuleAvailable($ModuleName, $ModuleVersion) { | ||
$modules = Get-Module -ListAvailable $moduleName | ||
if ($modules -ne $null) { | ||
if ($ModuleVersion -ne $null) { | ||
foreach ($module in $modules) { | ||
if ($module.Version.Equals($moduleVersion)) { | ||
return $true; | ||
} | ||
} | ||
} | ||
else { | ||
return $true; | ||
} | ||
} | ||
|
||
return $false; | ||
} | ||
|
||
function Test-PortAvailability($PortNumber) { | ||
$portAvailable = $true; | ||
|
||
try { | ||
$ipAddress = [System.Net.Dns]::GetHostEntryAsync("localhost").Result.AddressList[0]; | ||
$tcpListener = [System.Net.Sockets.TcpListener]::new($ipAddress, $portNumber); | ||
$tcpListener.Start(); | ||
$tcpListener.Stop(); | ||
|
||
} | ||
catch [System.Net.Sockets.SocketException] { | ||
# Check the SocketErrorCode to see if it's the expected exception | ||
if ($error[0].Exception.InnerException.SocketErrorCode -eq [System.Net.Sockets.SocketError]::AddressAlreadyInUse) { | ||
$portAvailable = $false; | ||
} | ||
else { | ||
Write-Output ("Error code: " + $error[0].SocketErrorCode) | ||
} | ||
} | ||
|
||
return $portAvailable; | ||
} | ||
|
||
$rand = [System.Random]::new() | ||
function Get-AvailablePort { | ||
$triesRemaining = 10; | ||
|
||
while ($triesRemaining -gt 0) { | ||
$port = $rand.Next(10000, 30000) | ||
if ((Test-PortAvailability -PortAvailability $port) -eq $true) { | ||
return $port | ||
} | ||
|
||
$triesRemaining--; | ||
} | ||
|
||
return $null | ||
} | ||
|
||
# OUTPUT PROTOCOL | ||
# - "started 29981 39898" - Server(s) are started, language and debug server ports (respectively) | ||
# - "failed Error message describing the failure" - General failure while starting, show error message to user (?) | ||
# - "needs_install" - User should be prompted to install PowerShell Editor Services via the PowerShell Gallery | ||
|
||
# Add BundledModulesPath to $env:PSModulePath | ||
if ($BundledModulesPath) { | ||
$env:PSMODULEPATH = $BundledModulesPath + [System.IO.Path]::PathSeparator + $env:PSMODULEPATH | ||
} | ||
|
||
# Check if PowerShellGet module is available | ||
if ((Test-ModuleAvailable "PowerShellGet") -eq $false) { | ||
# TODO: WRITE ERROR | ||
} | ||
|
||
# Check if the expected version of the PowerShell Editor Services | ||
# module is installed | ||
$parsedVersion = [System.Version]::new($EditorServicesVersion) | ||
if ((Test-ModuleAvailable "PowerShellEditorServices" -RequiredVersion $parsedVersion) -eq $false) { | ||
if ($ConfirmInstall) { | ||
# TODO: Check for error and return failure if necessary | ||
Install-Module "PowerShellEditorServices" -RequiredVersion $parsedVersion -Confirm | ||
} | ||
else { | ||
# Indicate to the client that the PowerShellEditorServices module | ||
# needs to be installed | ||
Write-Output "needs_install" | ||
} | ||
} | ||
|
||
Import-Module PowerShellEditorServices -RequiredVersion $parsedVersion -ErrorAction Stop | ||
|
||
# Locate available port numbers for services | ||
$languageServicePort = Get-AvailablePort | ||
$debugServicePort = Get-AvailablePort | ||
|
||
$editorServicesHost = | ||
Start-EditorServicesHost ` | ||
-HostName $HostName ` | ||
-HostProfileId $HostProfileId ` | ||
-HostVersion $HostVersion ` | ||
-LogPath $LogPath ` | ||
-LogLevel $LogLevel ` | ||
-AdditionalModules @() ` | ||
-LanguageServicePort $languageServicePort ` | ||
-DebugServicePort $debugServicePort ` | ||
-BundledModulesPath $BundledModulesPath ` | ||
-WaitForDebugger:$WaitForDebugger.IsPresent ` | ||
-FeatureFlags $FeatureFlags | ||
|
||
# TODO: Verify that the service is started | ||
|
||
$resultDetails = @{ | ||
"status" = "started"; | ||
"channel" = "tcp"; | ||
"languageServicePort" = $languageServicePort; | ||
"debugServicePort" = $debugServicePort; | ||
}; | ||
|
||
# Notify the client that the services have started | ||
Write-Output (ConvertTo-Json -InputObject $resultDetails -Compress) | ||
|
||
try { | ||
# Wait for the host to complete execution before exiting | ||
$editorServicesHost.WaitForCompletion() | ||
} | ||
catch [System.Exception] { | ||
$e = $_.Exception; #.InnerException; | ||
$errorString = "" | ||
|
||
while ($e -ne $null) { | ||
$errorString = $errorString + ($e.Message + "`r`n" + $e.StackTrace + "`r`n") | ||
$e = $e.InnerException; | ||
} | ||
|
||
Write-Error ("`r`nCaught error while waiting for EditorServicesHost to complete:`r`n" + $errorString) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1489,6 +1489,15 @@ private static async Task DelayThenInvokeDiagnostics( | |
catch (TaskCanceledException) | ||
{ | ||
// If the task is cancelled, exit directly | ||
foreach (var script in filesToAnalyze) | ||
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. Comment needs to be updated. |
||
{ | ||
await PublishScriptDiagnostics( | ||
script, | ||
script.SyntaxMarkers, | ||
correctionIndex, | ||
eventSender); | ||
} | ||
|
||
return; | ||
} | ||
|
||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mistake, must have done a vim line join and didn't notice.