Skip to content

Commit 6728a90

Browse files
committed
Markup PowerShellEditorServices.Hosting
1 parent d06d937 commit 6728a90

File tree

4 files changed

+73
-13
lines changed

4 files changed

+73
-13
lines changed

src/PowerShellEditorServices.Hosting/BuildInfo.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ namespace Microsoft.PowerShell.EditorServices.Hosting
44
{
55
public static class BuildInfo
66
{
7+
// TODO: Include a Git commit hash in this.
78
public static readonly string BuildVersion = "<development-build>";
89
public static readonly string BuildOrigin = "<development>";
910
public static readonly System.DateTime? BuildTime = System.DateTime.Parse("2019-12-06T21:43:41", CultureInfo.InvariantCulture.DateTimeFormat);

src/PowerShellEditorServices.Hosting/Configuration/HostLogger.cs

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,12 @@ namespace Microsoft.PowerShell.EditorServices.Hosting
1414
{
1515
/// <summary>
1616
/// User-facing log level for editor services configuration.
17-
/// The underlying values of this enum align to both Microsoft.Logging.Extensions.LogLevel
18-
/// and Serilog.Events.LogEventLevel.
1917
/// </summary>
18+
/// <remarks>
19+
/// The underlying values of this enum attempt to align to both <see
20+
/// cref="Microsoft.Logging.Extensions.LogLevel"</see> and <see
21+
/// cref="Serilog.Events.LogEventLevel"</see>.
22+
/// </remarks>
2023
public enum PsesLogLevel
2124
{
2225
Diagnostic = 0,
@@ -27,9 +30,14 @@ public enum PsesLogLevel
2730
}
2831

2932
/// <summary>
30-
/// A logging front-end for host startup allowing handover to the backend
31-
/// and decoupling from the host's particular logging sink.
33+
/// A logging front-end for host startup allowing handover to the backend and decoupling from
34+
/// the host's particular logging sink.
3235
/// </summary>
36+
/// <remarks>
37+
/// This custom logger exists to allow us to log during startup, which is vital information for
38+
/// debugging, but happens before we can load any logger library. This is because startup
39+
/// happens in our isolated assembly environment. See #2292 for more information.
40+
/// </remarks>
3341
public sealed class HostLogger :
3442
IObservable<(PsesLogLevel logLevel, string message)>,
3543
IObservable<(int logLevel, string message)>

src/PowerShellEditorServices.Hosting/EditorServicesLoader.cs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -263,11 +263,7 @@ private void UpdatePSModulePath()
263263

264264
private void LogHostInformation()
265265
{
266-
_logger.Log(PsesLogLevel.Diagnostic, "Logging host information");
267-
268-
_logger.Log(PsesLogLevel.Diagnostic, $@"
269-
PID: {System.Diagnostics.Process.GetCurrentProcess().Id}
270-
");
266+
_logger.Log(PsesLogLevel.Verbose, $"PID: {System.Diagnostics.Process.GetCurrentProcess().Id}");
271267

272268
_logger.Log(PsesLogLevel.Verbose, $@"
273269
== Build Details ==

src/PowerShellEditorServices.Hosting/Internal/EditorServicesRunner.cs

Lines changed: 59 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,23 @@
11
// Copyright (c) Microsoft Corporation.
22
// Licensed under the MIT License.
33

4-
using Microsoft.PowerShell.EditorServices.Server;
54
using System;
65
using System.Collections.Generic;
76
using System.IO;
87
using System.Threading.Tasks;
8+
using Microsoft.PowerShell.EditorServices.Server;
99

1010
namespace 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

Comments
 (0)