Source Code Breakdown of PowerShellEditorServices (at the time of v3.5.4)
To make the experience fit your profile, pick a username and tell us what interests you.
We found and based on your interests.
This is an attempt at comprehensively tracing the BundledModulesPath parameter. In this log, all uses of the BundledModulesPath parameter will be documented. This will support my unofficial documentation on the Start-EditorServices cmdlet
[-BundledModulesPath
< string, not null or empty >]
[ValidateNotNullOrEmpty()]
[string]
$BundledModulesPath
Import-Module -Name "$PSScriptRoot/PowerShellEditorServices.psd1"
Start-EditorServices @PSBoundParameters
# Script module or binary module file associated with this manifest.
RootModule = if ($PSEdition -eq 'Core')
{ 'bin/Core/Microsoft.PowerShell.EditorServices.Hosting.dll' }
else
{ 'bin/Desktop/Microsoft.PowerShell.EditorServices.Hosting.dll' }
- I believe this is a call to the Microsoft.PowerShell.EditorServices.Hosting namespace - still uncertain about this.
/// <summary>
/// The Start-EditorServices command, the conventional entrypoint for PowerShell Editor Services.
/// </summary>
...
[Cmdlet(
VerbsLifecycle.Start, "EditorServices",
DefaultParameterSetName = "NamedPipe"
)]
public sealed class StartEditorServicesCommand : PSCmdlet
{ ... }
PSES doesn't have a logo of their own, so I'm using the preview icon pulled from vscode-powershell:
My current idea is to remove the ">_" and replace it with "LSP" to represent that it is the language server
This log will be used to track all known instances of bloatcode in the repo
The code that follows this line can be reduced to this:
PSMemberInfoCollection<PSPropertyInfo> profiles = profile.Properties
ProfilePaths = new ProfilePathConfig
{
AllUsersAllHosts = (string)profiles.AllUsersAllHosts.Value,
AllUsersCurrentHost = Path.Combine(
Path.GetDirectoryName( (string)profiles.AllUsersCurrentHost.Value ),
$"{HostProfileId}_profile.ps1" ),
CurrentUserAllHosts = (string)profiles.CurrentUserAllHosts.Value,
CurrentUserCurrentHost = Path.Combine(
Path.GetDirectoryName( (string)profiles.CurrentUserCurrentHost.Value ),
$"{HostProfileId}_profile.ps1" ),
},
All referenced Enums and Methods for this generation can then be deleted
According to this search, this signature never gets used.
We don't need to reinvent the "new" keyword. Named constructors should only be used where verbose names make the constructor look like more than just a constructor. For example Int32.Parse() is a good named constructor; Int32.Create() is not
EditorServicesLoader.UpdatePSModulePath() should probably include the code from the CreateConfigObject method on the cmdlet
instead of using System.Text.Json to serialize to Json, they use the PowerShell command ConvertTo-Json to do it instead, but from C#. This is one of the most hilarious instances of bloat code I have ever seen
This code doesn't need to be here.
this doesn't need to be done in 5 different spots across the utility. Jesus Christ
This is my trace of the HostVersion parameter. The purpose of this log is to identify all uses for the HostVersion parameter. These uses will be documented in my unofficial documentation on the Start-EditorServices command
[-HostVersion <
string,
mandatory,
="" not="" null="" or="" empty=""
>]
[Parameter(Mandatory=$true)]
[ValidateNotNullOrEmpty()]
[string]
$HostVersion
Import-Module -Name "$PSScriptRoot/PowerShellEditorServices.psd1"
Start-EditorServices @PSBoundParameters
# Script module or binary module file associated with this manifest.
RootModule = if ($PSEdition -eq 'Core')
{
'bin/Core/Microsoft.PowerShell.EditorServices.Hosting.dll'
}
else
{
'bin/Desktop/Microsoft.PowerShell.EditorServices.Hosting.dll'
}
/// <summary>
/// The Start-EditorServices command, the conventional entrypoint for PowerShell Editor Services.
/// </summary>
[System.Diagnostics.CodeAnalysis.SuppressMessage("Performance",
"CA1819:Properties should not return arrays",
Justification = "Cmdlet parameters can be arrays")]
[Cmdlet(VerbsLifecycle.Start, "EditorServices",
DefaultParameterSetName = "NamedPipe")]
public sealed class StartEditorServicesCommand : PSCmdlet
{ ... }
/// <summary>
/// The version to report for the host.
/// </summary>
[Parameter(Mandatory = true)]
[ValidateNotNullOrEmpty]
public Version HostVersion { get; set; }
HostInfo hostInfo = new(HostName, HostProfileId, HostVersion);
From my previous experiences with these objects, this is gonna be a long trace :(
I find it hard to navigate through the project logs, so I'm moving the Docs to Github Gists. I may move them into their own repository later.
Haven't given this up. Just had to take some time off from logs, so that I could learn about Dependency Injection in C#.
This takes some time, because I need to specifically cover topics like IServiceCollection, and cover broad topics like inversion of control.
There isn't a whole lot of articles that demystify these topics very well. If I get asked, I might produce my own, but for now I don't feel like summing up the 30-some-odd pages I have had to read through to get a feel for the topic.
https://www.stevejgordon.co.uk/aspnet-core-dependency-injection-what-is-the-iservicecollection
According these 2 lines:
I believe that PSES is using the OmniSharp C# Language Server to create an LSP server
These source code files seem to be too large and broad to be scraped to get every detail over how PSES uses it, but it does look rewriteable in PowerShell :D...
So HostProfileId is a filename prefix used to reference a custom powershell profile that exists in the same directory as the current powershell profile
This is the PowerShell equivalent of Line 393:
function GetProfilePathFromProfileObject( $profile, $user, $host ){ $profilePath = $profile."$user$host" Join-Path -Path (Split-Path $profilePath) -ChildPath "$($HostProfileId)_profile.ps1" }
We need to test this functionality
Start-EditorServices
#Common to Every Parameter Set:
[-HostName <String, Mandatory, Not Null or Empty>]
[-HostProfileId <String, Mandatory, Not Null or Empty>]
[-HostVersion <String, Mandatory, Not Null or Empty>]
[-BundledModulesPath <String, Not Null or Empty>]
[-LogPath <Not Null or Empty>]
[-LogLevel <String: "Diagnostic", "Verbose", "Normal", "Warning", "Error"]
[-SessionDetailsPath <String, Mandatory, Not Null or Empty>]
[-EnableConsoleRepl <Switch>]
[-UseLegacyReadLine <Switch>]
[-DebugServiceOnly <Switch>]
[-LanguageServiceOnly <Switch>]
[-AdditionalModules <String[]>]
[-FeatureFlags <String[]>]
[-WaitForDebugger <Switch>]
[-ConfirmInstall <Switch>]
#NamedPipe Parameter Set (Default):
[-LanguageServicePipeName = $null <String>]
[-DebugServicePipeName = $null <String>]
#Stdio Parameter Set:
[-Stdio <Switch>]
#NamedPipeSimplex Parameter Set:
[-SplitInOutPipes <Switch>]
[-LanguageServiceInPipeName <String>]
[-LanguageServiceOutPipeName <String>]
[-DebugServiceInPipeName = $null <String>]
[-DebugServiceOutPipeName = $null <String>]
Starts the language and debug services from the PowerShellEditorServices module.
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:
HostName (Breakdown):
HostProfileId (Breakdown):
Create an account to leave a comment. Already have an account? Log In.
Become a member to follow this project and never miss any updates