@@ -60,16 +60,16 @@ public IDisposable AddHandler(IJsonRpcHandler handler)
60
60
return AddHandler ( handler ) ;
61
61
}
62
62
63
- public IDisposable AddHandlers ( params IJsonRpcHandler [ ] handlers )
63
+ public IDisposable AddHandlers ( IEnumerable < IJsonRpcHandler > handlers )
64
64
{
65
- return AddHandlers ( handlers . AsEnumerable ( ) ) ;
65
+ return AddHandlers ( handlers . ToArray ( ) ) ;
66
66
}
67
67
68
- public IDisposable AddHandlers ( IEnumerable < IJsonRpcHandler > handlers )
68
+ public IDisposable AddHandlers ( params IJsonRpcHandler [ ] handlers )
69
69
{
70
70
var handlerDisposable = _collection . Add ( handlers ) ;
71
71
72
- return new ImutableDisposable (
72
+ return new ImmutableDisposable (
73
73
handlerDisposable ,
74
74
new Disposable ( ( ) =>
75
75
{
@@ -122,24 +122,27 @@ async Task<InitializeResult> IRequestHandler<InitializeParams, InitializeResult>
122
122
}
123
123
}
124
124
125
+ var textDocumentCapabilities = Client . Capabilities . TextDocument ;
126
+ var workspaceCapabilities = Client . Capabilities . Workspace ;
127
+
125
128
var serverCapabilities = new ServerCapabilities ( )
126
129
{
127
- CodeActionProvider = HasHandler < ICodeActionHandler > ( ) ,
128
- CodeLensProvider = GetOptions < ICodeLensOptions , CodeLensOptions > ( CodeLensOptions . Of ) ,
129
- CompletionProvider = GetOptions < ICompletionOptions , CompletionOptions > ( CompletionOptions . Of ) ,
130
- DefinitionProvider = HasHandler < IDefinitionHandler > ( ) ,
131
- DocumentFormattingProvider = HasHandler < IDocumentFormattingHandler > ( ) ,
132
- DocumentHighlightProvider = HasHandler < IDocumentHighlightHandler > ( ) ,
133
- DocumentLinkProvider = GetOptions < IDocumentLinkOptions , DocumentLinkOptions > ( DocumentLinkOptions . Of ) ,
134
- DocumentOnTypeFormattingProvider = GetOptions < IDocumentOnTypeFormattingOptions , DocumentOnTypeFormattingOptions > ( DocumentOnTypeFormattingOptions . Of ) ,
135
- DocumentRangeFormattingProvider = HasHandler < IDocumentRangeFormattingHandler > ( ) ,
136
- DocumentSymbolProvider = HasHandler < IDocumentSymbolHandler > ( ) ,
137
- ExecuteCommandProvider = GetOptions < IExecuteCommandOptions , ExecuteCommandOptions > ( ExecuteCommandOptions . Of ) ,
138
- HoverProvider = HasHandler < IHoverHandler > ( ) ,
139
- ReferencesProvider = HasHandler < IReferencesHandler > ( ) ,
140
- RenameProvider = HasHandler < IRenameHandler > ( ) ,
141
- SignatureHelpProvider = GetOptions < ISignatureHelpOptions , SignatureHelpOptions > ( SignatureHelpOptions . Of ) ,
142
- WorkspaceSymbolProvider = HasHandler < IWorkspaceSymbolsHandler > ( )
130
+ CodeActionProvider = HasHandler < ICodeActionHandler > ( textDocumentCapabilities . CodeAction ) ,
131
+ CodeLensProvider = GetOptions < ICodeLensOptions , CodeLensOptions > ( textDocumentCapabilities . CodeLens , CodeLensOptions . Of ) ,
132
+ CompletionProvider = GetOptions < ICompletionOptions , CompletionOptions > ( textDocumentCapabilities . Completion , CompletionOptions . Of ) ,
133
+ DefinitionProvider = HasHandler < IDefinitionHandler > ( textDocumentCapabilities . Definition ) ,
134
+ DocumentFormattingProvider = HasHandler < IDocumentFormattingHandler > ( textDocumentCapabilities . Formatting ) ,
135
+ DocumentHighlightProvider = HasHandler < IDocumentHighlightHandler > ( textDocumentCapabilities . DocumentHighlight ) ,
136
+ DocumentLinkProvider = GetOptions < IDocumentLinkOptions , DocumentLinkOptions > ( textDocumentCapabilities . DocumentLink , DocumentLinkOptions . Of ) ,
137
+ DocumentOnTypeFormattingProvider = GetOptions < IDocumentOnTypeFormattingOptions , DocumentOnTypeFormattingOptions > ( textDocumentCapabilities . OnTypeFormatting , DocumentOnTypeFormattingOptions . Of ) ,
138
+ DocumentRangeFormattingProvider = HasHandler < IDocumentRangeFormattingHandler > ( textDocumentCapabilities . RangeFormatting ) ,
139
+ DocumentSymbolProvider = HasHandler < IDocumentSymbolHandler > ( textDocumentCapabilities . DocumentSymbol ) ,
140
+ ExecuteCommandProvider = GetOptions < IExecuteCommandOptions , ExecuteCommandOptions > ( workspaceCapabilities . ExecuteCommand , ExecuteCommandOptions . Of ) ,
141
+ HoverProvider = HasHandler < IHoverHandler > ( textDocumentCapabilities . Hover ) ,
142
+ ReferencesProvider = HasHandler < IReferencesHandler > ( textDocumentCapabilities . References ) ,
143
+ RenameProvider = HasHandler < IRenameHandler > ( textDocumentCapabilities . Rename ) ,
144
+ SignatureHelpProvider = GetOptions < ISignatureHelpOptions , SignatureHelpOptions > ( textDocumentCapabilities . SignatureHelp , SignatureHelpOptions . Of ) ,
145
+ WorkspaceSymbolProvider = HasHandler < IWorkspaceSymbolsHandler > ( workspaceCapabilities . Symbol )
143
146
} ;
144
147
145
148
var textSyncHandler = _collection
@@ -194,19 +197,34 @@ public Task Handle()
194
197
return Task . CompletedTask ;
195
198
}
196
199
197
- private bool HasHandler < T > ( )
200
+ private bool HasHandler < T > ( DynamicCapability capability )
198
201
{
199
- return _collection . Any ( z => z . Handler is T ) ;
202
+ return capability . DynamicRegistration ? false : _collection . Any ( z => z . Handler is T ) ;
200
203
}
201
204
202
- private T GetOptions < O , T > ( Func < O , T > action )
205
+ private bool HasHandler < T > ( Supports < DynamicCapability > capability )
206
+ {
207
+ if ( ! capability . IsSupported ) return false ;
208
+ return HasHandler < T > ( capability . Value ) ;
209
+ }
210
+
211
+ private T GetOptions < O , T > ( DynamicCapability capability , Func < O , T > action )
203
212
where T : class
204
213
{
214
+ if ( capability . DynamicRegistration ) return null ;
215
+
205
216
return _collection
206
217
. Select ( x => x . Registration ? . RegisterOptions is O cl ? action ( cl ) : null )
207
218
. FirstOrDefault ( x => x != null ) ;
208
219
}
209
220
221
+ private T GetOptions < O , T > ( Supports < DynamicCapability > capability , Func < O , T > action )
222
+ where T : class
223
+ {
224
+ if ( ! capability . IsSupported ) return null ;
225
+ return GetOptions < O , T > ( capability . Value , action ) ;
226
+ }
227
+
210
228
private void ProcessCapabilties ( object instance )
211
229
{
212
230
var values = instance
0 commit comments