1
1
using System ;
2
2
using System . Collections . Concurrent ;
3
+ using System . Collections . Generic ;
3
4
using System . Linq ;
4
5
using System . Reflection ;
5
6
using System . Threading ;
@@ -18,7 +19,7 @@ namespace OmniSharp.Extensions.LanguageServer
18
19
class LspRequestRouter : IRequestRouter
19
20
{
20
21
private readonly IHandlerCollection _collection ;
21
- private ITextDocumentSyncHandler _textDocumentSyncHandler ;
22
+ private ITextDocumentSyncHandler [ ] _textDocumentSyncHandlers ;
22
23
private readonly ConcurrentDictionary < string , CancellationTokenSource > _requests = new ConcurrentDictionary < string , CancellationTokenSource > ( ) ;
23
24
24
25
public LspRequestRouter ( IHandlerCollection collection )
@@ -46,19 +47,20 @@ private ILspHandlerDescriptor FindDescriptor(string method, JToken @params)
46
47
var descriptor = _collection . FirstOrDefault ( x => x . Method == method ) ;
47
48
if ( descriptor is null ) return null ;
48
49
49
- if ( _textDocumentSyncHandler == null )
50
+ if ( _textDocumentSyncHandlers == null )
50
51
{
51
- _textDocumentSyncHandler = _collection
52
+ _textDocumentSyncHandlers = _collection
52
53
. Select ( x => x . Handler is ITextDocumentSyncHandler r ? r : null )
53
- . FirstOrDefault ( x => x != null ) ;
54
+ . Where ( x => x != null )
55
+ . ToArray ( ) ;
54
56
}
55
57
56
- if ( _textDocumentSyncHandler is null ) return descriptor ;
57
-
58
58
if ( typeof ( ITextDocumentIdentifierParams ) . GetTypeInfo ( ) . IsAssignableFrom ( descriptor . Params ) )
59
59
{
60
60
var textDocumentIdentifierParams = @params . ToObject ( descriptor . Params ) as ITextDocumentIdentifierParams ;
61
- var attributes = _textDocumentSyncHandler . GetTextDocumentAttributes ( textDocumentIdentifierParams . TextDocument . Uri ) ;
61
+ var attributes = _textDocumentSyncHandlers
62
+ . Select ( x => x . GetTextDocumentAttributes ( textDocumentIdentifierParams . TextDocument . Uri ) )
63
+ . Where ( x => x != null ) ;
62
64
63
65
return GetHandler ( method , attributes ) ;
64
66
}
@@ -75,6 +77,13 @@ private ILspHandlerDescriptor FindDescriptor(string method, JToken @params)
75
77
return descriptor ;
76
78
}
77
79
80
+ private ILspHandlerDescriptor GetHandler ( string method , IEnumerable < TextDocumentAttributes > attributes )
81
+ {
82
+ return attributes
83
+ . Select ( x => GetHandler ( method , x ) )
84
+ . FirstOrDefault ( x => x != null ) ;
85
+ }
86
+
78
87
private ILspHandlerDescriptor GetHandler ( string method , TextDocumentAttributes attributes )
79
88
{
80
89
foreach ( var handler in _collection . Where ( x => x . Method == method ) )
0 commit comments