This commit is contained in:
N. Taylor Mullen 2021-12-22 12:07:45 -05:00
Родитель 07e115540f
Коммит e9ec3fb480
20 изменённых файлов: 343 добавлений и 70 удалений

Просмотреть файл

@ -2,6 +2,7 @@
<ItemGroup>
<PackageVersion Include="BenchmarkDotNet" Version="$(BenchmarkDotNetVersion)" />
<PackageVersion Include="Newtonsoft.Json" Version="$(NewtonsoftJsonVersion)" />
<PackageVersion Include="MessagePack.Annotations" Version="$(MessagePackAnnotationsVersion)" />
<PackageVersion Include="Microsoft.CodeAnalysis.CSharp" Version="$(MicrosoftCodeAnalysisCSharpVersion)" />
<PackageVersion Include="Microsoft.Extensions.DependencyModel" Version="$(MicrosoftExtensionsDependencyModelVersion)" />
<PackageVersion Include="Moq" Version="$(MoqVersion)" />

Просмотреть файл

@ -36,6 +36,7 @@
-->
<PropertyGroup Label="Manual">
<BenchmarkDotNetVersion>0.13.0</BenchmarkDotNetVersion>
<MessagePackAnnotationsVersion>2.3.85</MessagePackAnnotationsVersion>
<MicrosoftCodeAnalysisCSharpVersion>4.0.0-4.final</MicrosoftCodeAnalysisCSharpVersion>
<MicrosoftExtensionsDependencyModelVersion>6.0.0</MicrosoftExtensionsDependencyModelVersion>
<SystemDiagnosticsDiagnosticSourceVersion>6.0.0</SystemDiagnosticsDiagnosticSourceVersion>

Просмотреть файл

@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<Description>Transport package for Razor Source Generator support.</Description>
@ -27,6 +27,7 @@
</ItemGroup>
<ItemGroup>
<PackageReference Include="MessagePack.Annotations" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" />
</ItemGroup>

Просмотреть файл

