Пример #1
0
        public RazorCompletionEndpointTest()
        {
            // Working around strong naming restriction.
            var tagHelperFactsService      = new DefaultTagHelperFactsService();
            var tagHelperCompletionService = new LanguageServerTagHelperCompletionService(tagHelperFactsService);
            var completionProviders        = new RazorCompletionItemProvider[]
            {
                new DirectiveCompletionItemProvider(),
                new DirectiveAttributeCompletionItemProvider(tagHelperFactsService),
                new DirectiveAttributeParameterCompletionItemProvider(tagHelperFactsService),
                new TagHelperCompletionProvider(tagHelperCompletionService, new DefaultHtmlFactsService(), tagHelperFactsService)
            };

            CompletionFactsService = new DefaultRazorCompletionFactsService(completionProviders);
            CompletionListCache    = new CompletionListCache();
            ClientCapabilities     = new VSInternalClientCapabilities()
            {
                TextDocument = new TextDocumentClientCapabilities()
                {
                    Completion = new VSInternalCompletionSetting()
                    {
                        CompletionItemKind = new CompletionItemKindSetting()
                        {
                            ValueSet = new[] { CompletionItemKind.TagHelper }
                        },
                        CompletionList = new VSInternalCompletionListSetting()
                        {
                            CommitCharacters = true,
                            Data             = true,
                        }
                    }
                }
            };
        }
        public CompletionListSerializationBenchmark()
        {
            var tagHelperFactsService       = new DefaultTagHelperFactsService();
            var completionService           = new DefaultTagHelperCompletionService(tagHelperFactsService);
            var htmlFactsService            = new DefaultHtmlFactsService();
            var tagHelperCompletionProvider = new TagHelperCompletionProvider(completionService, htmlFactsService, tagHelperFactsService);

            var documentContent = "<";
            var queryIndex      = 1;

            CompletionList        = GenerateCompletionList(documentContent, queryIndex, tagHelperCompletionProvider);
            _completionListBuffer = GenerateBuffer(CompletionList);

            Serializer.Instance.JsonSerializer.Converters.Add(TagHelperDescriptorJsonConverter.Instance);
        }
 public RazorCompletionEndpointTest()
 {
     // Working around strong naming restriction.
     var tagHelperFactsService = new DefaultTagHelperFactsService();
     var completionProviders = new RazorCompletionItemProvider[]
     {
         new DirectiveCompletionItemProvider(),
         new DirectiveAttributeCompletionItemProvider(tagHelperFactsService),
         new DirectiveAttributeParameterCompletionItemProvider(tagHelperFactsService),
     };
     CompletionFactsService = new DefaultRazorCompletionFactsService(completionProviders);
     TagHelperCompletionService = Mock.Of<TagHelperCompletionService>(
         service => service.GetCompletionsAt(It.IsAny<SourceSpan>(), It.IsAny<RazorCodeDocument>()) == Array.Empty<CompletionItem>());
     TagHelperDescriptionFactory = Mock.Of<TagHelperDescriptionFactory>();
     EmptyDocumentResolver = Mock.Of<DocumentResolver>();
 }
