11using System ;
22using System . Collections . Concurrent ;
3+ using System . Collections . Generic ;
34using System . Linq ;
45using System . Reflection ;
56using System . Threading ;
@@ -18,7 +19,7 @@ namespace OmniSharp.Extensions.LanguageServer
1819 class LspRequestRouter : IRequestRouter
1920 {
2021 private readonly IHandlerCollection _collection ;
21- private ITextDocumentSyncHandler _textDocumentSyncHandler ;
22+ private ITextDocumentSyncHandler [ ] _textDocumentSyncHandlers ;
2223 private readonly ConcurrentDictionary < string , CancellationTokenSource > _requests = new ConcurrentDictionary < string , CancellationTokenSource > ( ) ;
2324
2425 public LspRequestRouter ( IHandlerCollection collection )
@@ -46,19 +47,20 @@ private ILspHandlerDescriptor FindDescriptor(string method, JToken @params)
4647 var descriptor = _collection . FirstOrDefault ( x => x . Method == method ) ;
4748 if ( descriptor is null ) return null ;
4849
49- if ( _textDocumentSyncHandler == null )
50+ if ( _textDocumentSyncHandlers == null )
5051 {
51- _textDocumentSyncHandler = _collection
52+ _textDocumentSyncHandlers = _collection
5253 . Select ( x => x . Handler is ITextDocumentSyncHandler r ? r : null )
53- . FirstOrDefault ( x => x != null ) ;
54+ . Where ( x => x != null )
55+ . ToArray ( ) ;
5456 }
5557
56- if ( _textDocumentSyncHandler is null ) return descriptor ;
57-
5858 if ( typeof ( ITextDocumentIdentifierParams ) . GetTypeInfo ( ) . IsAssignableFrom ( descriptor . Params ) )
5959 {
6060 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 ) ;
6264
6365 return GetHandler ( method , attributes ) ;
6466 }
@@ -75,6 +77,13 @@ private ILspHandlerDescriptor FindDescriptor(string method, JToken @params)
7577 return descriptor ;
7678 }
7779
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+
7887 private ILspHandlerDescriptor GetHandler ( string method , TextDocumentAttributes attributes )
7988 {
8089 foreach ( var handler in _collection . Where ( x => x . Method == method ) )
0 commit comments