@@ -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 }
0 commit comments