Пример #4
0
        public CompletionListSerializationBenchmark()
        {
            var tagHelperFactsService       = new DefaultTagHelperFactsService();
            var completionService           = new DefaultTagHelperCompletionService(tagHelperFactsService);
            var htmlFactsService            = new DefaultHtmlFactsService();
            var tagHelperCompletionProvider = new TagHelperCompletionProvider(completionService, htmlFactsService, tagHelperFactsService);

            var documentContent = "<";
            var queryIndex      = 1;

            CompletionList        = GenerateCompletionList(documentContent, queryIndex, tagHelperCompletionProvider);
            _completionListBuffer = GenerateBuffer(CompletionList);

            Serializer = new LspSerializer();
            Serializer.RegisterRazorConverters();
        }
        public void GetNearestAncestorTagInfo_TagHelperElement()
        {
            // Arrange
            var codeDocument = CreateCodeDocument($"@addTagHelper *, TestAssembly{Environment.NewLine}<test1><test2></test2></test1>", DefaultTagHelpers);
            var sourceSpan   = new SourceSpan(37 + Environment.NewLine.Length, 0);
            var syntaxTree   = codeDocument.GetSyntaxTree();
            var owner        = syntaxTree.Root.LocateOwner(new SourceChange(sourceSpan, string.Empty));
            var element      = owner.FirstAncestorOrSelf <MarkupTagHelperElementSyntax>();
            var service      = new DefaultTagHelperFactsService();

            // Act
            var(ancestorName, ancestorIsTagHelper) = service.GetNearestAncestorTagInfo(element.Ancestors());

            // Assert
            Assert.Equal("test1", ancestorName);
            Assert.True(ancestorIsTagHelper);
        }
        public RazorCompletionEndpointTest()
        {
            // Working around strong naming restriction.
            var tagHelperFactsService      = new DefaultTagHelperFactsService();
            var tagHelperCompletionService = new DefaultTagHelperCompletionService(tagHelperFactsService);
            var completionProviders        = new RazorCompletionItemProvider[]
            {
                new DirectiveCompletionItemProvider(),
                new DirectiveAttributeCompletionItemProvider(tagHelperFactsService),
                new DirectiveAttributeParameterCompletionItemProvider(tagHelperFactsService),
                new TagHelperCompletionProvider(tagHelperCompletionService, new DefaultHtmlFactsService(), tagHelperFactsService)
            };

            CompletionFactsService      = new DefaultRazorCompletionFactsService(completionProviders);
            TagHelperDescriptionFactory = Mock.Of <TagHelperDescriptionFactory>();
            EmptyDocumentResolver       = Mock.Of <DocumentResolver>();
        }
        public TagHelperServiceTestBase()
        {
            var builder1 = TagHelperDescriptorBuilder.Create("Test1TagHelper", "TestAssembly");

            builder1.TagMatchingRule(rule => rule.TagName = "test1");
            builder1.SetTypeName("Test1TagHelper");
            builder1.BindAttribute(attribute =>
            {
                attribute.Name = "bool-val";
                attribute.SetPropertyName("BoolVal");
                attribute.TypeName = typeof(bool).FullName;
            });
            builder1.BindAttribute(attribute =>
            {
                attribute.Name = "int-val";
                attribute.SetPropertyName("IntVal");
                attribute.TypeName = typeof(int).FullName;
            });

            var builder2 = TagHelperDescriptorBuilder.Create("Test2TagHelper", "TestAssembly");

            builder2.TagMatchingRule(rule => rule.TagName = "test2");
            builder2.SetTypeName("Test2TagHelper");
            builder2.BindAttribute(attribute =>
            {
                attribute.Name = "bool-val";
                attribute.SetPropertyName("BoolVal");
                attribute.TypeName = typeof(bool).FullName;
            });
            builder2.BindAttribute(attribute =>
            {
                attribute.Name = "int-val";
                attribute.SetPropertyName("IntVal");
                attribute.TypeName = typeof(int).FullName;
            });

            var builder3 = TagHelperDescriptorBuilder.Create(ComponentMetadata.Component.TagHelperKind, "Component1TagHelper", "TestAssembly");

            builder3.TagMatchingRule(rule => rule.TagName = "Component1");
            builder3.SetTypeName("Component1");
            builder3.Metadata[ComponentMetadata.Component.NameMatchKey] = ComponentMetadata.Component.FullyQualifiedNameMatch;
            builder3.BindAttribute(attribute =>
            {
                attribute.Name = "bool-val";
                attribute.SetPropertyName("BoolVal");
                attribute.TypeName = typeof(bool).FullName;
            });
            builder3.BindAttribute(attribute =>
            {
                attribute.Name = "int-val";
                attribute.SetPropertyName("IntVal");
                attribute.TypeName = typeof(int).FullName;
            });

            var directiveAttribute1 = TagHelperDescriptorBuilder.Create(ComponentMetadata.Component.TagHelperKind, "TestDirectiveAttribute", "TestAssembly");

            directiveAttribute1.TagMatchingRule(rule =>
            {
                rule.TagName = "*";
                rule.RequireAttributeDescriptor(b =>
                {
                    b.Name = "@test";
                    b.NameComparisonMode = RequiredAttributeDescriptor.NameComparisonMode.PrefixMatch;
                });
            });
            directiveAttribute1.TagMatchingRule(rule =>
            {
                rule.TagName = "*";
                rule.RequireAttributeDescriptor(b =>
                {
                    b.Name = "@test";
                    b.NameComparisonMode = RequiredAttributeDescriptor.NameComparisonMode.FullMatch;
                });
            });
            directiveAttribute1.BindAttribute(attribute =>
            {
                attribute.Metadata[ComponentMetadata.Common.DirectiveAttribute] = bool.TrueString;
                attribute.Name = "@test";
                attribute.SetPropertyName("Test");
                attribute.TypeName = typeof(string).FullName;

                attribute.BindAttributeParameter(parameter =>
                {
                    parameter.Name     = "something";
                    parameter.TypeName = typeof(string).FullName;

                    parameter.SetPropertyName("Something");
                });
            });
            directiveAttribute1.Metadata[TagHelperMetadata.Common.ClassifyAttributesOnly] = bool.TrueString;
            directiveAttribute1.Metadata[ComponentMetadata.Component.NameMatchKey]        = ComponentMetadata.Component.FullyQualifiedNameMatch;
            directiveAttribute1.SetTypeName("TestDirectiveAttribute");

            var directiveAttribute2 = TagHelperDescriptorBuilder.Create(ComponentMetadata.Component.TagHelperKind, "MinimizedDirectiveAttribute", "TestAssembly");

            directiveAttribute2.TagMatchingRule(rule =>
            {
                rule.TagName = "*";
                rule.RequireAttributeDescriptor(b =>
                {
                    b.Name = "@minimized";
                    b.NameComparisonMode = RequiredAttributeDescriptor.NameComparisonMode.PrefixMatch;
                });
            });
            directiveAttribute2.TagMatchingRule(rule =>
            {
                rule.TagName = "*";
                rule.RequireAttributeDescriptor(b =>
                {
                    b.Name = "@minimized";
                    b.NameComparisonMode = RequiredAttributeDescriptor.NameComparisonMode.FullMatch;
                });
            });
            directiveAttribute2.BindAttribute(attribute =>
            {
                attribute.Metadata[ComponentMetadata.Common.DirectiveAttribute] = bool.TrueString;
                attribute.Name = "@minimized";
                attribute.SetPropertyName("Minimized");
                attribute.TypeName = typeof(bool).FullName;

                attribute.BindAttributeParameter(parameter =>
                {
                    parameter.Name     = "something";
                    parameter.TypeName = typeof(string).FullName;

                    parameter.SetPropertyName("Something");
                });
            });
            directiveAttribute2.Metadata[TagHelperMetadata.Common.ClassifyAttributesOnly] = bool.TrueString;
            directiveAttribute2.Metadata[ComponentMetadata.Component.NameMatchKey]        = ComponentMetadata.Component.FullyQualifiedNameMatch;
            directiveAttribute2.SetTypeName("TestDirectiveAttribute");

            DefaultTagHelpers = new[] { builder1.Build(), builder2.Build(), builder3.Build(), directiveAttribute1.Build(), directiveAttribute2.Build() };

            HtmlFactsService                = new DefaultHtmlFactsService();
            TagHelperFactsService           = new DefaultTagHelperFactsService();
            RazorTagHelperCompletionService = new DefaultRazorTagHelperCompletionService(TagHelperFactsService);
        }