Skip to content

Commit 70a5278

Browse files
committed
Markup Microsoft.PowerShell.EditorServices.Server
1 parent 7f91147 commit 70a5278

File tree

3 files changed

+25
-4
lines changed

3 files changed

+25
-4
lines changed

src/PowerShellEditorServices/Server/PsesDebugServer.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ public async Task StartAsync()
9999
.AddLogging()
100100
.AddOptions()
101101
.AddPsesDebugServices(ServiceProvider, this, _useTempSession))
102+
// TODO: Consider replacing all WithHandler with AddSingleton
102103
.WithHandler<LaunchAndAttachHandler>()
103104
.WithHandler<DisconnectHandler>()
104105
.WithHandler<BreakpointHandlers>()

src/PowerShellEditorServices/Server/PsesLanguageServer.cs

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,16 @@ internal class PsesLanguageServer
3131

3232
/// <summary>
3333
/// Create a new language server instance.
34+
///
35+
/// NOTE: This class is only ever instantiated via <see
36+
/// cref="EditorServicesServerFactory.CreateLanguageServer"/>. It is essentially a
37+
/// singleton. The factory hides the logger.
3438
/// </summary>
3539
/// <param name="factory">Factory to create loggers with.</param>
3640
/// <param name="inputStream">Protocol transport input stream.</param>
3741
/// <param name="outputStream">Protocol transport output stream.</param>
38-
/// <param name="hostStartupInfo">Host configuration to instantiate the server and services with.</param>
42+
/// <param name="hostStartupInfo">Host configuration to instantiate the server and services
43+
/// with.</param>
3944
public PsesLanguageServer(
4045
ILoggerFactory factory,
4146
Stream inputStream,
@@ -52,6 +57,10 @@ public PsesLanguageServer(
5257

5358
/// <summary>
5459
/// Start the server listening for input.
60+
///
61+
/// For the services (including the <see cref="PowerShellContextService">
62+
/// context wrapper around PowerShell itself) see <see
63+
/// cref="PsesServiceCollectionExtensions.AddPsesLanguageServices"/>.
5564
/// </summary>
5665
/// <returns>A task that completes when the server is ready and listening.</returns>
5766
public async Task StartAsync()
@@ -62,11 +71,12 @@ public async Task StartAsync()
6271
.WithInput(_inputStream)
6372
.WithOutput(_outputStream)
6473
.WithServices(serviceCollection => serviceCollection
65-
.AddPsesLanguageServices(_hostDetails))
74+
.AddPsesLanguageServices(_hostDetails)) // NOTE: This adds a lot of services!
6675
.ConfigureLogging(builder => builder
67-
.AddSerilog(Log.Logger)
76+
.AddSerilog(Log.Logger) // TODO: Set dispose to true?
6877
.AddLanguageProtocolLogging()
6978
.SetMinimumLevel(_minimumLogLevel))
79+
// TODO: Consider replacing all WithHandler with AddSingleton
7080
.WithHandler<PsesWorkspaceSymbolsHandler>()
7181
.WithHandler<PsesTextDocumentHandler>()
7282
.WithHandler<GetVersionHandler>()
@@ -91,10 +101,14 @@ public async Task StartAsync()
91101
.WithHandler<ShowHelpHandler>()
92102
.WithHandler<ExpandAliasHandler>()
93103
.WithHandler<PsesSemanticTokensHandler>()
104+
// The OnInitialize delegate gets run when we first receive the _Initialize_ request:
105+
// https://microsoft.github.io/language-server-protocol/specifications/specification-current/#initialize
94106
.OnInitialize(
95107
// TODO: Either fix or ignore "method lacks 'await'" warning.
96108
async (languageServer, request, cancellationToken) =>
97109
{
110+
Log.Logger.Debug("Initializing OmniSharp Language Server");
111+
98112
var serviceProvider = languageServer.Services;
99113
var workspaceService = serviceProvider.GetService<WorkspaceService>();
100114

@@ -125,6 +139,7 @@ public async Task StartAsync()
125139
/// <returns>A task that completes when the server is shut down.</returns>
126140
public async Task WaitForShutdown()
127141
{
142+
Log.Logger.Debug("Shutting down OmniSharp Language Server");
128143
await _serverStart.Task.ConfigureAwait(false);
129144
await LanguageServer.WaitForExit.ConfigureAwait(false);
130145
}

src/PowerShellEditorServices/Server/PsesServiceCollectionExtensions.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,16 +24,21 @@ public static IServiceCollection AddPsesLanguageServices(
2424
(provider) =>
2525
PowerShellContextService.Create(
2626
provider.GetService<ILoggerFactory>(),
27+
// NOTE: Giving the context service access to the language server this
28+
// early is dangerous because it allows it to start sending
29+
// notifications etc. before it has initialized, potentially resulting
30+
// in deadlocks.
2731
provider.GetService<OmniSharp.Extensions.LanguageServer.Protocol.Server.ILanguageServerFacade>(),
2832
hostStartupInfo))
29-
.AddSingleton<TemplateService>()
33+
.AddSingleton<TemplateService>() // TODO: What's the difference between this and the TemplateHandler?
3034
.AddSingleton<EditorOperationsService>()
3135
.AddSingleton<RemoteFileManagerService>()
3236
.AddSingleton<ExtensionService>(
3337
(provider) =>
3438
{
3539
var extensionService = new ExtensionService(
3640
provider.GetService<PowerShellContextService>(),
41+
// NOTE: See above warning.
3742
provider.GetService<OmniSharp.Extensions.LanguageServer.Protocol.Server.ILanguageServerFacade>());
3843
extensionService.InitializeAsync(
3944
serviceProvider: provider,

0 commit comments

Comments
 (0)