コード例 #1
0
        public void Should_Return_Did_Open_Text_Document_Handler_Descriptor_With_Sepcial_Character()
        {
            // Given
            var textDocumentSyncHandler =
                TextDocumentSyncHandlerExtensions.With(DocumentSelector.ForPattern("**/*.cshtml"));
            var collection = new HandlerCollection(SupportedCapabilitiesFixture.AlwaysTrue)
            {
                textDocumentSyncHandler
            };

            AutoSubstitute.Provide <IHandlerCollection>(collection);
            AutoSubstitute.Provide <IEnumerable <ILspHandlerDescriptor> >(collection);
            var handlerMatcher = AutoSubstitute.Resolve <TextDocumentMatcher>();

            // When
            var result = handlerMatcher.FindHandler(new DidOpenTextDocumentParams()
            {
                TextDocument = new TextDocumentItem {
                    Uri = new Uri("file://c:/users/myøasdf/d.cshtml")
                }
            },
                                                    collection.Where(x => x.Method == DocumentNames.DidOpen));

            // Then
            result.Should().NotBeNullOrEmpty();
            result.Should().Contain(x => x.Method == DocumentNames.DidOpen);
        }
コード例 #2
0
        public void Should_Return_Did_Change_Text_Document_Descriptor()
        {
            // Given
            var textDocumentSyncHandler =
                TextDocumentSyncHandlerExtensions.With(DocumentSelector.ForPattern("**/*.cs"));
            var collection = new HandlerCollection(SupportedCapabilitiesFixture.AlwaysTrue)
            {
                textDocumentSyncHandler
            };

            AutoSubstitute.Provide <IHandlerCollection>(collection);
            var handlerMatcher = AutoSubstitute.Resolve <TextDocumentMatcher>();

            // When
            var result = handlerMatcher.FindHandler(new DidChangeTextDocumentParams()
            {
                TextDocument = new VersionedTextDocumentIdentifier {
                    Uri = new Uri("file:///abc/123/d.cs"), Version = 1
                }
            },
                                                    collection.Where(x => x.Method == DocumentNames.DidChange));

            // Then
            result.Should().NotBeNullOrEmpty();
            result.Should().Contain(x => x.Method == DocumentNames.DidChange);
        }
        public void Should_Return_Did_Open_Text_Document_Handler_Descriptor_With_Sepcial_Character()
        {
            // Given
            var textDocumentSyncHandler =
                TextDocumentSyncHandlerExtensions.With(DocumentSelector.ForPattern("**/*.cshtml"), "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>();

            // When
            var result = handlerMatcher.FindHandler(
                new DidOpenTextDocumentParams {
                TextDocument = new TextDocumentItem {
                    Uri = new Uri("file://c:/users/myøasdf/d.cshtml")
                }
            },
                collection.Where(x => x.Method == TextDocumentNames.DidOpen)
                );

            // Then
            result.Should().NotBeNullOrEmpty();
            result.Should().Contain(x => x.Method == TextDocumentNames.DidOpen);
        }
コード例 #4
0
        public void Should_Return_Did_Change_Text_Document_Descriptor()
        {
            // Given
            var handlerMatcher          = new TextDocumentMatcher(_logger);
            var textDocumentSyncHandler =
                TextDocumentSyncHandlerExtensions.With(DocumentSelector.ForPattern("**/*.cs"));

            // When
            var result = handlerMatcher.FindHandler(new DidChangeTextDocumentParams()
            {
                TextDocument = new VersionedTextDocumentIdentifier {
                    Uri = new Uri("file:///abc/123/d.cs"), Version = 1
                }
            },
                                                    new List <HandlerDescriptor>()
            {
                new HandlerDescriptor(DocumentNames.DidChange,
                                      "Key",
                                      textDocumentSyncHandler,
                                      textDocumentSyncHandler.GetType(),
                                      typeof(DidOpenTextDocumentParams),
                                      typeof(TextDocumentRegistrationOptions),
                                      typeof(TextDocumentClientCapabilities),
                                      () => { })
            });

            // Then
            result.Should().NotBeNullOrEmpty();
            result.Should().Contain(x => x.Method == DocumentNames.DidChange);
        }
コード例 #5
0
        public void Should_Return_Did_Close_Text_Document_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>();

            // When
            var result = handlerMatcher.FindHandler(
                new DidCloseTextDocumentParams {
                TextDocument = new VersionedTextDocumentIdentifier {
                    Uri = new Uri("file:///abc/123/d.cs"), Version = 1
                }
            },
                collection.Where(x => x.Method == TextDocumentNames.DidClose)
                );

            // Then
            var lspHandlerDescriptors = result as ILspHandlerDescriptor[] ?? result.ToArray();

            lspHandlerDescriptors.Should().NotBeNullOrEmpty();
            lspHandlerDescriptors.Should().Contain(x => x.Method == TextDocumentNames.DidClose);
        }
コード例 #6
0
        public void Should_Return_Did_Open_Text_Document_Handler_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>();

            // When
            var result = handlerMatcher.FindHandler(
                new DidOpenTextDocumentParams {
                TextDocument = new TextDocumentItem {
                    Uri = new Uri("file:///abc/123/d.cs")
                }
            },
                collection.Where(x => x.Method == TextDocumentNames.DidOpen)
                );

            // Then
            result.Should().NotBeNullOrEmpty();
            result.Should().Contain(x => x.Method == TextDocumentNames.DidOpen);
        }
        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");
        }
コード例 #8
0
        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]");
        }
コード例 #9
0
        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]");
        }
コード例 #10
0
        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);
        }
コード例 #11
0
        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);
        }