Skip to content

Commit be124f2

Browse files
authored
Merge branch 'master' into fix/gh-370
2 parents c31bf3c + 25eb13f commit be124f2

File tree

2 files changed

+33
-2
lines changed

2 files changed

+33
-2
lines changed

test/Lsp.Tests/Matchers/TextDocumentMatcherTests.cs

+31
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,37 @@ public void Should_Return_Empty_Descriptor()
5454
result.Should().BeEmpty();
5555
}
5656

57+
[Fact]
58+
public void Should_Return_Did_Open_Text_Document_Handler_Descriptor_With_No_Registration_Options()
59+
{
60+
// Given
61+
var textDocumentSyncHandler =
62+
TextDocumentSyncHandlerExtensions.With(null, "csharp");
63+
var textDocumentIdentifiers = new TextDocumentIdentifiers();
64+
AutoSubstitute.Provide(textDocumentIdentifiers);
65+
var collection = new SharedHandlerCollection(SupportedCapabilitiesFixture.AlwaysTrue, textDocumentIdentifiers, Substitute.For<IResolverContext>(),
66+
new LspHandlerTypeDescriptorProvider(new [] { typeof(FoundationTests).Assembly, typeof(LanguageServer).Assembly, typeof(LanguageClient).Assembly, typeof(IRegistrationManager).Assembly, typeof(LspRequestRouter).Assembly }))
67+
{ textDocumentSyncHandler };
68+
AutoSubstitute.Provide<IHandlerCollection>(collection);
69+
AutoSubstitute.Provide<IEnumerable<ILspHandlerDescriptor>>(collection);
70+
var handlerMatcher = AutoSubstitute.Resolve<TextDocumentMatcher>();
71+
72+
// When
73+
var result = handlerMatcher.FindHandler(
74+
new DidOpenTextDocumentParams {
75+
TextDocument = new TextDocumentItem {
76+
Uri = new Uri("file:///abc/123/d.cs")
77+
}
78+
},
79+
collection.Where(x => x.Method == TextDocumentNames.DidOpen)
80+
);
81+
82+
// Then
83+
var lspHandlerDescriptors = result as ILspHandlerDescriptor[] ?? result.ToArray();
84+
lspHandlerDescriptors.Should().NotBeNullOrEmpty();
85+
lspHandlerDescriptors.Should().Contain(x => x.Method == TextDocumentNames.DidOpen);
86+
}
87+
5788
[Fact]
5889
public void Should_Return_Did_Open_Text_Document_Handler_Descriptor()
5990
{

test/Lsp.Tests/TextDocumentSyncHandlerExtensions.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@ namespace Lsp.Tests
88
{
99
internal static class TextDocumentSyncHandlerExtensions
1010
{
11-
public static ITextDocumentSyncHandler With(DocumentSelector documentSelector, string language) =>
11+
public static ITextDocumentSyncHandler With(DocumentSelector? documentSelector, string language) =>
1212
Substitute.For<ITextDocumentSyncHandler>().With(documentSelector, language);
1313

14-
public static ITextDocumentSyncHandler With(this ITextDocumentSyncHandler handler, DocumentSelector documentSelector, string language)
14+
public static ITextDocumentSyncHandler With(this ITextDocumentSyncHandler handler, DocumentSelector? documentSelector, string language)
1515
{
1616
( (IDidChangeTextDocumentHandler) handler ).GetRegistrationOptions(Arg.Any<SynchronizationCapability>(), Arg.Any<ClientCapabilities>()).Returns(new TextDocumentChangeRegistrationOptions() { DocumentSelector = documentSelector });
1717
( (IDidOpenTextDocumentHandler) handler ).GetRegistrationOptions(Arg.Any<SynchronizationCapability>(), Arg.Any<ClientCapabilities>()).Returns(new TextDocumentOpenRegistrationOptions() { DocumentSelector = documentSelector });

0 commit comments

Comments
 (0)