@ -4,15 +4,21 @@
using System;
using System.Collections.Generic;
using System.Linq;
using MessagePack;
namespace Microsoft.AspNetCore.Razor.Language;
[MessagePackObject]
[Union(0, typeof(DefaultAllowedChildTagDescriptor))]
public abstract class AllowedChildTagDescriptor : IEquatable<AllowedChildTagDescriptor>
{
[Key(0)]
public string Name { get; protected set; }
[Key(1)]
public string DisplayName { get; protected set; }
[Key(2)]
public IReadOnlyList<RazorDiagnostic> Diagnostics { get; protected set; }
public bool HasErrors

Просмотреть файл

@ -4,12 +4,15 @@
using System;
using System.Collections.Generic;
using System.Linq;
using MessagePack;
namespace Microsoft.AspNetCore.Razor.Language;
/// <summary>
/// A metadata class describing a tag helper attribute.
/// </summary>
[MessagePackObject]
[Union(0, typeof(DefaultBoundAttributeDescriptor))]
public abstract class BoundAttributeDescriptor : IEquatable<BoundAttributeDescriptor>
{
protected BoundAttributeDescriptor(string kind)
@ -17,42 +20,61 @@ public abstract class BoundAttributeDescriptor : IEquatable<BoundAttributeDescri
Kind = kind;
}
[Key(0)]
public string Kind { get; }
public bool IsIndexerStringProperty { get; protected set; }
public bool IsIndexerBooleanProperty { get; protected set; }
public bool IsEnum { get; protected set; }
public bool IsStringProperty { get; protected set; }
public bool IsBooleanProperty { get; protected set; }
internal bool IsEditorRequired { get; set; }
[Key(1)]
public string Name { get; protected set; }
public string IndexerNamePrefix { get; protected set; }
[Key(2)]
public string TypeName { get; protected set; }
public string IndexerTypeName { get; protected set; }
[Key(3)]
public bool IsEnum { get; protected set; }
[Key(4)]
public bool HasIndexer { get; protected set; }
[Key(5)]
public string IndexerNamePrefix { get; protected set; }
[Key(6)]
public string IndexerTypeName { get; protected set; }
[Key(7)]
public string Documentation { get; protected set; }
[Key(8)]
public string DisplayName { get; protected set; }
[Key(9)]
public bool CaseSensitive { get; protected set; }
public IReadOnlyList<RazorDiagnostic> Diagnostics { get; protected set; }
public IReadOnlyDictionary<string, string> Metadata { get; protected set; }
[Key(10)]
public virtual IReadOnlyList<BoundAttributeParameterDescriptor> BoundAttributeParameters { get; protected set; }
[Key(11)]
public IReadOnlyDictionary<string, string> Metadata { get; protected set; }
[Key(12)]
public IReadOnlyList<RazorDiagnostic> Diagnostics { get; protected set; }
[IgnoreMember]
public bool IsIndexerStringProperty { get; protected set; }
[IgnoreMember]
public bool IsIndexerBooleanProperty { get; protected set; }
[IgnoreMember]
public bool IsStringProperty { get; protected set; }
[IgnoreMember]
public bool IsBooleanProperty { get; protected set; }
[IgnoreMember]
internal bool IsEditorRequired { get; set; }
[IgnoreMember]
public bool HasErrors
{
get

Просмотреть файл

@ -1,12 +1,15 @@
// Licensed to the .NET Foundation under one or more agreements.
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
using System;
using System.Collections.Generic;
using System.Linq;
using MessagePack;
namespace Microsoft.AspNetCore.Razor.Language;
[MessagePackObject]
[Union(0, typeof(DefaultBoundAttributeParameterDescriptor))]
public abstract class BoundAttributeParameterDescriptor : IEquatable<BoundAttributeParameterDescriptor>
{
protected BoundAttributeParameterDescriptor(string kind)
@ -14,28 +17,40 @@ public abstract class BoundAttributeParameterDescriptor : IEquatable<BoundAttrib
Kind = kind;
}
[Key(0)]
public string Kind { get; }
public bool IsEnum { get; protected set; }
public bool IsStringProperty { get; protected set; }
public bool IsBooleanProperty { get; protected set; }
[Key(1)]
public string Name { get; protected set; }
[Key(2)]
public string TypeName { get; protected set; }
[Key(3)]
public bool IsEnum { get; protected set; }
[Key(4)]
public string Documentation { get; protected set; }
[Key(5)]
public string DisplayName { get; protected set; }
[Key(6)]
public bool CaseSensitive { get; protected set; }
public IReadOnlyList<RazorDiagnostic> Diagnostics { get; protected set; }
[Key(7)]
public IReadOnlyDictionary<string, string> Metadata { get; protected set; }
[Key(8)]
public IReadOnlyList<RazorDiagnostic> Diagnostics { get; protected set; }
[IgnoreMember]
public bool IsStringProperty { get; protected set; }
[IgnoreMember]
public bool IsBooleanProperty { get; protected set; }
[IgnoreMember]
public bool HasErrors
{
get

Просмотреть файл

@ -2,11 +2,14 @@
// The .NET Foundation licenses this file to you under the MIT license.
using System.Collections.Generic;
using MessagePack;
namespace Microsoft.AspNetCore.Razor.Language;
internal sealed class DefaultBoundAttributeDescriptor : BoundAttributeDescriptor
[MessagePackObject]
public sealed class DefaultBoundAttributeDescriptor : BoundAttributeDescriptor
{
[SerializationConstructor]
public DefaultBoundAttributeDescriptor(
string kind,
string name,
@ -18,9 +21,9 @@ internal sealed class DefaultBoundAttributeDescriptor : BoundAttributeDescriptor
string documentation,
string displayName,
bool caseSensitive,
BoundAttributeParameterDescriptor[] parameterDescriptors,
Dictionary<string, string> metadata,
RazorDiagnostic[] diagnostics)
IReadOnlyList<BoundAttributeParameterDescriptor> parameterDescriptors,
IReadOnlyDictionary<string, string> metadata,
IReadOnlyList<RazorDiagnostic> diagnostics)
: base(kind)
{
Name = name;

Просмотреть файл

@ -1,12 +1,15 @@
// Licensed to the .NET Foundation under one or more agreements.
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
using System.Collections.Generic;
using MessagePack;
namespace Microsoft.AspNetCore.Razor.Language;
internal class DefaultBoundAttributeParameterDescriptor : BoundAttributeParameterDescriptor
[MessagePackObject]
public class DefaultBoundAttributeParameterDescriptor : BoundAttributeParameterDescriptor
{
[SerializationConstructor]
public DefaultBoundAttributeParameterDescriptor(
string kind,
string name,
@ -15,8 +18,8 @@ internal class DefaultBoundAttributeParameterDescriptor : BoundAttributeParamete
string documentation,
string displayName,
bool caseSensitive,
Dictionary<string, string> metadata,
RazorDiagnostic[] diagnostics)
IReadOnlyDictionary<string, string> metadata,
IReadOnlyList<RazorDiagnostic> diagnostics)
: base(kind)
{
Name = name;

Просмотреть файл

@ -1,12 +1,15 @@
// Licensed to the .NET Foundation under one or more agreements.
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
using System.Collections.Generic;
using MessagePack;
namespace Microsoft.AspNetCore.Razor.Language;
internal class DefaultRequiredAttributeDescriptor : RequiredAttributeDescriptor
[MessagePackObject]
public class DefaultRequiredAttributeDescriptor : RequiredAttributeDescriptor
{
[SerializationConstructor]
public DefaultRequiredAttributeDescriptor(
string name,
NameComparisonMode nameComparison,
@ -14,8 +17,8 @@ internal class DefaultRequiredAttributeDescriptor : RequiredAttributeDescriptor
string value,
ValueComparisonMode valueComparison,
string displayName,
RazorDiagnostic[] diagnostics,
Dictionary<string, string> metadata)
IReadOnlyDictionary<string, string> metadata,
IReadOnlyList<RazorDiagnostic> diagnostics)
{
Name = name;
NameComparison = nameComparison;

Просмотреть файл

@ -60,8 +60,8 @@ internal class DefaultRequiredAttributeDescriptorBuilder : RequiredAttributeDesc
Value,
ValueComparisonMode,
displayName,
diagnostics?.ToArray() ?? Array.Empty<RazorDiagnostic>(),
new Dictionary<string, string>(Metadata));
new Dictionary<string, string>(Metadata),
diagnostics?.ToArray() ?? Array.Empty<RazorDiagnostic>());
return rule;
}

Просмотреть файл

@ -1,12 +1,15 @@
// Licensed to the .NET Foundation under one or more agreements.
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
using System.Collections.Generic;
using MessagePack;
namespace Microsoft.AspNetCore.Razor.Language;
internal class DefaultTagHelperDescriptor : TagHelperDescriptor
[MessagePackObject]
public class DefaultTagHelperDescriptor : TagHelperDescriptor
{
[SerializationConstructor]
public DefaultTagHelperDescriptor(
string kind,
string name,
@ -15,11 +18,11 @@ internal class DefaultTagHelperDescriptor : TagHelperDescriptor
string documentation,
string tagOutputHint,
bool caseSensitive,
TagMatchingRuleDescriptor[] tagMatchingRules,
BoundAttributeDescriptor[] attributeDescriptors,
AllowedChildTagDescriptor[] allowedChildTags,
Dictionary<string, string> metadata,
RazorDiagnostic[] diagnostics)
IReadOnlyList<TagMatchingRuleDescriptor> tagMatchingRules,
IReadOnlyList<BoundAttributeDescriptor> attributeDescriptors,
IReadOnlyList<AllowedChildTagDescriptor> allowedChildTags,
IReadOnlyDictionary<string, string> metadata,
IReadOnlyList<RazorDiagnostic> diagnostics)
: base(kind)
{
Name = name;

Просмотреть файл

@ -1,17 +1,22 @@
// Licensed to the .NET Foundation under one or more agreements.
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
using System.Collections.Generic;
using MessagePack;
namespace Microsoft.AspNetCore.Razor.Language;
internal class DefaultTagMatchingRuleDescriptor : TagMatchingRuleDescriptor
[MessagePackObject]
public class DefaultTagMatchingRuleDescriptor : TagMatchingRuleDescriptor
{
[SerializationConstructor]
public DefaultTagMatchingRuleDescriptor(
string tagName,
string parentTag,
TagStructure tagStructure,
bool caseSensitive,
RequiredAttributeDescriptor[] attributes,
RazorDiagnostic[] diagnostics)
IReadOnlyList<RequiredAttributeDescriptor> attributes,
IReadOnlyList<RazorDiagnostic> diagnostics)
{
TagName = tagName;
ParentTag = parentTag;

Просмотреть файл

@ -7,4 +7,8 @@
<ExcludeFromSourceBuild>false</ExcludeFromSourceBuild>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="MessagePack.Annotations" />
</ItemGroup>
</Project>

Просмотреть файл

@ -1,19 +1,25 @@
// Licensed to the .NET Foundation under one or more agreements.
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
using System;
using MessagePack;
namespace Microsoft.AspNetCore.Razor.Language;
[MessagePackObject]
[Union(0, typeof(DefaultRazorDiagnostic))]
public abstract class RazorDiagnostic : IEquatable<RazorDiagnostic>, IFormattable
{
internal static readonly RazorDiagnostic[] EmptyArray = Array.Empty<RazorDiagnostic>();
internal static readonly object[] EmptyArgs = Array.Empty<object>();
[Key(0)]
public abstract string Id { get; }
[Key(1)]
public abstract RazorDiagnosticSeverity Severity { get; }
[Key(2)]
public abstract SourceSpan Span { get; }
public abstract string GetMessage(IFormatProvider formatProvider);

Просмотреть файл

@ -1,30 +1,42 @@
// Licensed to the .NET Foundation under one or more agreements.
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
using System;
using System.Collections.Generic;
using System.Linq;
using MessagePack;
namespace Microsoft.AspNetCore.Razor.Language;
[MessagePackObject]
[Union(0, typeof(DefaultRequiredAttributeDescriptor))]
public abstract class RequiredAttributeDescriptor : IEquatable<RequiredAttributeDescriptor>
{
[Key(0)]
public string Name { get; protected set; }
[Key(1)]
public NameComparisonMode NameComparison { get; protected set; }
[Key(2)]
public bool CaseSensitive { get; protected set; }
[Key(3)]
public string Value { get; protected set; }
[Key(4)]
public ValueComparisonMode ValueComparison { get; protected set; }
[Key(5)]
public string DisplayName { get; protected set; }
public IReadOnlyList<RazorDiagnostic> Diagnostics { get; protected set; }
[Key(6)]
public IReadOnlyDictionary<string, string> Metadata { get; protected set; }
[Key(7)]
public IReadOnlyList<RazorDiagnostic> Diagnostics { get; protected set; }
[IgnoreMember]
public bool HasErrors
{
get

Просмотреть файл

@ -3,10 +3,12 @@
using System;
using System.Globalization;
using MessagePack;
using Microsoft.Extensions.Internal;
namespace Microsoft.AspNetCore.Razor.Language;
[MessagePackObject]
public struct SourceSpan : IEquatable<SourceSpan>
{
public static readonly SourceSpan Undefined = new SourceSpan(SourceLocation.Undefined, 0);
@ -42,18 +44,25 @@ public struct SourceSpan : IEquatable<SourceSpan>
{
}
[Key(0)]
public int Length { get; }
[Key(1)]
public int AbsoluteIndex { get; }
[Key(2)]
public int LineIndex { get; }
[Key(3)]
public int CharacterIndex { get; }
[Key(4)]
public int LineCount { get; }
[Key(5)]
public int EndCharacterIndex { get; }
[Key(6)]
public string FilePath { get; }
public bool Equals(SourceSpan other)

Просмотреть файл

@ -4,9 +4,12 @@
using System;
using System.Collections.Generic;
using System.Linq;
using MessagePack;
namespace Microsoft.AspNetCore.Razor.Language;
[MessagePackObject]
[Union(0, typeof(DefaultTagHelperDescriptor))]
public abstract class TagHelperDescriptor : IEquatable<TagHelperDescriptor>
{
private IEnumerable<RazorDiagnostic> _allDiagnostics;
@ -17,30 +20,42 @@ public abstract class TagHelperDescriptor : IEquatable<TagHelperDescriptor>
Kind = kind;
}
[Key(0)]
public string Kind { get; }
[Key(1)]
public string Name { get; protected set; }
public IReadOnlyList<TagMatchingRuleDescriptor> TagMatchingRules { get; protected set; }
[Key(2)]
public string AssemblyName { get; protected set; }
public IReadOnlyList<BoundAttributeDescriptor> BoundAttributes { get; protected set; }
public IReadOnlyList<AllowedChildTagDescriptor> AllowedChildTags { get; protected set; }
public string Documentation { get; protected set; }
[Key(3)]
public string DisplayName { get; protected set; }
[Key(4)]
public string Documentation { get; protected set; }
[Key(5)]
public string TagOutputHint { get; protected set; }
[Key(6)]
public bool CaseSensitive { get; protected set; }
public IReadOnlyList<RazorDiagnostic> Diagnostics { get; protected set; }
[Key(7)]
public IReadOnlyList<TagMatchingRuleDescriptor> TagMatchingRules { get; protected set; }
[Key(8)]
public IReadOnlyList<BoundAttributeDescriptor> BoundAttributes { get; protected set; }
[Key(9)]
public IReadOnlyList<AllowedChildTagDescriptor> AllowedChildTags { get; protected set; }
[Key(10)]
public IReadOnlyDictionary<string, string> Metadata { get; protected set; }
[Key(11)]
public IReadOnlyList<RazorDiagnostic> Diagnostics { get; protected set; }
// Hoisted / cached metadata
private int? _hashCode;
internal bool? IsComponentFullyQualifiedNameMatchCache { get; set; }
@ -55,6 +70,7 @@ public abstract class TagHelperDescriptor : IEquatable<TagHelperDescriptor>
}
}
[IgnoreMember]
public bool HasErrors
{
get

Просмотреть файл

@ -4,27 +4,36 @@
using System;
using System.Collections.Generic;
using System.Linq;
using MessagePack;
namespace Microsoft.AspNetCore.Razor.Language;
[MessagePackObject]
[Union(0, typeof(DefaultTagMatchingRuleDescriptor))]
public abstract class TagMatchingRuleDescriptor : IEquatable<TagMatchingRuleDescriptor>
{
private int? _hashCode;
private IEnumerable<RazorDiagnostic> _allDiagnostics;
[Key(0)]
public string TagName { get; protected set; }
public IReadOnlyList<RequiredAttributeDescriptor> Attributes { get; protected set; }
[Key(1)]
public string ParentTag { get; protected set; }
[Key(2)]
public TagStructure TagStructure { get; protected set; }
[Key(3)]
public bool CaseSensitive { get; protected set; }
[Key(4)]
public IReadOnlyList<RequiredAttributeDescriptor> Attributes { get; protected set; }
[Key(5)]
public IReadOnlyList<RazorDiagnostic> Diagnostics { get; protected set; }
[IgnoreMember]
public bool HasErrors
{
get

Просмотреть файл

@ -0,0 +1,39 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
using System.Collections.Generic;
using MessagePack;
namespace Microsoft.AspNetCore.Razor.Language;
public class DefaultTagHelperDescriptor : TagHelperDescriptor
{
[SerializationConstructor]
public DefaultTagHelperDescriptor(
string kind,
string name,
string assemblyName,
string displayName,
string documentation,
string tagOutputHint,
bool caseSensitive,
TagMatchingRuleDescriptor[] tagMatchingRules,
BoundAttributeDescriptor[] attributeDescriptors,
AllowedChildTagDescriptor[] allowedChildTags,
Dictionary<string, string> metadata,
RazorDiagnostic[] diagnostics)
: base(kind)
{
Name = name;
AssemblyName = assemblyName;
DisplayName = displayName;
Documentation = documentation;
TagOutputHint = tagOutputHint;
CaseSensitive = caseSensitive;
TagMatchingRules = tagMatchingRules;
BoundAttributes = attributeDescriptors;
AllowedChildTags = allowedChildTags;
Diagnostics = diagnostics;
Metadata = metadata;
}
}

Просмотреть файл

@ -0,0 +1,115 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
using System;
using System.Globalization;
using MessagePack;
using Microsoft.Extensions.Internal;
namespace Microsoft.AspNetCore.Razor.Language;
[MessagePackObject]
public struct SourceSpan : IEquatable<SourceSpan>
{
public static readonly SourceSpan Undefined = new SourceSpan(SourceLocation.Undefined, 0);
public SourceSpan(int absoluteIndex, int length)
: this(null, absoluteIndex, -1, -1, length)
{
}
public SourceSpan(SourceLocation location, int contentLength)
: this(location.FilePath, location.AbsoluteIndex, location.LineIndex, location.CharacterIndex, contentLength, lineCount: 1, endCharacterIndex: 0)
{
}
public SourceSpan(string filePath, int absoluteIndex, int lineIndex, int characterIndex, int length)
: this(filePath: filePath, absoluteIndex: absoluteIndex, lineIndex: lineIndex, characterIndex: characterIndex, length: length, lineCount: 0, endCharacterIndex: 0)
{
}
public SourceSpan(string filePath, int absoluteIndex, int lineIndex, int characterIndex, int length, int lineCount, int endCharacterIndex)
{
AbsoluteIndex = absoluteIndex;
LineIndex = lineIndex;
CharacterIndex = characterIndex;
Length = length;
FilePath = filePath;
LineCount = lineCount;
EndCharacterIndex = endCharacterIndex;
}
public SourceSpan(int absoluteIndex, int lineIndex, int characterIndex, int length)
: this(filePath: null, absoluteIndex: absoluteIndex, lineIndex: lineIndex, characterIndex: characterIndex, length: length)
{
}
[Key(0)]
public int Length { get; }
[Key(1)]
public int AbsoluteIndex { get; }
[Key(2)]
public int LineIndex { get; }
[Key(3)]
public int CharacterIndex { get; }
[Key(4)]
public int LineCount { get; }
[Key(5)]
public int EndCharacterIndex { get; }
[Key(6)]
public string FilePath { get; }
public bool Equals(SourceSpan other)
{
return
string.Equals(FilePath, other.FilePath, StringComparison.Ordinal) &&
AbsoluteIndex == other.AbsoluteIndex &&
LineIndex == other.LineIndex &&
CharacterIndex == other.CharacterIndex &&
Length == other.Length;
}
public override bool Equals(object obj)
{
return obj is SourceSpan span && Equals(span);
}
public override int GetHashCode()
{
var hash = HashCodeCombiner.Start();
hash.Add(FilePath, StringComparer.Ordinal);
hash.Add(AbsoluteIndex);
hash.Add(LineIndex);
hash.Add(CharacterIndex);
hash.Add(Length);
return hash;
}
public override string ToString()
{
return string.Format(
CultureInfo.CurrentCulture, "({0}:{1},{2} [{3}] {4})",
AbsoluteIndex,
LineIndex,
CharacterIndex,
Length,
FilePath);
}
public static bool operator ==(SourceSpan left, SourceSpan right)
{
return left.Equals(right);
}
public static bool operator !=(SourceSpan left, SourceSpan right)
{
return !left.Equals(right);
}
}