1
1
// Copyright (c) Microsoft Corporation.
2
2
// Licensed under the MIT License.
3
3
4
- using Microsoft . PowerShell . EditorServices . Server ;
5
4
using System ;
6
5
using System . Collections . Generic ;
7
6
using System . IO ;
8
7
using System . Threading . Tasks ;
8
+ using Microsoft . PowerShell . EditorServices . Server ;
9
9
10
10
namespace Microsoft . PowerShell . EditorServices . Hosting
11
11
{
12
12
/// <summary>
13
13
/// 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.
15
14
/// </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>
16
21
internal class EditorServicesRunner : IDisposable
17
22
{
18
23
private readonly HostLogger _logger ;
@@ -36,6 +41,7 @@ public EditorServicesRunner(
36
41
_logger = logger ;
37
42
_config = config ;
38
43
_sessionFileWriter = sessionFileWriter ;
44
+ // NOTE: This factory helps to isolate `Microsoft.Extensions.Logging/DependencyInjection`.
39
45
_serverFactory = EditorServicesServerFactory . Create ( _config . LogPath , ( int ) _config . LogLevel , logger ) ;
40
46
_alreadySubscribedDebug = false ;
41
47
_loggersToUnsubscribe = loggersToUnsubscribe ;
@@ -44,10 +50,13 @@ public EditorServicesRunner(
44
50
/// <summary>
45
51
/// Start and run Editor Services and then wait for shutdown.
46
52
/// </summary>
53
+ /// <remarks>
54
+ /// TODO: Use "Async" suffix in names of methods that return an awaitable type.
55
+ /// </remarks>
47
56
/// <returns>A task that ends when Editor Services shuts down.</returns>
48
57
public Task RunUntilShutdown ( )
49
58
{
50
- // Start Editor Services
59
+ // Start Editor Services (see function below)
51
60
Task runAndAwaitShutdown = CreateEditorServicesAndRunUntilShutdown ( ) ;
52
61
53
62
// Now write the session file
@@ -59,14 +68,60 @@ public Task RunUntilShutdown()
59
68
return runAndAwaitShutdown ;
60
69
}
61
70
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>
62
78
public void Dispose ( )
63
79
{
64
80
_serverFactory . Dispose ( ) ;
65
81
}
66
82
67
83
/// <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"/>.
69
87
/// </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>
70
125
/// <returns>A task that ends when Editor Services shuts down.</returns>
71
126
private async Task CreateEditorServicesAndRunUntilShutdown ( )
72
127
{
0 commit comments