11// Copyright (c) Microsoft Corporation.
22// Licensed under the MIT License.
33
4- using Microsoft . PowerShell . EditorServices . Server ;
54using System ;
65using System . Collections . Generic ;
76using System . IO ;
87using System . Threading . Tasks ;
8+ using Microsoft . PowerShell . EditorServices . Server ;
99
1010namespace Microsoft . PowerShell . EditorServices . Hosting
1111{
1212 /// <summary>
1313 /// Class to manage the startup of PowerShell Editor Services.
14- /// This should be called by <see cref="EditorServicesLoader"/> only after Editor Services has been loaded.
1514 /// </summary>
15+ /// <remarks>
16+ /// This should be called by <see cref="EditorServicesLoader"/> only after Editor Services has
17+ /// been loaded. It relies on <see cref="EditorServicesServerFactory"/> to indirectly load <see
18+ /// cref="Microsoft.Extensions.Logging"/> and <see
19+ /// cref="Microsoft.Extensions.DependencyInjection"/>.
20+ /// </remarks>
1621 internal class EditorServicesRunner : IDisposable
1722 {
1823 private readonly HostLogger _logger ;
@@ -36,6 +41,7 @@ public EditorServicesRunner(
3641 _logger = logger ;
3742 _config = config ;
3843 _sessionFileWriter = sessionFileWriter ;
44+ // NOTE: This factory helps to isolate `Microsoft.Extensions.Logging/DependencyInjection`.
3945 _serverFactory = EditorServicesServerFactory . Create ( _config . LogPath , ( int ) _config . LogLevel , logger ) ;
4046 _alreadySubscribedDebug = false ;
4147 _loggersToUnsubscribe = loggersToUnsubscribe ;
@@ -44,10 +50,13 @@ public EditorServicesRunner(
4450 /// <summary>
4551 /// Start and run Editor Services and then wait for shutdown.
4652 /// </summary>
53+ /// <remarks>
54+ /// TODO: Use "Async" suffix in names of methods that return an awaitable type.
55+ /// </remarks>
4756 /// <returns>A task that ends when Editor Services shuts down.</returns>
4857 public Task RunUntilShutdown ( )
4958 {
50- // Start Editor Services
59+ // Start Editor Services (see function below)
5160 Task runAndAwaitShutdown = CreateEditorServicesAndRunUntilShutdown ( ) ;
5261
5362 // Now write the session file
@@ -59,14 +68,60 @@ public Task RunUntilShutdown()
5968 return runAndAwaitShutdown ;
6069 }
6170
71+ /// <remarks>
72+ /// TODO: This class probably should not be <see cref="IDisposable"/> as the primary
73+ /// intention of that interface is to provide cleanup of unmanaged resources, which the
74+ /// logger certainly is not. Nor is this class used with a <see langword="using"/>. It is
75+ /// only because of the use of <see cref="_serverFactory"/> that this class is also
76+ /// disposable, and instead that class should be fixed.
77+ /// </remarks>
6278 public void Dispose ( )
6379 {
6480 _serverFactory . Dispose ( ) ;
6581 }
6682
6783 /// <summary>
68- /// Master method for instantiating, running and waiting for the LSP and debug servers at the heart of Editor Services.
84+ /// This is the servers' entry point, e.g. <c>main</c>, as it instantiates, runs and waits
85+ /// for the LSP and debug servers at the heart of Editor Services. Uses <see
86+ /// cref="HostStartupInfo"/>.
6987 /// </summary>
88+ /// <remarks>
89+ /// The logical stack of the program is:
90+ /// <list type="number">
91+ /// <listheader>
92+ /// <term>Symbol</term>
93+ /// <description>Description</description>
94+ /// </listheader>
95+ /// <item>
96+ /// <term><see cref="Microsoft.PowerShell.EditorServices.Commands.StartEditorServicesCommand"/></term>
97+ /// <description>
98+ /// The StartEditorServicesCommand PSCmdlet, our PowerShell cmdlet written in C# and
99+ /// shipped in the module.
100+ /// </description>
101+ /// </item>
102+ /// <item>
103+ /// <term><see cref="Microsoft.PowerShell.EditorServices.Commands.StartEditorServicesCommand.EndProcessing"/></term>
104+ /// <description>
105+ /// As a cmdlet, this is the end of its "process" block, and it instantiates <see
106+ /// cref="EditorServicesLoader"/>.
107+ /// </description>
108+ /// </item>
109+ /// <item>
110+ /// <term><see cref="EditorServicesLoader.LoadAndRunEditorServicesAsync"></term>
111+ /// <description>
112+ /// Loads isolated dependencies then runs and returns the next task.
113+ /// </description>
114+ /// </item>
115+ /// <item>
116+ /// <term><see cref="RunUntilShutdown"></term>
117+ /// <description>Task which opens a logfile then returns this task.</description>
118+ /// </item>
119+ /// <item>
120+ /// <term><see cref="CreateEditorServicesAndRunUntilShutdown"></term>
121+ /// <description>This task!</description>
122+ /// </item>
123+ /// </list>
124+ /// </remarks>
70125 /// <returns>A task that ends when Editor Services shuts down.</returns>
71126 private async Task CreateEditorServicesAndRunUntilShutdown ( )
72127 {
0 commit comments