Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FUSE] Component attribute nameof() #10581

Merged
merged 15 commits into from
Jul 16, 2024
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ private static TagHelperDescriptor CreateNameMatchingDescriptor(
continue;
}

CreateProperty(builder, property, kind);
CreateProperty(builder, type, property, kind);
}

if (builder.BoundAttributes.Any(static a => a.IsParameterizedChildContentProperty()) &&
Expand All @@ -195,13 +195,14 @@ private static TagHelperDescriptor CreateNameMatchingDescriptor(
return builder.Build();
}

private static void CreateProperty(TagHelperDescriptorBuilder builder, IPropertySymbol property, PropertyKind kind)
private static void CreateProperty(TagHelperDescriptorBuilder builder, INamedTypeSymbol containingSymbol, IPropertySymbol property, PropertyKind kind)
{
builder.BindAttribute(pb =>
{
using var metadata = new MetadataBuilder();

pb.Name = property.Name;
pb.ContainingType = containingSymbol.ToDisplayString(SymbolExtensions.FullNameTypeDisplayFormat);
pb.TypeName = property.Type.ToDisplayString(SymbolExtensions.FullNameTypeDisplayFormat);
pb.IsEditorRequired = property.GetAttributes().Any(
static a => a.AttributeClass.HasFullName("Microsoft.AspNetCore.Components.EditorRequiredAttribute"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ private enum BoundAttributeFlags
public string Name { get; }
public string TypeName { get; }
public string DisplayName { get; }
public string? ContainingType { get; }

public string? IndexerNamePrefix { get; }
public string? IndexerTypeName { get; }
Expand Down Expand Up @@ -62,6 +63,7 @@ internal BoundAttributeDescriptor(
string? indexerTypeName,
DocumentationObject documentationObject,
string displayName,
string? containingType,
bool caseSensitive,
bool isEditorRequired,
ImmutableArray<BoundAttributeParameterDescriptor> parameters,
Expand All @@ -76,6 +78,7 @@ internal BoundAttributeDescriptor(
IndexerTypeName = indexerTypeName;
_documentationObject = documentationObject;
DisplayName = displayName;
ContainingType = containingType;
Parameters = parameters.NullToEmpty();
Metadata = metadata ?? MetadataCollection.Empty;

Expand Down Expand Up @@ -137,6 +140,7 @@ private protected override void BuildChecksum(in Checksum.Builder builder)
builder.AppendData(IndexerNamePrefix);
builder.AppendData(IndexerTypeName);
builder.AppendData(DisplayName);
builder.AppendData(ContainingType);

DocumentationObject.AppendToChecksum(in builder);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ public string? Documentation

public string? DisplayName { get; set; }

public string? ContainingType { get; set; }

public IDictionary<string, string?> Metadata => _metadata.MetadataDictionary;

public void SetMetadata(MetadataCollection metadata) => _metadata.SetMetadataCollection(metadata);
Expand Down Expand Up @@ -113,6 +115,7 @@ private protected override BoundAttributeDescriptor BuildCore(ImmutableArray<Raz
IndexerValueTypeName,
_documentationObject,
GetDisplayName(),
ContainingType,
CaseSensitive,
IsEditorRequired,
Parameters.ToImmutable(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ private protected override void Reset()
IndexerAttributeNamePrefix = null;
IndexerValueTypeName = null;
DisplayName = null;
ContainingType = null;
Parameters.Clear();
_metadata.Clear();
}
Expand Down
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ private BoundAttributeFormatter()

public override BoundAttributeDescriptor Deserialize(ref MessagePackReader reader, SerializerCachingOptions options)
{
reader.ReadArrayHeaderAndVerify(14);
reader.ReadArrayHeaderAndVerify(15);

var kind = CachedStringFormatter.Instance.Deserialize(ref reader, options).AssumeNotNull();
var name = CachedStringFormatter.Instance.Deserialize(ref reader, options);
Expand All @@ -27,6 +27,7 @@ public override BoundAttributeDescriptor Deserialize(ref MessagePackReader reade
var indexerNamePrefix = CachedStringFormatter.Instance.Deserialize(ref reader, options);
var indexerTypeName = CachedStringFormatter.Instance.Deserialize(ref reader, options);
var displayName = CachedStringFormatter.Instance.Deserialize(ref reader, options).AssumeNotNull();
var containingType = CachedStringFormatter.Instance.Deserialize(ref reader, options);
var documentationObject = reader.Deserialize<DocumentationObject>(options);
var caseSensitive = reader.ReadBoolean();
var isEditorRequired = reader.ReadBoolean();
Expand All @@ -38,13 +39,13 @@ public override BoundAttributeDescriptor Deserialize(ref MessagePackReader reade
return new BoundAttributeDescriptor(
kind, name!, typeName, isEnum,
hasIndexer, indexerNamePrefix, indexerTypeName,
documentationObject, displayName, caseSensitive, isEditorRequired,
documentationObject, displayName, containingType, caseSensitive, isEditorRequired,
parameters, metadata, diagnostics);
}

public override void Serialize(ref MessagePackWriter writer, BoundAttributeDescriptor value, SerializerCachingOptions options)
{
writer.WriteArrayHeader(14);
writer.WriteArrayHeader(15);

CachedStringFormatter.Instance.Serialize(ref writer, value.Kind, options);
CachedStringFormatter.Instance.Serialize(ref writer, value.Name, options);
Expand All @@ -54,6 +55,7 @@ public override void Serialize(ref MessagePackWriter writer, BoundAttributeDescr
CachedStringFormatter.Instance.Serialize(ref writer, value.IndexerNamePrefix, options);
CachedStringFormatter.Instance.Serialize(ref writer, value.IndexerTypeName, options);
CachedStringFormatter.Instance.Serialize(ref writer, value.DisplayName, options);
CachedStringFormatter.Instance.Serialize(ref writer, value.ContainingType, options);
writer.Serialize(value.DocumentationObject, options);
writer.Write(value.CaseSensitive);
writer.Write(value.IsEditorRequired);
Expand All @@ -65,7 +67,7 @@ public override void Serialize(ref MessagePackWriter writer, BoundAttributeDescr

public override void Skim(ref MessagePackReader reader, SerializerCachingOptions options)
{
reader.ReadArrayHeaderAndVerify(14);
reader.ReadArrayHeaderAndVerify(15);

CachedStringFormatter.Instance.Skim(ref reader, options); // Kind;
CachedStringFormatter.Instance.Skim(ref reader, options); // Name
Expand All @@ -75,8 +77,9 @@ public override void Skim(ref MessagePackReader reader, SerializerCachingOptions
CachedStringFormatter.Instance.Skim(ref reader, options); // IndexerNamePrefix
CachedStringFormatter.Instance.Skim(ref reader, options); // IndexerTypeName
CachedStringFormatter.Instance.Skim(ref reader, options); // DisplayName
CachedStringFormatter.Instance.Skim(ref reader, options); // ContainingType
DocumentationObjectFormatter.Instance.Skim(ref reader, options); // DocumentationObject
reader.Skip(); // CaseSenstive
reader.Skip(); // CaseSensitive
reader.Skip(); // IsEditorRequired
BoundAttributeParameterFormatter.Instance.SkimArray(ref reader, options); // BoundAttributeParameters

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ internal static class SerializationFormat
// or any of the types that compose it changes. This includes: RazorConfiguration,
// ProjectWorkspaceState, TagHelperDescriptor, and DocumentSnapshotHandle.
// NOTE: If this version is changed, a coordinated insertion is required between Roslyn and Razor for the C# extension.
public const int Version = 4;
public const int Version = 5;
chsienki marked this conversation as resolved.
Show resolved Hide resolved
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So we need to do a coordinated insertion per the note above?

}
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,7 @@ static BoundAttributeDescriptor ReadFromProperties(JsonDataReader reader)
var indexerNamePrefix = reader.ReadStringOrNull(nameof(BoundAttributeDescriptor.IndexerNamePrefix));
var indexerTypeName = reader.ReadStringOrNull(nameof(BoundAttributeDescriptor.IndexerTypeName));
var displayName = reader.ReadNonNullString(nameof(BoundAttributeDescriptor.DisplayName));
var containingType = reader.ReadStringOrNull(nameof(BoundAttributeDescriptor.ContainingType));
var documentationObject = ReadDocumentationObject(reader, nameof(BoundAttributeDescriptor.Documentation));
var caseSensitive = reader.ReadBooleanOrTrue(nameof(BoundAttributeDescriptor.CaseSensitive));
var isEditorRequired = reader.ReadBooleanOrFalse(nameof(BoundAttributeDescriptor.IsEditorRequired));
Expand All @@ -226,8 +227,8 @@ static BoundAttributeDescriptor ReadFromProperties(JsonDataReader reader)
return new BoundAttributeDescriptor(
Cached(kind), Cached(name)!, Cached(typeName), isEnum,
hasIndexer, Cached(indexerNamePrefix), Cached(indexerTypeName),
documentationObject, Cached(displayName), caseSensitive, isEditorRequired,
parameters, metadata, diagnostics);
documentationObject, Cached(displayName), Cached(containingType),
caseSensitive, isEditorRequired, parameters, metadata, diagnostics);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@ static void WriteBoundAttribute(JsonDataWriter writer, BoundAttributeDescriptor
writer.WriteIfNotNull(nameof(value.IndexerNamePrefix), value.IndexerNamePrefix);
writer.WriteIfNotNull(nameof(value.IndexerTypeName), value.IndexerTypeName);
writer.WriteIfNotNull(nameof(value.DisplayName), value.DisplayName);
writer.WriteIfNotNull(nameof(value.ContainingType), value.ContainingType);
WriteDocumentationObject(writer, nameof(value.Documentation), value.DocumentationObject);
writer.WriteIfNotTrue(nameof(value.CaseSensitive), value.CaseSensitive);
writer.WriteIfNotFalse(nameof(value.IsEditorRequired), value.IsEditorRequired);
Expand Down