public void Should_Return_Code_Lens_Descriptor() { // Given var textDocumentSyncHandler = TextDocumentSyncHandlerExtensions.With(DocumentSelector.ForPattern("**/*.cs")); var handlerMatcher = new TextDocumentMatcher(_logger, () => new[] { textDocumentSyncHandler }); var codeLensHandler = Substitute.For(new Type[] { typeof(ICodeLensHandler), typeof(ICodeLensResolveHandler) }, new object[0]) as ICodeLensHandler; codeLensHandler.GetRegistrationOptions() .Returns(new CodeLensRegistrationOptions() { DocumentSelector = new DocumentSelector(new DocumentFilter { Pattern = "**/*.cs" }) }); var codeLensHandler2 = Substitute.For(new Type[] { typeof(ICodeLensHandler), typeof(ICodeLensResolveHandler) }, new object[0]) as ICodeLensHandler; codeLensHandler2.GetRegistrationOptions() .Returns(new CodeLensRegistrationOptions() { DocumentSelector = new DocumentSelector(new DocumentFilter { Pattern = "**/*.cake" }) }); // When var result = handlerMatcher.FindHandler(new DidCloseTextDocumentParams() { TextDocument = new VersionedTextDocumentIdentifier { Uri = new Uri("file:///abc/123/d.cs"), Version = 1 } }, new List <HandlerDescriptor>() { new HandlerDescriptor(DocumentNames.CodeLens, "Key2", codeLensHandler2, codeLensHandler2.GetType(), typeof(CodeLensParams), typeof(CodeLensRegistrationOptions), typeof(CodeLensCapability), () => { }), new HandlerDescriptor(DocumentNames.CodeLens, "Key", codeLensHandler, codeLensHandler.GetType(), typeof(CodeLensParams), typeof(CodeLensRegistrationOptions), typeof(CodeLensCapability), () => { }), }); // Then result.Should().NotBeNullOrEmpty(); result.Should().Contain(x => x.Method == DocumentNames.CodeLens); result.Should().Contain(x => ((HandlerDescriptor)x).Key == "Key"); }
public void Should_Return_Code_Lens_Descriptor() { // Given var textDocumentSyncHandler = TextDocumentSyncHandlerExtensions.With(DocumentSelector.ForPattern("**/*.cs"), "csharp"); var textDocumentIdentifiers = new TextDocumentIdentifiers(); AutoSubstitute.Provide(textDocumentIdentifiers); var collection = new SharedHandlerCollection(SupportedCapabilitiesFixture.AlwaysTrue, textDocumentIdentifiers, Substitute.For <IResolverContext>(), new LspHandlerTypeDescriptorProvider(new [] { typeof(FoundationTests).Assembly, typeof(LanguageServer).Assembly, typeof(LanguageClient).Assembly, typeof(IRegistrationManager).Assembly, typeof(LspRequestRouter).Assembly })) { textDocumentSyncHandler }; AutoSubstitute.Provide <IHandlerCollection>(collection); AutoSubstitute.Provide <IEnumerable <ILspHandlerDescriptor> >(collection); var handlerMatcher = AutoSubstitute.Resolve <TextDocumentMatcher>(); var codeLensHandler = (ICodeLensHandler)Substitute.For(new[] { typeof(ICodeLensHandler), typeof(ICodeLensResolveHandler) }, new object[0]); codeLensHandler.GetRegistrationOptions(Arg.Any <CodeLensCapability>(), Arg.Any <ClientCapabilities>()) .Returns( new CodeLensRegistrationOptions { DocumentSelector = new DocumentSelector(new DocumentFilter { Pattern = "**/*.cs" }) } ); var codeLensHandler2 = (ICodeLensHandler)Substitute.For(new[] { typeof(ICodeLensHandler), typeof(ICodeLensResolveHandler) }, new object[0]); codeLensHandler2.GetRegistrationOptions(Arg.Any <CodeLensCapability>(), Arg.Any <ClientCapabilities>()) .Returns( new CodeLensRegistrationOptions { DocumentSelector = new DocumentSelector(new DocumentFilter { Pattern = "**/*.cake" }) } ); collection.Add(codeLensHandler, codeLensHandler2); collection.Initialize(); // When var result = handlerMatcher.FindHandler( new CodeLensParams { TextDocument = new OptionalVersionedTextDocumentIdentifier { Uri = new Uri("file:///abc/123/d.cs"), Version = 1 } }, collection.Where(x => x.Method == TextDocumentNames.CodeLens) ); // Then var lspHandlerDescriptors = result as ILspHandlerDescriptor[] ?? result.ToArray(); lspHandlerDescriptors.Should().NotBeNullOrEmpty(); lspHandlerDescriptors.Should().Contain(x => x.Method == TextDocumentNames.CodeLens); lspHandlerDescriptors.Should().Contain(x => ((LspHandlerDescriptor)x).Key == "[**/*.cs]"); }
public void Should_Return_Code_Lens_Descriptor() { // Given var textDocumentSyncHandler = TextDocumentSyncHandlerExtensions.With(DocumentSelector.ForPattern("**/*.cs"), "csharp"); var textDocumentIdentifiers = new TextDocumentIdentifiers(); AutoSubstitute.Provide(textDocumentIdentifiers); var collection = new SharedHandlerCollection(SupportedCapabilitiesFixture.AlwaysTrue, textDocumentIdentifiers, new ServiceCollection().BuildServiceProvider()) { textDocumentSyncHandler }; AutoSubstitute.Provide <IHandlerCollection>(collection); AutoSubstitute.Provide <IEnumerable <ILspHandlerDescriptor> >(collection); var handlerMatcher = AutoSubstitute.Resolve <TextDocumentMatcher>(); var codeLensHandler = Substitute.For(new[] { typeof(ICodeLensHandler), typeof(ICodeLensResolveHandler) }, new object[0]) as ICodeLensHandler; codeLensHandler.GetRegistrationOptions() .Returns( new CodeLensRegistrationOptions { DocumentSelector = new DocumentSelector(new DocumentFilter { Pattern = "**/*.cs" }) } ); var codeLensHandler2 = Substitute.For(new[] { typeof(ICodeLensHandler), typeof(ICodeLensResolveHandler) }, new object[0]) as ICodeLensHandler; codeLensHandler2.GetRegistrationOptions() .Returns( new CodeLensRegistrationOptions { DocumentSelector = new DocumentSelector(new DocumentFilter { Pattern = "**/*.cake" }) } ); collection.Add(codeLensHandler, codeLensHandler2); // When var result = handlerMatcher.FindHandler( new CodeLensParams { TextDocument = new VersionedTextDocumentIdentifier { Uri = new Uri("file:///abc/123/d.cs"), Version = 1 } }, collection.Where(x => x.Method == TextDocumentNames.CodeLens) ); // Then result.Should().NotBeNullOrEmpty(); result.Should().Contain(x => x.Method == TextDocumentNames.CodeLens); result.Should().Contain(x => ((LspHandlerDescriptor)x).Key == "[**/*.cs]"); }
public void Should_Return_Did_Folding_Range_handler() { // Given var textDocumentSyncHandler = TextDocumentSyncHandlerExtensions.With(DocumentSelector.ForPattern("**/*.ps*1"), "powershell"); var handler = Substitute.For <IFoldingRangeHandler>(); handler.GetRegistrationOptions().Returns( new FoldingRangeRegistrationOptions { DocumentSelector = new DocumentSelector(new DocumentFilter { Pattern = "**/*.ps*1" }) } ); var textDocumentIdentifiers = new TextDocumentIdentifiers(); AutoSubstitute.Provide(textDocumentIdentifiers); var collection = new SharedHandlerCollection(SupportedCapabilitiesFixture.AlwaysTrue, textDocumentIdentifiers, Substitute.For <IResolverContext>(), new LspHandlerTypeDescriptorProvider(new [] { typeof(FoundationTests).Assembly, typeof(LanguageServer).Assembly, typeof(LanguageClient).Assembly, typeof(IRegistrationManager).Assembly, typeof(LspRequestRouter).Assembly })) { textDocumentSyncHandler, handler }; AutoSubstitute.Provide <IHandlerCollection>(collection); AutoSubstitute.Provide <IEnumerable <ILspHandlerDescriptor> >(collection); var handlerMatcher = AutoSubstitute.Resolve <TextDocumentMatcher>(); // When var result = handlerMatcher.FindHandler( new FoldingRangeRequestParam { TextDocument = new TextDocumentItem { Uri = new Uri("file:///abc/123/d.ps1") } }, collection.Where(x => x.Method == TextDocumentNames.DidOpen) ); // Then var lspHandlerDescriptors = result as ILspHandlerDescriptor[] ?? result.ToArray(); lspHandlerDescriptors.Should().NotBeNullOrEmpty(); lspHandlerDescriptors.Should().Contain(x => x.Method == TextDocumentNames.DidOpen); }
public void Should_Return_Did_Folding_Range_handler() { // Given var textDocumentSyncHandler = TextDocumentSyncHandlerExtensions.With(DocumentSelector.ForPattern("**/*.ps*1"), "powershell"); var handler = Substitute.For <IFoldingRangeHandler>(); handler.GetRegistrationOptions().Returns( new FoldingRangeRegistrationOptions { DocumentSelector = new DocumentSelector(new DocumentFilter { Pattern = "**/*.ps*1" }) } ); var textDocumentIdentifiers = new TextDocumentIdentifiers(); AutoSubstitute.Provide(textDocumentIdentifiers); var collection = new SharedHandlerCollection(SupportedCapabilitiesFixture.AlwaysTrue, textDocumentIdentifiers, new ServiceCollection().BuildServiceProvider()) { textDocumentSyncHandler, handler }; AutoSubstitute.Provide <IHandlerCollection>(collection); AutoSubstitute.Provide <IEnumerable <ILspHandlerDescriptor> >(collection); var handlerMatcher = AutoSubstitute.Resolve <TextDocumentMatcher>(); // When var result = handlerMatcher.FindHandler( new FoldingRangeRequestParam { TextDocument = new TextDocumentItem { Uri = new Uri("file:///abc/123/d.ps1") } }, collection.Where(x => x.Method == TextDocumentNames.DidOpen) ); // Then result.Should().NotBeNullOrEmpty(); result.Should().Contain(x => x.Method == TextDocumentNames.DidOpen); }