|
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;
|
@@ -133,18 +134,38 @@ public static IEnumerable<object[]> DisallowDynamicSupportsCapabilities()
|
133 | 134 | });
|
134 | 135 | }
|
135 | 136 |
|
136 |
| - private static bool HasHandler(ClientCapabilityProvider provider, object instance) |
| 137 | + [Fact] |
| 138 | + public void Should_Handle_Mixed_Capabilities() |
137 | 139 | {
|
138 |
| - return (bool)typeof(ClientCapabilityProviderTests).GetTypeInfo() |
139 |
| - .GetMethod(nameof(GenericHasHandler), BindingFlags.Static | BindingFlags.NonPublic) |
140 |
| - .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(); |
141 | 162 | }
|
142 | 163 |
|
143 |
| - private static bool HasHandler(ClientCapabilityProvider provider, Type type) |
| 164 | + private static bool HasHandler(ClientCapabilityProvider provider, object instance) |
144 | 165 | {
|
145 | 166 | return (bool)typeof(ClientCapabilityProviderTests).GetTypeInfo()
|
146 | 167 | .GetMethod(nameof(GenericHasHandler), BindingFlags.Static | BindingFlags.NonPublic)
|
147 |
| - .MakeGenericMethod(type).Invoke(null, new object[] { provider, null }); |
| 168 | + .MakeGenericMethod(instance.GetType().GetTypeInfo().GetGenericArguments()[0]).Invoke(null, new[] { provider, instance }); |
148 | 169 | }
|
149 | 170 |
|
150 | 171 | private static bool GenericHasHandler<T>(ClientCapabilityProvider provider, Supports<T> supports)
|
|
0 commit comments