11
11
using OmniSharp . Extensions . LanguageServer . Protocol . Models ;
12
12
using Xunit ;
13
13
using HandlerCollection = OmniSharp . Extensions . LanguageServer . Server . HandlerCollection ;
14
+ using System . Collections . Generic ;
14
15
15
16
namespace Lsp . Tests
16
17
{
@@ -133,7 +134,8 @@ public void Should_Contain_AllDefinedMethods_OnLanguageServer(Type requestHandle
133
134
var sub = ( IJsonRpcHandler ) Substitute . For ( new Type [ ] { requestHandler , type2 } , new object [ 0 ] ) ;
134
135
if ( sub is IRegistration < TextDocumentRegistrationOptions > reg )
135
136
reg . GetRegistrationOptions ( )
136
- . Returns ( new TextDocumentRegistrationOptions ( ) {
137
+ . Returns ( new TextDocumentRegistrationOptions ( )
138
+ {
137
139
DocumentSelector = new DocumentSelector ( )
138
140
} ) ;
139
141
handler . Add ( sub ) ;
@@ -150,13 +152,15 @@ public void Should_Contain_AllDefinedMethods_OnLanguageServer_WithDifferentKeys(
150
152
var sub = ( IJsonRpcHandler ) Substitute . For ( new Type [ ] { requestHandler , type2 } , new object [ 0 ] ) ;
151
153
if ( sub is IRegistration < TextDocumentRegistrationOptions > reg )
152
154
reg . GetRegistrationOptions ( )
153
- . Returns ( new TextDocumentRegistrationOptions ( ) {
155
+ . Returns ( new TextDocumentRegistrationOptions ( )
156
+ {
154
157
DocumentSelector = new DocumentSelector ( )
155
158
} ) ;
156
159
var sub2 = ( IJsonRpcHandler ) Substitute . For ( new Type [ ] { requestHandler , type2 } , new object [ 0 ] ) ;
157
160
if ( sub2 is IRegistration < TextDocumentRegistrationOptions > reg2 )
158
161
reg2 . GetRegistrationOptions ( )
159
- . Returns ( new TextDocumentRegistrationOptions ( ) {
162
+ . Returns ( new TextDocumentRegistrationOptions ( )
163
+ {
160
164
DocumentSelector = new DocumentSelector ( )
161
165
} ) ;
162
166
handler . Add ( sub ) ;
@@ -172,12 +176,31 @@ public void Should_AllowSpecificHandlers_ToBeAdded(string method, Type handlerTy
172
176
{
173
177
var handler = new HandlerCollection ( ) ;
174
178
var sub = ( IJsonRpcHandler ) Substitute . For ( new Type [ ] { handlerType } , new object [ 0 ] ) ;
175
- var sub2 = ( IJsonRpcHandler ) Substitute . For ( new Type [ ] { handlerType } , new object [ 0 ] ) ;
179
+ var sub2 = ( IJsonRpcHandler ) Substitute . For ( new Type [ ] { handlerType } , new object [ 0 ] ) ;
176
180
handler . Add ( method , sub ) ;
177
181
handler . Add ( method , sub2 ) ;
178
182
handler . _handlers . Should ( ) . Contain ( x => x . Method == method ) ;
179
183
handler . _handlers . Should ( ) . Contain ( x => x . Method == method ) ;
180
184
handler . _handlers . Count . Should ( ) . Be ( 1 ) ;
181
185
}
186
+
187
+ [ Theory ]
188
+ [ MemberData ( nameof ( Should_DealWithClassesThatImplementMultipleHandlers_WithoutConflictingRegistrations_Data ) ) ]
189
+ public void Should_DealWithClassesThatImplementMultipleHandlers_WithoutConflictingRegistrations ( string method , IJsonRpcHandler sub )
190
+ {
191
+ var handler = new HandlerCollection ( ) ;
192
+ handler . Add ( sub ) ;
193
+
194
+ var descriptor = handler . _handlers . First ( x => x . Method == method ) ;
195
+ descriptor . Key . Should ( ) . Be ( "default" ) ;
196
+ }
197
+
198
+ public static IEnumerable < object [ ] > Should_DealWithClassesThatImplementMultipleHandlers_WithoutConflictingRegistrations_Data ( )
199
+ {
200
+ yield return new object [ ] {
201
+ DocumentNames . CodeLensResolve ,
202
+ Substitute . For ( new Type [ ] { typeof ( ICodeLensHandler ) , typeof ( ICodeLensResolveHandler ) } , new object [ 0 ] )
203
+ } ;
204
+ }
182
205
}
183
206
}
0 commit comments