示例#1
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);
        }
        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");
        }
示例#3
0
        public void Should_Not_Return_Null()
        {
            // Given
            var handlerDescriptors = Enumerable.Empty <ILspHandlerDescriptor>();
            var handlerMatcher     = new TextDocumentMatcher(_logger);

            // When
            var result = handlerMatcher.FindHandler(1, handlerDescriptors);

            // Then
            result.Should().NotBeNull();
        }
        public void Should_Return_Empty_Descriptor()
        {
            // Given
            var handlerDescriptors = Enumerable.Empty <ILspHandlerDescriptor>();

            var handlerMatcher = new TextDocumentMatcher(_logger, () => new List <ITextDocumentSyncHandler>());

            // When
            var result = handlerMatcher.FindHandler(1, handlerDescriptors);

            // Then
            result.Should().BeEmpty();
        }