@@ -18,24 +18,9 @@ namespace Lsp.Tests
18
18
{
19
19
public class ClientCapabilityProviderTests
20
20
{
21
- private static readonly Type [ ] Capabilities = {
22
- typeof ( CompletionCapability ) ,
23
- typeof ( HoverCapability ) ,
24
- typeof ( SignatureHelpCapability ) ,
25
- typeof ( ReferencesCapability ) ,
26
- typeof ( DocumentHighlightCapability ) ,
27
- typeof ( DocumentSymbolCapability ) ,
28
- typeof ( DocumentFormattingCapability ) ,
29
- typeof ( DocumentRangeFormattingCapability ) ,
30
- typeof ( DocumentOnTypeFormattingCapability ) ,
31
- typeof ( DefinitionCapability ) ,
32
- typeof ( CodeActionCapability ) ,
33
- typeof ( CodeLensCapability ) ,
34
- typeof ( DocumentLinkCapability ) ,
35
- typeof ( RenameCapability ) ,
36
- typeof ( WorkspaceSymbolCapability ) ,
37
- typeof ( ExecuteCommandCapability ) ,
38
- } ;
21
+ private static readonly Type [ ] Capabilities = typeof ( ClientCapabilities ) . Assembly . GetTypes ( )
22
+ . Where ( x => x . GetInterfaces ( ) . Any ( i => i . IsGenericType && i . GetGenericTypeDefinition ( ) == typeof ( ConnectedCapability < > ) ) )
23
+ . ToArray ( ) ;
39
24
40
25
[ Theory , MemberData ( nameof ( AllowSupportedCapabilities ) ) ]
41
26
public void Should_AllowSupportedCapabilities ( IJsonRpcHandler handler , object instance )
@@ -51,8 +36,8 @@ public void Should_AllowSupportedCapabilities(IJsonRpcHandler handler, object in
51
36
public static IEnumerable < object [ ] > AllowSupportedCapabilities ( )
52
37
{
53
38
return GetItems ( Capabilities , type => {
54
- var handlerType = GetHandlerType ( type ) ;
55
- var handler = Substitute . For ( new Type [ ] { handlerType } , new object [ 0 ] ) ;
39
+ var handlerTypes = GetHandlerTypes ( type ) ;
40
+ var handler = Substitute . For ( handlerTypes . ToArray ( ) , new object [ 0 ] ) ;
56
41
return new [ ] { handler , Activator . CreateInstance ( typeof ( Supports < > ) . MakeGenericType ( type ) , true , Activator . CreateInstance ( type ) ) } ;
57
42
} ) ;
58
43
}
@@ -99,8 +84,8 @@ public void Should_Invoke_Reduce_Delegate()
99
84
public static IEnumerable < object [ ] > DisallowUnsupportedCapabilities ( )
100
85
{
101
86
return GetItems ( Capabilities , type => {
102
- var handlerType = GetHandlerType ( type ) ;
103
- var handler = Substitute . For ( new Type [ ] { handlerType } , new object [ 0 ] ) ;
87
+ var handlerTypes = GetHandlerTypes ( type ) ;
88
+ var handler = Substitute . For ( handlerTypes . ToArray ( ) , new object [ 0 ] ) ;
104
89
return new [ ] { handler , Activator . CreateInstance ( typeof ( Supports < > ) . MakeGenericType ( type ) , false ) } ;
105
90
} ) ;
106
91
}
@@ -119,8 +104,8 @@ public void Should_DisallowNullSupportedCapabilities(IJsonRpcHandler handler, ob
119
104
public static IEnumerable < object [ ] > DisallowNullSupportsCapabilities ( )
120
105
{
121
106
return GetItems ( Capabilities , type => {
122
- var handlerType = GetHandlerType ( type ) ;
123
- var handler = Substitute . For ( new Type [ ] { handlerType } , new object [ 0 ] ) ;
107
+ var handlerTypes = GetHandlerTypes ( type ) ;
108
+ var handler = Substitute . For ( handlerTypes . ToArray ( ) , new object [ 0 ] ) ;
124
109
return new [ ] { handler , Activator . CreateInstance ( typeof ( Supports < > ) . MakeGenericType ( type ) , true ) } ;
125
110
} ) ;
126
111
}
@@ -150,11 +135,11 @@ private static IEnumerable<object[]> GetItems<T>(IEnumerable<T> types, Func<T, I
150
135
return types . Select ( x => func ( x ) . ToArray ( ) ) ;
151
136
}
152
137
153
- private static Type GetHandlerType ( Type type )
138
+ private static IEnumerable < Type > GetHandlerTypes ( Type type )
154
139
{
155
140
return type . GetTypeInfo ( ) . ImplementedInterfaces
156
- . Single ( x => x . GetTypeInfo ( ) . IsGenericType && x . GetTypeInfo ( ) . GetGenericTypeDefinition ( ) == typeof ( ConnectedCapability < > ) )
157
- . GetTypeInfo ( ) . GetGenericArguments ( ) [ 0 ] ;
141
+ . Where ( x => x . GetTypeInfo ( ) . IsGenericType && x . GetTypeInfo ( ) . GetGenericTypeDefinition ( ) == typeof ( ConnectedCapability < > ) )
142
+ . Select ( x => x . GetTypeInfo ( ) . GetGenericArguments ( ) [ 0 ] ) ;
158
143
}
159
144
}
160
145
}
0 commit comments