Skip to content

Commit e2868ae

Browse files
Added addiitional mixed text to prove through it working with multiple items
1 parent 3ddab5f commit e2868ae

File tree

1 file changed

+27
-6
lines changed

1 file changed

+27
-6
lines changed

test/Lsp.Tests/ClientCapabilityProviderTests.cs

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
using OmniSharp.Extensions.LanguageServer.Protocol;
1010
using OmniSharp.Extensions.LanguageServer.Protocol.Client.Capabilities;
1111
using OmniSharp.Extensions.LanguageServer.Protocol.Models;
12+
using OmniSharp.Extensions.LanguageServer.Protocol.Server;
1213
using OmniSharp.Extensions.LanguageServer.Protocol.Server.Capabilities;
1314
using OmniSharp.Extensions.LanguageServer.Server;
1415
using Xunit;
@@ -133,18 +134,38 @@ public static IEnumerable<object[]> DisallowDynamicSupportsCapabilities()
133134
});
134135
}
135136

136-
private static bool HasHandler(ClientCapabilityProvider provider, object instance)
137+
[Fact]
138+
public void Should_Handle_Mixed_Capabilities()
137139
{
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();
141162
}
142163

143-
private static bool HasHandler(ClientCapabilityProvider provider, Type type)
164+
private static bool HasHandler(ClientCapabilityProvider provider, object instance)
144165
{
145166
return (bool)typeof(ClientCapabilityProviderTests).GetTypeInfo()
146167
.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 });
148169
}
149170

150171
private static bool GenericHasHandler<T>(ClientCapabilityProvider provider, Supports<T> supports)

0 commit comments

Comments
 (0)