Skip to content

Commit 7f91147

Browse files
committed
Markup Microsoft.PowerShell.EditorServices.Hosting
1 parent af3cffa commit 7f91147

File tree

4 files changed

+79
-16
lines changed

4 files changed

+79
-16
lines changed

src/PowerShellEditorServices/Hosting/EditorServicesLoading.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ internal static class EditorServicesLoading
1111
{
1212
internal static void LoadEditorServicesForHost()
1313
{
14-
// No op that forces loading this assembly
14+
// No-op that forces loading this assembly
1515
}
1616
}
1717
}

src/PowerShellEditorServices/Hosting/EditorServicesServerFactory.cs

Lines changed: 63 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,22 @@ namespace Microsoft.PowerShell.EditorServices.Hosting
2121
{
2222
/// <summary>
2323
/// Factory class for hiding dependencies of Editor Services.
24-
/// In particular, dependency injection and logging are wrapped by factory methods on this class
25-
/// so that the host assembly can construct the LSP and debug servers
26-
/// without taking logging or dependency injection dependencies directly.
24+
///
25+
/// NOTE: dependency injection and logging are wrapped by factory methods on this class so that
26+
/// the host assembly can construct the LSP and debug servers without directly depending on <see
27+
/// cref="Microsoft.Extensions.Logging"/>
28+
/// and <see cref="Microsoft.Extensions.DependencyInjection"/>.
2729
/// </summary>
2830
internal class EditorServicesServerFactory : IDisposable
2931
{
3032
/// <summary>
31-
/// Create a new Editor Services factory.
32-
/// This method will instantiate logging.
33+
/// Create a new Editor Services factory. This method will instantiate logging.
34+
///
35+
/// NOTE: This can only be called once because it sets global state (the logger) and that
36+
/// call is in <see cref="EditorServicesRunner"/>.
37+
///
38+
/// TODO: Why is this a static function wrapping a constructor instead of just a
39+
/// constructor? In the end it returns an instance (albeit a "singleton").
3340
/// </summary>
3441
/// <param name="logPath">The path of the log file to use.</param>
3542
/// <param name="minimumLogLevel">The minimum log level to use.</param>
@@ -69,10 +76,15 @@ private EditorServicesServerFactory(ILoggerFactory loggerFactory, LogLevel minim
6976

7077
/// <summary>
7178
/// Create the LSP server.
79+
///
80+
/// NOTE: This is only called once and that's in <see cref="EditorServicesRunner"/>.
81+
///
82+
/// TODO: Why is this a method on this class? It only uses <see cref="_loggerFactory"/>.
7283
/// </summary>
7384
/// <param name="inputStream">The protocol transport input stream.</param>
7485
/// <param name="outputStream">The protocol transport output stream.</param>
75-
/// <param name="hostStartupInfo">The host details configuration for Editor Services instantation.</param>
86+
/// <param name="hostStartupInfo">The host details configuration for Editor Services
87+
/// instantation.</param>
7688
/// <returns>A new, unstarted language server instance.</returns>
7789
public PsesLanguageServer CreateLanguageServer(
7890
Stream inputStream,
@@ -84,42 +96,73 @@ public PsesLanguageServer CreateLanguageServer(
8496

8597
/// <summary>
8698
/// Create the debug server given a language server instance.
99+
///
100+
/// NOTE: This is only called once and that's in <see cref="EditorServicesRunner"/>.
101+
///
102+
/// TODO: Why is this a method on this class? It only uses <see cref="_loggerFactory"/>.
87103
/// </summary>
88104
/// <param name="inputStream">The protocol transport input stream.</param>
89105
/// <param name="outputStream">The protocol transport output stream.</param>
90106
/// <param name="languageServer"></param>
91107
/// <returns>A new, unstarted debug server instance.</returns>
92-
public PsesDebugServer CreateDebugServerWithLanguageServer(Stream inputStream, Stream outputStream, PsesLanguageServer languageServer, bool usePSReadLine)
108+
public PsesDebugServer CreateDebugServerWithLanguageServer(
109+
Stream inputStream,
110+
Stream outputStream,
111+
PsesLanguageServer languageServer,
112+
bool usePSReadLine)
93113
{
94-
return new PsesDebugServer(_loggerFactory, inputStream, outputStream, languageServer.LanguageServer.Services, useTempSession: false, usePSReadLine);
114+
return new PsesDebugServer(
115+
_loggerFactory,
116+
inputStream,
117+
outputStream,
118+
languageServer.LanguageServer.Services,
119+
useTempSession: false,
120+
usePSReadLine);
95121
}
96122

97123
/// <summary>
98124
/// Create a new debug server based on an old one in an ended session.
125+
///
126+
/// NOTE: This is only called once and that's in <see cref="EditorServicesRunner"/>.
127+
///
128+
/// TODO: Why is this a method on this class? It only uses <see cref="_loggerFactory"/>.
99129
/// </summary>
100130
/// <param name="inputStream">The protocol transport input stream.</param>
101131
/// <param name="outputStream">The protocol transport output stream.</param>
102132
/// <param name="debugServer">The old debug server to recreate.</param>
103133
/// <returns></returns>
104-
public PsesDebugServer RecreateDebugServer(Stream inputStream, Stream outputStream, PsesDebugServer debugServer, bool usePSReadLine)
134+
public PsesDebugServer RecreateDebugServer(
135+
Stream inputStream,
136+
Stream outputStream,
137+
PsesDebugServer debugServer,
138+
bool usePSReadLine)
105139
{
106-
return new PsesDebugServer(_loggerFactory, inputStream, outputStream, debugServer.ServiceProvider, useTempSession: false, usePSReadLine);
140+
return new PsesDebugServer(
141+
_loggerFactory,
142+
inputStream,
143+
outputStream,
144+
debugServer.ServiceProvider,
145+
useTempSession: false,
146+
usePSReadLine);
107147
}
108148

109149
/// <summary>
110150
/// Create a standalone debug server for temp sessions.
151+
///
152+
/// TODO: What is a "temp session" and how is this different?
111153
/// </summary>
112154
/// <param name="inputStream">The protocol transport input stream.</param>
113155
/// <param name="outputStream">The protocol transport output stream.</param>
114156
/// <param name="hostStartupInfo">The host startup configuration to create the server session with.</param>
115157
/// <returns></returns>
116-
public PsesDebugServer CreateDebugServerForTempSession(Stream inputStream, Stream outputStream, HostStartupInfo hostStartupInfo)
158+
public PsesDebugServer CreateDebugServerForTempSession(
159+
Stream inputStream, Stream outputStream, HostStartupInfo hostStartupInfo)
117160
{
118161
var serviceProvider = new ServiceCollection()
119162
.AddLogging(builder => builder
120163
.ClearProviders()
121164
.AddSerilog()
122-
.SetMinimumLevel(LogLevel.Trace))
165+
.SetMinimumLevel(LogLevel.Trace)) // TODO: Why randomly set to trace?
123166
.AddSingleton<ILanguageServerFacade>(provider => null)
124167
.AddPsesLanguageServices(hostStartupInfo)
125168
// For a Temp session, there is no LanguageServer so just set it to null
@@ -143,6 +186,14 @@ public PsesDebugServer CreateDebugServerForTempSession(Stream inputStream, Strea
143186
usePSReadLine: hostStartupInfo.ConsoleReplEnabled && !hostStartupInfo.UsesLegacyReadLine);
144187
}
145188

189+
/// <summary>
190+
/// TODO: This class probably should not be <see cref="IDisposable"/> as the primary
191+
/// intention of that interface is to provide cleanup of unmanaged resources, which the
192+
/// logger certainly is not. Nor is this class used with a <see langword="using"/>. Instead,
193+
/// this class should call <see cref="Serilog.Log.CloseAndFlush()"/> in a finalizer. This
194+
/// could potentially even be done with <see
195+
/// cref="SerilogLoggerFactoryExtensions.AddSerilog"</> by passing <c>dispose=true</c>.
196+
/// </summary>
146197
public void Dispose()
147198
{
148199
Log.CloseAndFlush();

src/PowerShellEditorServices/Hosting/HostStartupInfo.cs

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,10 @@
99
namespace Microsoft.PowerShell.EditorServices.Hosting
1010
{
1111
/// <summary>
12-
/// Contains details about the host as well as any other information
13-
/// needed by Editor Services at startup time.
12+
/// Contains details about the host as well as any other information needed by Editor Services
13+
/// at startup time.
14+
///
15+
/// TODO: Can this be simplified as a <see langword="record"/>?
1416
/// </summary>
1517
public sealed class HostStartupInfo
1618
{
@@ -96,6 +98,10 @@ public sealed class HostStartupInfo
9698

9799
/// <summary>
98100
/// The minimum log level of log events to be logged.
101+
///
102+
/// NOTE: This is cast to all of <see cref="PsesLogLevel"/>, <see
103+
/// cref="Microsoft.Extensions.Logging.LogLevel"/>, and <see
104+
/// cref="Serilog.Events.LogEventLevel"/>, hence it is an <c>int</c>.
99105
/// </summary>
100106
public int LogLevel { get; }
101107

@@ -158,6 +164,12 @@ public HostStartupInfo(
158164
#endregion
159165
}
160166

167+
/// <summary>
168+
/// This is a strange class that is generally <c>null</c> or otherwise just has a single path
169+
/// set. It is eventually parsed one-by-one when setting up the PowerShell runspace.
170+
///
171+
/// TODO: This could probably be very simplified.
172+
/// </summary>
161173
public sealed class ProfilePathInfo
162174
{
163175
public ProfilePathInfo(

src/PowerShellEditorServices/Logging/PsesTelemetryEvent.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
namespace Microsoft.PowerShell.EditorServices.Logging
88
{
9-
// This inheirits from Dictionary so that it can be passed in to SendTelemetryEvent()
9+
// This inherits from Dictionary so that it can be passed in to SendTelemetryEvent()
1010
// which takes in an IDictionary<string, object>
1111
// However, I wanted creation to be easy so you can do
1212
// new PsesTelemetryEvent { EventName = "eventName", Data = data }

0 commit comments

Comments
 (0)