Add Razor component TagHelper detection.

- WTE needs a way to detect if a `TagHelperDescriptor` is a component based `TagHelper` in order to turn features like validation, completion etc. on/off.
- Updated tests to add verification points for the new `IsRazorComponentTagHelper` method.
\n\nCommit migrated from 6fcd12e60b
This commit is contained in:
N. Taylor Mullen 2019-06-03 15:48:46 -07:00
parent c588d53a42
commit 48eeaefc1e
7 changed files with 32 additions and 1 deletions

View File

@ -124,7 +124,9 @@ namespace Microsoft.AspNetCore.Razor.Language.Components
throw new ArgumentNullException(nameof(tagHelper));
}
return !tagHelper.Metadata.ContainsKey(ComponentMetadata.SpecialKindKey);
return
string.Equals(tagHelper.Kind, ComponentMetadata.Component.TagHelperKind) &&
!tagHelper.Metadata.ContainsKey(ComponentMetadata.SpecialKindKey);
}
public static bool IsEventHandlerTagHelper(this TagHelperDescriptor tagHelper)

View File

@ -2,6 +2,7 @@
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using Microsoft.AspNetCore.Razor.Language.Components;
namespace Microsoft.AspNetCore.Razor.Language
{
@ -38,5 +39,25 @@ namespace Microsoft.AspNetCore.Razor.Language
tagHelper.Metadata.TryGetValue(TagHelperMetadata.Runtime.Name, out var value);
return string.Equals(TagHelperConventions.DefaultKind, value, StringComparison.Ordinal);
}
public static bool IsComponentOrChildContentTagHelper(this TagHelperDescriptor tagHelper)
{
if (tagHelper == null)
{
throw new ArgumentNullException(nameof(tagHelper));
}
if (tagHelper.IsComponentTagHelper())
{
return true;
}
if (tagHelper.IsChildContentTagHelper())
{
return true;
}
return false;
}
}
}

View File

@ -71,6 +71,7 @@ namespace Test
Assert.Equal(ComponentMetadata.Bind.RuntimeName, bind.Metadata[TagHelperMetadata.Runtime.Name]);
Assert.False(bind.IsDefaultKind());
Assert.False(bind.KindUsesDefaultTagHelperRuntime());
Assert.False(bind.IsComponentOrChildContentTagHelper());
Assert.Equal("MyProperty", bind.Metadata[ComponentMetadata.Bind.ValueAttribute]);
Assert.Equal("MyPropertyChanged", bind.Metadata[ComponentMetadata.Bind.ChangeAttribute]);
@ -187,6 +188,7 @@ namespace Test
Assert.Equal(ComponentMetadata.Bind.RuntimeName, bind.Metadata[TagHelperMetadata.Runtime.Name]);
Assert.False(bind.IsDefaultKind());
Assert.False(bind.KindUsesDefaultTagHelperRuntime());
Assert.False(bind.IsComponentOrChildContentTagHelper());
Assert.Equal("MyProperty", bind.Metadata[ComponentMetadata.Bind.ValueAttribute]);
Assert.Equal("MyPropertyChanged", bind.Metadata[ComponentMetadata.Bind.ChangeAttribute]);
@ -334,6 +336,7 @@ namespace Test
Assert.Equal(ComponentMetadata.Bind.RuntimeName, bind.Metadata[TagHelperMetadata.Runtime.Name]);
Assert.False(bind.IsDefaultKind());
Assert.False(bind.KindUsesDefaultTagHelperRuntime());
Assert.False(bind.IsComponentOrChildContentTagHelper());
Assert.Equal("myprop", bind.Metadata[ComponentMetadata.Bind.ValueAttribute]);
Assert.Equal("myevent", bind.Metadata[ComponentMetadata.Bind.ChangeAttribute]);
@ -698,6 +701,7 @@ namespace Test
Assert.Equal(ComponentMetadata.Bind.RuntimeName, bind.Metadata[TagHelperMetadata.Runtime.Name]);
Assert.False(bind.IsDefaultKind());
Assert.False(bind.KindUsesDefaultTagHelperRuntime());
Assert.False(bind.IsComponentOrChildContentTagHelper());
Assert.False(bind.Metadata.ContainsKey(ComponentMetadata.Bind.ValueAttribute));
Assert.False(bind.Metadata.ContainsKey(ComponentMetadata.Bind.ChangeAttribute));

View File

@ -60,6 +60,7 @@ namespace Test
Assert.Equal(ComponentMetadata.Component.TagHelperKind, component.Kind);
Assert.False(component.IsDefaultKind());
Assert.False(component.KindUsesDefaultTagHelperRuntime());
Assert.True(component.IsComponentOrChildContentTagHelper());
// No documentation in this test
Assert.Null(component.Documentation);

View File

@ -56,6 +56,7 @@ namespace Test
Assert.Equal(ComponentMetadata.EventHandler.RuntimeName, item.Metadata[TagHelperMetadata.Runtime.Name]);
Assert.False(item.IsDefaultKind());
Assert.False(item.KindUsesDefaultTagHelperRuntime());
Assert.False(item.IsComponentOrChildContentTagHelper());
Assert.Equal(
"Sets the '@onclick' attribute to the provided string or delegate value. " +

View File

@ -35,6 +35,7 @@ namespace Microsoft.CodeAnalysis.Razor
Assert.Equal(ComponentMetadata.Key.RuntimeName, item.Metadata[TagHelperMetadata.Runtime.Name]);
Assert.False(item.IsDefaultKind());
Assert.False(item.KindUsesDefaultTagHelperRuntime());
Assert.False(item.IsComponentOrChildContentTagHelper());
Assert.Equal(
"Ensures that the component or element will be preserved across renders if (and only if) the supplied key value matches.",

View File

@ -35,6 +35,7 @@ namespace Microsoft.CodeAnalysis.Razor
Assert.Equal(ComponentMetadata.Ref.RuntimeName, item.Metadata[TagHelperMetadata.Runtime.Name]);
Assert.False(item.IsDefaultKind());
Assert.False(item.KindUsesDefaultTagHelperRuntime());
Assert.False(item.IsComponentOrChildContentTagHelper());
Assert.Equal(
"Populates the specified field or property with a reference to the element or component.",