@@ -61,7 +61,14 @@ public static Task<ILanguageServer> From(Action<LanguageServerOptions> optionsAc
6161 {
6262 var options = new LanguageServerOptions ( ) ;
6363 optionsAction ( options ) ;
64- return From ( options ) ;
64+ return From ( options , token ) ;
65+ }
66+
67+ public static ILanguageServer PreInit ( Action < LanguageServerOptions > optionsAction )
68+ {
69+ var options = new LanguageServerOptions ( ) ;
70+ optionsAction ( options ) ;
71+ return PreInit ( options ) ;
6572 }
6673
6774 public static async Task < ILanguageServer > From ( LanguageServerOptions options , CancellationToken token )
@@ -91,6 +98,38 @@ public static async Task<ILanguageServer> From(LanguageServerOptions options, Ca
9198 return server ;
9299 }
93100
101+ /// <summary>
102+ /// Create the server without connecting to the client
103+ ///
104+ /// Mainly used for unit testing
105+ /// </summary>
106+ /// <param name="options"></param>
107+ /// <returns></returns>
108+ public static ILanguageServer PreInit ( LanguageServerOptions options )
109+ {
110+ var server = new LanguageServer (
111+ options . Input ,
112+ options . Output ,
113+ options . Reciever ,
114+ options . RequestProcessIdentifier ,
115+ options . LoggerFactory ,
116+ options . Serializer ,
117+ options . Services ,
118+ options . HandlerTypes . Select ( x => x . Assembly )
119+ . Distinct ( ) . Concat ( options . HandlerAssemblies ) ,
120+ options . Handlers ,
121+ options . NamedHandlers ,
122+ options . NamedServiceHandlers ,
123+ options . InitializeDelegates ,
124+ options . InitializedDelegates
125+ ) ;
126+
127+ if ( options . AddDefaultLoggingProvider )
128+ options . LoggerFactory . AddProvider ( new LanguageServerLoggerProvider ( server ) ) ;
129+
130+ return server ;
131+ }
132+
94133 internal LanguageServer (
95134 Stream input ,
96135 Stream output ,
@@ -132,7 +171,9 @@ internal LanguageServer(
132171 services . AddSingleton < ILanguageServer > ( this ) ;
133172 services . AddTransient < IHandlerMatcher , ExecuteCommandMatcher > ( ) ;
134173 services . AddTransient < IHandlerMatcher , ResolveCommandMatcher > ( ) ;
135- services . AddSingleton < IRequestRouter < ILspHandlerDescriptor > , LspRequestRouter > ( ) ;
174+ services . AddSingleton < LspRequestRouter > ( ) ;
175+ services . AddSingleton < IRequestRouter < ILspHandlerDescriptor > > ( _ => _ . GetRequiredService < LspRequestRouter > ( ) ) ;
176+ services . AddSingleton < IRequestRouter < IHandlerDescriptor > > ( _ => _ . GetRequiredService < LspRequestRouter > ( ) ) ;
136177 services . AddSingleton < IResponseRouter , ResponseRouter > ( ) ;
137178 services . AddTransient ( typeof ( IPipelineBehavior < , > ) , typeof ( ResolveCommandPipeline < , > ) ) ;
138179
@@ -285,7 +326,7 @@ async Task<InitializeResult> IRequestHandler<InitializeParams, InitializeResult>
285326 MinimumLogLevel = LogLevel . Trace ;
286327 }
287328
288- _clientVersion = request . Capabilities . GetClientVersion ( ) ;
329+ _clientVersion = request . Capabilities ? . GetClientVersion ( ) ?? ClientVersion . Lsp2 ;
289330 _serializer . SetClientCapabilities ( _clientVersion . Value , request . Capabilities ) ;
290331
291332 var supportedCapabilities = new List < ISupports > ( ) ;
@@ -312,8 +353,8 @@ async Task<InitializeResult> IRequestHandler<InitializeParams, InitializeResult>
312353
313354 await Task . WhenAll ( _initializeDelegates . Select ( c => c ( this , request ) ) ) ;
314355
315- var textDocumentCapabilities = ClientSettings . Capabilities . TextDocument ;
316- var workspaceCapabilities = ClientSettings . Capabilities . Workspace ;
356+ var textDocumentCapabilities = ClientSettings . Capabilities ? . TextDocument ?? new TextDocumentClientCapabilities ( ) ;
357+ var workspaceCapabilities = ClientSettings . Capabilities ? . Workspace ?? new WorkspaceClientCapabilities ( ) ;
317358
318359 var ccp = new ClientCapabilityProvider ( _collection ) ;
319360
0 commit comments