9
9
using OmniSharp . Extensions . LanguageServer . Protocol ;
10
10
using OmniSharp . Extensions . LanguageServer . Protocol . Client . Capabilities ;
11
11
using OmniSharp . Extensions . LanguageServer . Protocol . Models ;
12
+ using OmniSharp . Extensions . LanguageServer . Protocol . Server ;
12
13
using OmniSharp . Extensions . LanguageServer . Protocol . Server . Capabilities ;
13
14
using OmniSharp . Extensions . LanguageServer . Server ;
14
15
using Xunit ;
@@ -42,15 +43,24 @@ public static IEnumerable<object[]> AllowSupportedCapabilities()
42
43
} ) ;
43
44
}
44
45
45
- [ Theory , MemberData ( nameof ( DisallowUnsupportedCapabilities ) ) ]
46
- public void Should_DisallowUnsupportedCapabilities ( IJsonRpcHandler handler , object instance )
46
+ [ Theory , MemberData ( nameof ( AllowUnsupportedCapabilities ) ) ]
47
+ public void Should_AllowUnsupportedCapabilities ( IJsonRpcHandler handler , object instance )
47
48
{
48
49
var textDocumentSyncHandler = TextDocumentSyncHandlerExtensions . With ( DocumentSelector . ForPattern ( "**/*.cs" ) ) ;
49
50
50
51
var collection = new HandlerCollection ( SupportedCapabilitiesFixture . AlwaysTrue ) { textDocumentSyncHandler , handler } ;
51
52
var provider = new ClientCapabilityProvider ( collection ) ;
52
53
53
- HasHandler ( provider , instance ) . Should ( ) . BeFalse ( ) ;
54
+ HasHandler ( provider , instance ) . Should ( ) . BeTrue ( ) ;
55
+ }
56
+
57
+ public static IEnumerable < object [ ] > AllowUnsupportedCapabilities ( )
58
+ {
59
+ return GetItems ( Capabilities , type => {
60
+ var handlerTypes = GetHandlerTypes ( type ) ;
61
+ var handler = Substitute . For ( handlerTypes . ToArray ( ) , new object [ 0 ] ) ;
62
+ return new [ ] { handler , Activator . CreateInstance ( typeof ( Supports < > ) . MakeGenericType ( type ) , false ) } ;
63
+ } ) ;
54
64
}
55
65
56
66
[ Fact ]
@@ -81,17 +91,29 @@ public void Should_Invoke_Reduce_Delegate()
81
91
stub . Received ( ) . Invoke ( Arg . Any < IEnumerable < IExecuteCommandOptions > > ( ) ) ;
82
92
}
83
93
84
- public static IEnumerable < object [ ] > DisallowUnsupportedCapabilities ( )
94
+ [ Theory , MemberData ( nameof ( AllowNullSupportsCapabilities ) ) ]
95
+ public void Should_AllowNullSupportedCapabilities ( IJsonRpcHandler handler , object instance )
96
+ {
97
+ var textDocumentSyncHandler = TextDocumentSyncHandlerExtensions . With ( DocumentSelector . ForPattern ( "**/*.cs" ) ) ;
98
+
99
+ var collection = new HandlerCollection ( SupportedCapabilitiesFixture . AlwaysTrue ) { textDocumentSyncHandler , handler } ;
100
+ var provider = new ClientCapabilityProvider ( collection ) ;
101
+
102
+ HasHandler ( provider , instance ) . Should ( ) . BeTrue ( ) ;
103
+ }
104
+
105
+ public static IEnumerable < object [ ] > AllowNullSupportsCapabilities ( )
85
106
{
86
107
return GetItems ( Capabilities , type => {
87
108
var handlerTypes = GetHandlerTypes ( type ) ;
88
109
var handler = Substitute . For ( handlerTypes . ToArray ( ) , new object [ 0 ] ) ;
89
- return new [ ] { handler , Activator . CreateInstance ( typeof ( Supports < > ) . MakeGenericType ( type ) , false ) } ;
110
+ return new [ ] { handler , Activator . CreateInstance ( typeof ( Supports < > ) . MakeGenericType ( type ) , true ) } ;
90
111
} ) ;
91
112
}
92
113
93
- [ Theory , MemberData ( nameof ( DisallowNullSupportsCapabilities ) ) ]
94
- public void Should_DisallowNullSupportedCapabilities ( IJsonRpcHandler handler , object instance )
114
+
115
+ [ Theory , MemberData ( nameof ( DisallowDynamicSupportsCapabilities ) ) ]
116
+ public void Should_DisallowDynamicSupportedCapabilities ( IJsonRpcHandler handler , object instance )
95
117
{
96
118
var textDocumentSyncHandler = TextDocumentSyncHandlerExtensions . With ( DocumentSelector . ForPattern ( "**/*.cs" ) ) ;
97
119
@@ -101,27 +123,49 @@ public void Should_DisallowNullSupportedCapabilities(IJsonRpcHandler handler, ob
101
123
HasHandler ( provider , instance ) . Should ( ) . BeFalse ( ) ;
102
124
}
103
125
104
- public static IEnumerable < object [ ] > DisallowNullSupportsCapabilities ( )
126
+ public static IEnumerable < object [ ] > DisallowDynamicSupportsCapabilities ( )
105
127
{
106
128
return GetItems ( Capabilities , type => {
107
129
var handlerTypes = GetHandlerTypes ( type ) ;
108
130
var handler = Substitute . For ( handlerTypes . ToArray ( ) , new object [ 0 ] ) ;
109
- return new [ ] { handler , Activator . CreateInstance ( typeof ( Supports < > ) . MakeGenericType ( type ) , true ) } ;
131
+ var capability = Activator . CreateInstance ( type ) ;
132
+ if ( capability is DynamicCapability dyn ) dyn . DynamicRegistration = true ;
133
+ return new [ ] { handler , Activator . CreateInstance ( typeof ( Supports < > ) . MakeGenericType ( type ) , true , capability ) } ;
110
134
} ) ;
111
135
}
112
136
113
- private static bool HasHandler ( ClientCapabilityProvider provider , object instance )
137
+ [ Fact ]
138
+ public void Should_Handle_Mixed_Capabilities ( )
114
139
{
115
- return ( bool ) typeof ( ClientCapabilityProviderTests ) . GetTypeInfo ( )
116
- . GetMethod ( nameof ( GenericHasHandler ) , BindingFlags . Static | BindingFlags . NonPublic )
117
- . MakeGenericMethod ( instance . GetType ( ) . GetTypeInfo ( ) . GetGenericArguments ( ) [ 0 ] ) . Invoke ( null , new [ ] { provider , instance } ) ;
140
+ var textDocumentSyncHandler = TextDocumentSyncHandlerExtensions . With ( DocumentSelector . ForPattern ( "**/*.cs" ) ) ;
141
+
142
+ var codeActionHandler = Substitute . For < ICodeActionHandler > ( ) ;
143
+ var definitionHandler = Substitute . For < IDefinitionHandler > ( ) ;
144
+ var typeDefinitionHandler = Substitute . For < ITypeDefinitionHandler > ( ) ;
145
+
146
+ var collection = new HandlerCollection ( SupportedCapabilitiesFixture . AlwaysTrue ) { textDocumentSyncHandler , codeActionHandler , definitionHandler , typeDefinitionHandler } ;
147
+ var provider = new ClientCapabilityProvider ( collection ) ;
148
+ var capabilities = new ClientCapabilities ( ) {
149
+ TextDocument = new TextDocumentClientCapabilities ( ) {
150
+ CodeAction = new Supports < CodeActionCapability > ( true , new CodeActionCapability ( ) {
151
+ DynamicRegistration = false ,
152
+ } ) ,
153
+ TypeDefinition = new Supports < TypeDefinitionCapability > ( true , new TypeDefinitionCapability ( ) {
154
+ DynamicRegistration = true ,
155
+ } )
156
+ }
157
+ } ;
158
+
159
+ provider . GetStaticOptions ( capabilities . TextDocument . CodeAction ) . Get < ICodeActionOptions , CodeActionOptions > ( CodeActionOptions . Of ) . Should ( ) . NotBeNull ( ) ;
160
+ provider . HasStaticHandler ( capabilities . TextDocument . Definition ) . Should ( ) . BeTrue ( ) ;
161
+ provider . HasStaticHandler ( capabilities . TextDocument . TypeDefinition ) . Should ( ) . BeFalse ( ) ;
118
162
}
119
163
120
- private static bool HasHandler ( ClientCapabilityProvider provider , Type type )
164
+ private static bool HasHandler ( ClientCapabilityProvider provider , object instance )
121
165
{
122
166
return ( bool ) typeof ( ClientCapabilityProviderTests ) . GetTypeInfo ( )
123
167
. GetMethod ( nameof ( GenericHasHandler ) , BindingFlags . Static | BindingFlags . NonPublic )
124
- . MakeGenericMethod ( type ) . Invoke ( null , new object [ ] { provider , null } ) ;
168
+ . MakeGenericMethod ( instance . GetType ( ) . GetTypeInfo ( ) . GetGenericArguments ( ) [ 0 ] ) . Invoke ( null , new [ ] { provider , instance } ) ;
125
169
}
126
170
127
171
private static bool GenericHasHandler < T > ( ClientCapabilityProvider provider , Supports < T > supports )
0 commit comments