Add DisplayName and Description for directives
Renamed Name -> Directive so that it doesn't overlap with DisplayName.
This commit is contained in:
parent
1dfe37b55a
commit
95c5049dd0
|
|
@ -142,7 +142,7 @@ namespace Microsoft.AspNetCore.Mvc.Razor.Extensions
|
|||
{
|
||||
ModelDirectives.Add(node);
|
||||
}
|
||||
else if (node.Descriptor.Name == "inherits")
|
||||
else if (node.Descriptor.Directive == "inherits")
|
||||
{
|
||||
InheritsDirectives.Add(node);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -99,15 +99,15 @@ namespace Microsoft.AspNetCore.Razor.Language
|
|||
|
||||
public override void VisitDirective(DirectiveIRNode node)
|
||||
{
|
||||
if (string.Equals(node.Name, CSharpCodeParser.FunctionsDirectiveDescriptor.Name, StringComparison.Ordinal))
|
||||
if (string.Equals(node.Name, CSharpCodeParser.FunctionsDirectiveDescriptor.Directive, StringComparison.Ordinal))
|
||||
{
|
||||
FunctionsDirectiveNodes.Add(node);
|
||||
}
|
||||
else if (string.Equals(node.Name, CSharpCodeParser.InheritsDirectiveDescriptor.Name, StringComparison.Ordinal))
|
||||
else if (string.Equals(node.Name, CSharpCodeParser.InheritsDirectiveDescriptor.Directive, StringComparison.Ordinal))
|
||||
{
|
||||
InheritsDirectiveNodes.Add(node);
|
||||
}
|
||||
else if (string.Equals(node.Name, CSharpCodeParser.SectionDirectiveDescriptor.Name, StringComparison.Ordinal))
|
||||
else if (string.Equals(node.Name, CSharpCodeParser.SectionDirectiveDescriptor.Directive, StringComparison.Ordinal))
|
||||
{
|
||||
SectionDirectiveNodes.Add(node);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -55,7 +55,7 @@ namespace Microsoft.AspNetCore.Razor.Language
|
|||
if (_nestedLevel > 0)
|
||||
{
|
||||
var directiveStart = block.Children.First(child => !child.IsBlock && ((Span)child).Kind == SpanKindInternal.Transition).Start;
|
||||
var errorLength = /* @ */ 1 + CSharpCodeParser.SectionDirectiveDescriptor.Name.Length;
|
||||
var errorLength = /* @ */ 1 + CSharpCodeParser.SectionDirectiveDescriptor.Directive.Length;
|
||||
_errorSink.OnError(
|
||||
directiveStart,
|
||||
LegacyResources.FormatParseError_Sections_Cannot_Be_Nested(LegacyResources.SectionExample_CS),
|
||||
|
|
|
|||
|
|
@ -116,7 +116,7 @@ namespace Microsoft.AspNetCore.Razor.Language
|
|||
{
|
||||
_builder.Push(new DirectiveIRNode()
|
||||
{
|
||||
Name = CSharpCodeParser.AddTagHelperDirectiveDescriptor.Name,
|
||||
Name = CSharpCodeParser.AddTagHelperDirectiveDescriptor.Directive,
|
||||
Descriptor = CSharpCodeParser.AddTagHelperDirectiveDescriptor,
|
||||
Source = BuildSourceSpanFromNode(span),
|
||||
});
|
||||
|
|
@ -135,7 +135,7 @@ namespace Microsoft.AspNetCore.Razor.Language
|
|||
{
|
||||
_builder.Push(new DirectiveIRNode()
|
||||
{
|
||||
Name = CSharpCodeParser.RemoveTagHelperDirectiveDescriptor.Name,
|
||||
Name = CSharpCodeParser.RemoveTagHelperDirectiveDescriptor.Directive,
|
||||
Descriptor = CSharpCodeParser.RemoveTagHelperDirectiveDescriptor,
|
||||
Source = BuildSourceSpanFromNode(span),
|
||||
});
|
||||
|
|
@ -154,7 +154,7 @@ namespace Microsoft.AspNetCore.Razor.Language
|
|||
{
|
||||
_builder.Push(new DirectiveIRNode()
|
||||
{
|
||||
Name = CSharpCodeParser.TagHelperPrefixDirectiveDescriptor.Name,
|
||||
Name = CSharpCodeParser.TagHelperPrefixDirectiveDescriptor.Directive,
|
||||
Descriptor = CSharpCodeParser.TagHelperPrefixDirectiveDescriptor,
|
||||
Source = BuildSourceSpanFromNode(span),
|
||||
});
|
||||
|
|
@ -220,7 +220,7 @@ namespace Microsoft.AspNetCore.Razor.Language
|
|||
|
||||
_builder.Push(new DirectiveIRNode()
|
||||
{
|
||||
Name = chunkGenerator.Descriptor.Name,
|
||||
Name = chunkGenerator.Descriptor.Directive,
|
||||
Descriptor = chunkGenerator.Descriptor,
|
||||
Source = BuildSourceSpanFromNode(block),
|
||||
});
|
||||
|
|
@ -259,7 +259,7 @@ namespace Microsoft.AspNetCore.Razor.Language
|
|||
{
|
||||
_builder.Push(new DirectiveIRNode()
|
||||
{
|
||||
Name = chunkGenerator.Descriptor.Name,
|
||||
Name = chunkGenerator.Descriptor.Directive,
|
||||
Descriptor = chunkGenerator.Descriptor,
|
||||
Source = BuildSourceSpanFromNode(block),
|
||||
});
|
||||
|
|
|
|||
|
|
@ -7,107 +7,185 @@ using System.Linq;
|
|||
|
||||
namespace Microsoft.AspNetCore.Razor.Language
|
||||
{
|
||||
/// <summary>
|
||||
/// A descriptor type for a directive that can be parsed by the Razor parser.
|
||||
/// </summary>
|
||||
public abstract class DirectiveDescriptor
|
||||
{
|
||||
public abstract string Name { get; }
|
||||
/// <summary>
|
||||
/// Gets the description of the directive.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// The description is used for information purposes, and has no effect on parsing.
|
||||
/// </remarks>
|
||||
public abstract string Description { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the directive keyword without the leading <c>@</c> token.
|
||||
/// </summary>
|
||||
public abstract string Directive { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the display name of the directive.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// The display name is used for information purposes, and has no effect on parsing.
|
||||
/// </remarks>
|
||||
public abstract string DisplayName { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the kind of the directive. The kind determines whether or not a directive has an associated block.
|
||||
/// </summary>
|
||||
public abstract DirectiveKind Kind { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the list of directive tokens that can follow the directive keyword.
|
||||
/// </summary>
|
||||
public abstract IReadOnlyList<DirectiveTokenDescriptor> Tokens { get; }
|
||||
|
||||
public static DirectiveDescriptor CreateDirective(string name, DirectiveKind kind)
|
||||
/// <summary>
|
||||
/// Creates a new <see cref="DirectiveDescriptor"/>.
|
||||
/// </summary>
|
||||
/// <param name="directive">The directive keyword.</param>
|
||||
/// <param name="kind">The directive kind.</param>
|
||||
/// <returns>A <see cref="DirectiveDescriptor"/> for the created directive.</returns>
|
||||
public static DirectiveDescriptor CreateDirective(string directive, DirectiveKind kind)
|
||||
{
|
||||
if (name == null)
|
||||
if (directive == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(name));
|
||||
throw new ArgumentNullException(nameof(directive));
|
||||
}
|
||||
|
||||
return CreateDirective(name, kind, configure: null);
|
||||
return CreateDirective(directive, kind, configure: null);
|
||||
}
|
||||
|
||||
public static DirectiveDescriptor CreateDirective(string name, DirectiveKind kind, Action<IDirectiveDescriptorBuilder> configure)
|
||||
/// <summary>
|
||||
/// Creates a new <see cref="DirectiveDescriptor"/>.
|
||||
/// </summary>
|
||||
/// <param name="directive">The directive keyword.</param>
|
||||
/// <param name="kind">The directive kind.</param>
|
||||
/// <param name="configure">A configuration delegate for the directive.</param>
|
||||
/// <returns>A <see cref="DirectiveDescriptor"/> for the created directive.</returns>
|
||||
public static DirectiveDescriptor CreateDirective(string directive, DirectiveKind kind, Action<IDirectiveDescriptorBuilder> configure)
|
||||
{
|
||||
if (name == null)
|
||||
if (directive == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(name));
|
||||
throw new ArgumentNullException(nameof(directive));
|
||||
}
|
||||
|
||||
var builder = new DefaultDirectiveDescriptorBuilder(name, kind);
|
||||
var builder = new DefaultDirectiveDescriptorBuilder(directive, kind);
|
||||
configure?.Invoke(builder);
|
||||
return builder.Build();
|
||||
}
|
||||
|
||||
public static DirectiveDescriptor CreateSingleLineDirective(string name)
|
||||
/// <summary>
|
||||
/// Creates a new <see cref="DirectiveDescriptor"/> with <see cref="Kind"/> set to <see cref="DirectiveKind.SingleLine"/>
|
||||
/// </summary>
|
||||
/// <param name="directive">The directive keyword.</param>
|
||||
/// <returns>A <see cref="DirectiveDescriptor"/> for the created directive.</returns>
|
||||
public static DirectiveDescriptor CreateSingleLineDirective(string directive)
|
||||
{
|
||||
if (name == null)
|
||||
if (directive == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(name));
|
||||
throw new ArgumentNullException(nameof(directive));
|
||||
}
|
||||
|
||||
return CreateDirective(name, DirectiveKind.SingleLine, configure: null);
|
||||
return CreateDirective(directive, DirectiveKind.SingleLine, configure: null);
|
||||
}
|
||||
|
||||
public static DirectiveDescriptor CreateSingleLineDirective(string name, Action<IDirectiveDescriptorBuilder> configure)
|
||||
/// <summary>
|
||||
/// Creates a new <see cref="DirectiveDescriptor"/> with <see cref="Kind"/> set to <see cref="DirectiveKind.SingleLine"/>
|
||||
/// </summary>
|
||||
/// <param name="directive">The directive keyword.</param>
|
||||
/// <param name="configure">A configuration delegate for the directive.</param>
|
||||
/// <returns>A <see cref="DirectiveDescriptor"/> for the created directive.</returns>
|
||||
public static DirectiveDescriptor CreateSingleLineDirective(string directive, Action<IDirectiveDescriptorBuilder> configure)
|
||||
{
|
||||
if (name == null)
|
||||
if (directive == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(name));
|
||||
throw new ArgumentNullException(nameof(directive));
|
||||
}
|
||||
|
||||
return CreateDirective(name, DirectiveKind.SingleLine, configure);
|
||||
return CreateDirective(directive, DirectiveKind.SingleLine, configure);
|
||||
}
|
||||
|
||||
public static DirectiveDescriptor CreateRazorBlockDirective(string name)
|
||||
/// <summary>
|
||||
/// Creates a new <see cref="DirectiveDescriptor"/> with <see cref="Kind"/> set to <see cref="DirectiveKind.RazorBlock"/>
|
||||
/// </summary>
|
||||
/// <param name="directive">The directive keyword.</param>
|
||||
/// <returns>A <see cref="DirectiveDescriptor"/> for the created directive.</returns>
|
||||
public static DirectiveDescriptor CreateRazorBlockDirective(string directive)
|
||||
{
|
||||
if (name == null)
|
||||
if (directive == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(name));
|
||||
throw new ArgumentNullException(nameof(directive));
|
||||
}
|
||||
|
||||
return CreateDirective(name, DirectiveKind.RazorBlock, configure: null);
|
||||
return CreateDirective(directive, DirectiveKind.RazorBlock, configure: null);
|
||||
}
|
||||
|
||||
public static DirectiveDescriptor CreateRazorBlockDirective(string name, Action<IDirectiveDescriptorBuilder> configure)
|
||||
/// <summary>
|
||||
/// Creates a new <see cref="DirectiveDescriptor"/> with <see cref="Kind"/> set to <see cref="DirectiveKind.RazorBlock"/>
|
||||
/// </summary>
|
||||
/// <param name="directive">The directive keyword.</param>
|
||||
/// <param name="configure">A configuration delegate for the directive.</param>
|
||||
/// <returns>A <see cref="DirectiveDescriptor"/> for the created directive.</returns>
|
||||
public static DirectiveDescriptor CreateRazorBlockDirective(string directive, Action<IDirectiveDescriptorBuilder> configure)
|
||||
{
|
||||
if (name == null)
|
||||
if (directive == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(name));
|
||||
throw new ArgumentNullException(nameof(directive));
|
||||
}
|
||||
|
||||
return CreateDirective(name, DirectiveKind.RazorBlock, configure);
|
||||
return CreateDirective(directive, DirectiveKind.RazorBlock, configure);
|
||||
}
|
||||
|
||||
public static DirectiveDescriptor CreateCodeBlockDirective(string name)
|
||||
/// <summary>
|
||||
/// Creates a new <see cref="DirectiveDescriptor"/> with <see cref="Kind"/> set to <see cref="DirectiveKind.CodeBlock"/>
|
||||
/// </summary>
|
||||
/// <param name="directive">The directive keyword.</param>
|
||||
/// <returns>A <see cref="DirectiveDescriptor"/> for the created directive.</returns>
|
||||
public static DirectiveDescriptor CreateCodeBlockDirective(string directive)
|
||||
{
|
||||
if (name == null)
|
||||
if (directive == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(name));
|
||||
throw new ArgumentNullException(nameof(directive));
|
||||
}
|
||||
|
||||
return CreateDirective(name, DirectiveKind.CodeBlock, configure: null);
|
||||
return CreateDirective(directive, DirectiveKind.CodeBlock, configure: null);
|
||||
}
|
||||
|
||||
public static DirectiveDescriptor CreateCodeBlockDirective(string name, Action<IDirectiveDescriptorBuilder> configure)
|
||||
/// <summary>
|
||||
/// Creates a new <see cref="DirectiveDescriptor"/> with <see cref="Kind"/> set to <see cref="DirectiveKind.CodeBlock"/>
|
||||
/// </summary>
|
||||
/// <param name="directive">The directive keyword.</param>
|
||||
/// <param name="configure">A configuration delegate for the directive.</param>
|
||||
/// <returns>A <see cref="DirectiveDescriptor"/> for the created directive.</returns>
|
||||
public static DirectiveDescriptor CreateCodeBlockDirective(string directive, Action<IDirectiveDescriptorBuilder> configure)
|
||||
{
|
||||
if (name == null)
|
||||
if (directive == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(name));
|
||||
throw new ArgumentNullException(nameof(directive));
|
||||
}
|
||||
|
||||
return CreateDirective(name, DirectiveKind.CodeBlock, configure);
|
||||
return CreateDirective(directive, DirectiveKind.CodeBlock, configure);
|
||||
}
|
||||
|
||||
private class DefaultDirectiveDescriptorBuilder : IDirectiveDescriptorBuilder
|
||||
{
|
||||
public DefaultDirectiveDescriptorBuilder(string name, DirectiveKind kind)
|
||||
{
|
||||
Name = name;
|
||||
Directive = name;
|
||||
Kind = kind;
|
||||
|
||||
Tokens = new List<DirectiveTokenDescriptor>();
|
||||
}
|
||||
|
||||
public string Name { get; }
|
||||
public string Description { get; set; }
|
||||
|
||||
public string Directive { get; }
|
||||
|
||||
public string DisplayName { get; set; }
|
||||
|
||||
public DirectiveKind Kind { get; }
|
||||
|
||||
|
|
@ -115,16 +193,16 @@ namespace Microsoft.AspNetCore.Razor.Language
|
|||
|
||||
public DirectiveDescriptor Build()
|
||||
{
|
||||
if (Name.Length == 0)
|
||||
if (Directive.Length == 0)
|
||||
{
|
||||
throw new InvalidOperationException(Resources.FormatDirectiveDescriptor_InvalidDirectiveName(Name));
|
||||
throw new InvalidOperationException(Resources.FormatDirectiveDescriptor_InvalidDirectiveKeyword(Directive));
|
||||
}
|
||||
|
||||
for (var i = 0; i < Name.Length; i++)
|
||||
for (var i = 0; i < Directive.Length; i++)
|
||||
{
|
||||
if (!char.IsLetter(Name[i]))
|
||||
if (!char.IsLetter(Directive[i]))
|
||||
{
|
||||
throw new InvalidOperationException(Resources.FormatDirectiveDescriptor_InvalidDirectiveName(Name));
|
||||
throw new InvalidOperationException(Resources.FormatDirectiveDescriptor_InvalidDirectiveKeyword(Directive));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -140,20 +218,31 @@ namespace Microsoft.AspNetCore.Razor.Language
|
|||
}
|
||||
}
|
||||
|
||||
return new DefaultDirectiveDescriptor(Name, Kind, Tokens.ToArray());
|
||||
return new DefaultDirectiveDescriptor(Directive, Kind, Tokens.ToArray(), DisplayName, Description);
|
||||
}
|
||||
}
|
||||
|
||||
private class DefaultDirectiveDescriptor : DirectiveDescriptor
|
||||
{
|
||||
public DefaultDirectiveDescriptor(string name, DirectiveKind kind, DirectiveTokenDescriptor[] tokens)
|
||||
public DefaultDirectiveDescriptor(
|
||||
string directive,
|
||||
DirectiveKind kind,
|
||||
DirectiveTokenDescriptor[] tokens,
|
||||
string displayName,
|
||||
string description)
|
||||
{
|
||||
Name = name;
|
||||
Directive = directive;
|
||||
Kind = kind;
|
||||
Tokens = tokens;
|
||||
DisplayName = displayName;
|
||||
Description = description;
|
||||
}
|
||||
|
||||
public override string Name { get; }
|
||||
public override string Description { get; }
|
||||
|
||||
public override string Directive { get; }
|
||||
|
||||
public override string DisplayName { get; }
|
||||
|
||||
public override DirectiveKind Kind { get; }
|
||||
|
||||
|
|
|
|||
|
|
@ -24,7 +24,7 @@ namespace Microsoft.AspNetCore.Razor.Language
|
|||
}
|
||||
|
||||
return descriptorX != null &&
|
||||
string.Equals(descriptorX.Name, descriptorY.Name, StringComparison.Ordinal) &&
|
||||
string.Equals(descriptorX.Directive, descriptorY.Directive, StringComparison.Ordinal) &&
|
||||
descriptorX.Kind == descriptorY.Kind &&
|
||||
Enumerable.SequenceEqual(
|
||||
descriptorX.Tokens,
|
||||
|
|
@ -40,7 +40,7 @@ namespace Microsoft.AspNetCore.Razor.Language
|
|||
}
|
||||
|
||||
var hashCodeCombiner = HashCodeCombiner.Start();
|
||||
hashCodeCombiner.Add(descriptor.Name, StringComparer.Ordinal);
|
||||
hashCodeCombiner.Add(descriptor.Directive, StringComparer.Ordinal);
|
||||
hashCodeCombiner.Add(descriptor.Kind);
|
||||
|
||||
return hashCodeCombiner.CombinedHash;
|
||||
|
|
|
|||
|
|
@ -5,14 +5,40 @@ using System.Collections.Generic;
|
|||
|
||||
namespace Microsoft.AspNetCore.Razor.Language
|
||||
{
|
||||
/// <summary>
|
||||
/// A builder interface for configuring a <see cref="DirectiveDescriptor"/>.
|
||||
/// </summary>
|
||||
public interface IDirectiveDescriptorBuilder
|
||||
{
|
||||
string Name { get; }
|
||||
/// <summary>
|
||||
/// Gets or sets the description of the directive.
|
||||
/// </summary>
|
||||
string Description { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the directive keyword.
|
||||
/// </summary>
|
||||
string Directive { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the display name of the directive.
|
||||
/// </summary>
|
||||
string DisplayName { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the directive kind.
|
||||
/// </summary>
|
||||
DirectiveKind Kind { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets a list of the directive tokens.
|
||||
/// </summary>
|
||||
IList<DirectiveTokenDescriptor> Tokens { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Creates a <see cref="DirectiveDescriptor"/> based on the current property values of the builder.
|
||||
/// </summary>
|
||||
/// <returns>The created <see cref="DirectiveDescriptor" />.</returns>
|
||||
DirectiveDescriptor Build();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1546,8 +1546,8 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
|
|||
for (var i = 0; i < allDirectives.Count; i++)
|
||||
{
|
||||
var directiveDescriptor = allDirectives[i];
|
||||
CurrentKeywords.Add(directiveDescriptor.Name);
|
||||
MapDirectives(() => HandleDirective(directiveDescriptor), directiveDescriptor.Name);
|
||||
CurrentKeywords.Add(directiveDescriptor.Directive);
|
||||
MapDirectives(() => HandleDirective(directiveDescriptor), directiveDescriptor.Directive);
|
||||
}
|
||||
|
||||
MapDirectives(TagHelperPrefixDirective, SyntaxConstants.CSharp.TagHelperPrefixKeyword);
|
||||
|
|
@ -1583,7 +1583,7 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
|
|||
{
|
||||
Context.Builder.CurrentBlock.Type = BlockKindInternal.Directive;
|
||||
Context.Builder.CurrentBlock.ChunkGenerator = new DirectiveChunkGenerator(descriptor);
|
||||
AssertDirective(descriptor.Name);
|
||||
AssertDirective(descriptor.Directive);
|
||||
|
||||
AcceptAndMoveNext();
|
||||
Output(SpanKindInternal.MetaCode, AcceptedCharactersInternal.None);
|
||||
|
|
@ -1614,7 +1614,7 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
|
|||
{
|
||||
Context.ErrorSink.OnError(
|
||||
CurrentStart,
|
||||
LegacyResources.FormatUnexpectedEOFAfterDirective(descriptor.Name, tokenDescriptor.Kind.ToString().ToLowerInvariant()),
|
||||
LegacyResources.FormatUnexpectedEOFAfterDirective(descriptor.Directive, tokenDescriptor.Kind.ToString().ToLowerInvariant()),
|
||||
length: 1);
|
||||
return;
|
||||
}
|
||||
|
|
@ -1626,7 +1626,7 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
|
|||
{
|
||||
Context.ErrorSink.OnError(
|
||||
CurrentStart,
|
||||
LegacyResources.FormatDirectiveExpectsTypeName(descriptor.Name),
|
||||
LegacyResources.FormatDirectiveExpectsTypeName(descriptor.Directive),
|
||||
CurrentSymbol.Content.Length);
|
||||
|
||||
return;
|
||||
|
|
@ -1638,7 +1638,7 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
|
|||
{
|
||||
Context.ErrorSink.OnError(
|
||||
CurrentStart,
|
||||
LegacyResources.FormatDirectiveExpectsNamespace(descriptor.Name),
|
||||
LegacyResources.FormatDirectiveExpectsNamespace(descriptor.Directive),
|
||||
identifierLength);
|
||||
|
||||
return;
|
||||
|
|
@ -1654,7 +1654,7 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
|
|||
{
|
||||
Context.ErrorSink.OnError(
|
||||
CurrentStart,
|
||||
LegacyResources.FormatDirectiveExpectsIdentifier(descriptor.Name),
|
||||
LegacyResources.FormatDirectiveExpectsIdentifier(descriptor.Directive),
|
||||
CurrentSymbol.Content.Length);
|
||||
return;
|
||||
}
|
||||
|
|
@ -1669,7 +1669,7 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
|
|||
{
|
||||
Context.ErrorSink.OnError(
|
||||
CurrentStart,
|
||||
LegacyResources.FormatDirectiveExpectsQuotedStringLiteral(descriptor.Name),
|
||||
LegacyResources.FormatDirectiveExpectsQuotedStringLiteral(descriptor.Directive),
|
||||
CurrentSymbol.Content.Length);
|
||||
return;
|
||||
}
|
||||
|
|
@ -1698,7 +1698,7 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
|
|||
{
|
||||
Context.ErrorSink.OnError(
|
||||
CurrentStart,
|
||||
LegacyResources.FormatUnexpectedDirectiveLiteral(descriptor.Name, LegacyResources.ErrorComponent_Newline),
|
||||
LegacyResources.FormatUnexpectedDirectiveLiteral(descriptor.Directive, LegacyResources.ErrorComponent_Newline),
|
||||
CurrentSymbol.Content.Length);
|
||||
}
|
||||
|
||||
|
|
@ -1750,14 +1750,14 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
|
|||
{
|
||||
Context.ErrorSink.OnError(
|
||||
CurrentStart,
|
||||
LegacyResources.FormatUnexpectedEOFAfterDirective(descriptor.Name, "{"),
|
||||
LegacyResources.FormatUnexpectedEOFAfterDirective(descriptor.Directive, "{"),
|
||||
length: 1 /* { */);
|
||||
}
|
||||
else if (!At(CSharpSymbolType.LeftBrace))
|
||||
{
|
||||
Context.ErrorSink.OnError(
|
||||
CurrentStart,
|
||||
LegacyResources.FormatUnexpectedDirectiveLiteral(descriptor.Name, "{"),
|
||||
LegacyResources.FormatUnexpectedDirectiveLiteral(descriptor.Directive, "{"),
|
||||
CurrentSymbol.Content.Length);
|
||||
}
|
||||
else
|
||||
|
|
@ -1777,7 +1777,7 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
|
|||
editHandler.AutoCompleteString = "}";
|
||||
Context.ErrorSink.OnError(
|
||||
startingBraceLocation,
|
||||
LegacyResources.FormatParseError_Expected_EndOfBlock_Before_EOF(descriptor.Name, "}", "{"),
|
||||
LegacyResources.FormatParseError_Expected_EndOfBlock_Before_EOF(descriptor.Directive, "}", "{"),
|
||||
length: 1 /* } */);
|
||||
}
|
||||
else
|
||||
|
|
|
|||
|
|
@ -389,18 +389,18 @@ namespace Microsoft.AspNetCore.Razor.Language
|
|||
=> string.Format(CultureInfo.CurrentCulture, GetString("InvalidOperation_SpanIsNotChangeOwner"), p0, p1);
|
||||
|
||||
/// <summary>
|
||||
/// Invalid directive name '{0}'. Directives must have a non-empty name that consists only of letters.
|
||||
/// Invalid directive keyword '{0}'. Directives must have a non-empty keyword that consists only of letters.
|
||||
/// </summary>
|
||||
internal static string DirectiveDescriptor_InvalidDirectiveName
|
||||
internal static string DirectiveDescriptor_InvalidDirectiveKeyword
|
||||
{
|
||||
get => GetString("DirectiveDescriptor_InvalidDirectiveName");
|
||||
get => GetString("DirectiveDescriptor_InvalidDirectiveKeyword");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Invalid directive name '{0}'. Directives must have a non-empty name that consists only of letters.
|
||||
/// Invalid directive keyword '{0}'. Directives must have a non-empty keyword that consists only of letters.
|
||||
/// </summary>
|
||||
internal static string FormatDirectiveDescriptor_InvalidDirectiveName(object p0)
|
||||
=> string.Format(CultureInfo.CurrentCulture, GetString("DirectiveDescriptor_InvalidDirectiveName"), p0);
|
||||
internal static string FormatDirectiveDescriptor_InvalidDirectiveKeyword(object p0)
|
||||
=> string.Format(CultureInfo.CurrentCulture, GetString("DirectiveDescriptor_InvalidDirectiveKeyword"), p0);
|
||||
|
||||
/// <summary>
|
||||
/// The feature must be initialized by setting the '{0}' property.
|
||||
|
|
|
|||
|
|
@ -198,8 +198,8 @@
|
|||
<data name="InvalidOperation_SpanIsNotChangeOwner" xml:space="preserve">
|
||||
<value>The node '{0}' is not the owner of change '{1}'.</value>
|
||||
</data>
|
||||
<data name="DirectiveDescriptor_InvalidDirectiveName" xml:space="preserve">
|
||||
<value>Invalid directive name '{0}'. Directives must have a non-empty name that consists only of letters.</value>
|
||||
<data name="DirectiveDescriptor_InvalidDirectiveKeyword" xml:space="preserve">
|
||||
<value>Invalid directive keyword '{0}'. Directives must have a non-empty keyword that consists only of letters.</value>
|
||||
</data>
|
||||
<data name="FeatureMustBeInitialized" xml:space="preserve">
|
||||
<value>The feature must be initialized by setting the '{0}' property.</value>
|
||||
|
|
|
|||
|
|
@ -42,7 +42,7 @@ namespace Microsoft.AspNetCore.Razor.Language
|
|||
// Assert
|
||||
var syntaxTree = codeDocument.GetSyntaxTree();
|
||||
var directive = Assert.Single(syntaxTree.Options.Directives);
|
||||
Assert.Equal("test", directive.Name);
|
||||
Assert.Equal("test", directive.Directive);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
|
@ -70,8 +70,8 @@ namespace Microsoft.AspNetCore.Razor.Language
|
|||
// Assert
|
||||
Assert.Collection(
|
||||
codeDocument.GetImportSyntaxTrees(),
|
||||
t => { Assert.Same(t.Source, imports[0]); Assert.Equal("test", Assert.Single(t.Options.Directives).Name); },
|
||||
t => { Assert.Same(t.Source, imports[1]); Assert.Equal("test", Assert.Single(t.Options.Directives).Name); });
|
||||
t => { Assert.Same(t.Source, imports[0]); Assert.Equal("test", Assert.Single(t.Options.Directives).Directive); },
|
||||
t => { Assert.Same(t.Source, imports[1]); Assert.Equal("test", Assert.Single(t.Options.Directives).Directive); });
|
||||
}
|
||||
|
||||
private class MyParserOptionsFeature : RazorEngineFeatureBase, IRazorParserOptionsFeature
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@ namespace Microsoft.AspNetCore.Razor.Language
|
|||
var directive = DirectiveDescriptor.CreateDirective("test", DirectiveKind.SingleLine);
|
||||
|
||||
// Assert
|
||||
Assert.Equal("test", directive.Name);
|
||||
Assert.Equal("test", directive.Directive);
|
||||
Assert.Equal(DirectiveKind.SingleLine, directive.Kind);
|
||||
}
|
||||
|
||||
|
|
@ -30,7 +30,7 @@ namespace Microsoft.AspNetCore.Razor.Language
|
|||
var directive = DirectiveDescriptor.CreateDirective("test", DirectiveKind.SingleLine, configure);
|
||||
|
||||
// Assert
|
||||
Assert.Equal("test", directive.Name);
|
||||
Assert.Equal("test", directive.Directive);
|
||||
Assert.Equal(DirectiveKind.SingleLine, directive.Kind);
|
||||
Assert.True(called);
|
||||
}
|
||||
|
|
@ -42,7 +42,7 @@ namespace Microsoft.AspNetCore.Razor.Language
|
|||
var directive = DirectiveDescriptor.CreateSingleLineDirective("test");
|
||||
|
||||
// Assert
|
||||
Assert.Equal("test", directive.Name);
|
||||
Assert.Equal("test", directive.Directive);
|
||||
Assert.Equal(DirectiveKind.SingleLine, directive.Kind);
|
||||
}
|
||||
|
||||
|
|
@ -57,7 +57,7 @@ namespace Microsoft.AspNetCore.Razor.Language
|
|||
var directive = DirectiveDescriptor.CreateSingleLineDirective("test", configure);
|
||||
|
||||
// Assert
|
||||
Assert.Equal("test", directive.Name);
|
||||
Assert.Equal("test", directive.Directive);
|
||||
Assert.Equal(DirectiveKind.SingleLine, directive.Kind);
|
||||
Assert.True(called);
|
||||
}
|
||||
|
|
@ -69,7 +69,7 @@ namespace Microsoft.AspNetCore.Razor.Language
|
|||
var directive = DirectiveDescriptor.CreateRazorBlockDirective("test");
|
||||
|
||||
// Assert
|
||||
Assert.Equal("test", directive.Name);
|
||||
Assert.Equal("test", directive.Directive);
|
||||
Assert.Equal(DirectiveKind.RazorBlock, directive.Kind);
|
||||
}
|
||||
|
||||
|
|
@ -84,7 +84,7 @@ namespace Microsoft.AspNetCore.Razor.Language
|
|||
var directive = DirectiveDescriptor.CreateRazorBlockDirective("test", configure);
|
||||
|
||||
// Assert
|
||||
Assert.Equal("test", directive.Name);
|
||||
Assert.Equal("test", directive.Directive);
|
||||
Assert.Equal(DirectiveKind.RazorBlock, directive.Kind);
|
||||
Assert.True(called);
|
||||
}
|
||||
|
|
@ -96,7 +96,7 @@ namespace Microsoft.AspNetCore.Razor.Language
|
|||
var directive = DirectiveDescriptor.CreateCodeBlockDirective("test");
|
||||
|
||||
// Assert
|
||||
Assert.Equal("test", directive.Name);
|
||||
Assert.Equal("test", directive.Directive);
|
||||
Assert.Equal(DirectiveKind.CodeBlock, directive.Kind);
|
||||
}
|
||||
|
||||
|
|
@ -111,29 +111,29 @@ namespace Microsoft.AspNetCore.Razor.Language
|
|||
var directive = DirectiveDescriptor.CreateCodeBlockDirective("test", configure);
|
||||
|
||||
// Assert
|
||||
Assert.Equal("test", directive.Name);
|
||||
Assert.Equal("test", directive.Directive);
|
||||
Assert.Equal(DirectiveKind.CodeBlock, directive.Kind);
|
||||
Assert.True(called);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Build_ValidatesDirectiveName_EmptyIsInvalid()
|
||||
public void Build_ValidatesDirectiveKeyword_EmptyIsInvalid()
|
||||
{
|
||||
// Arrange & Act
|
||||
var ex = Assert.Throws<InvalidOperationException>(() => DirectiveDescriptor.CreateSingleLineDirective(""));
|
||||
|
||||
// Assert
|
||||
Assert.Equal("Invalid directive name ''. Directives must have a non-empty name that consists only of letters.", ex.Message);
|
||||
Assert.Equal("Invalid directive keyword ''. Directives must have a non-empty keyword that consists only of letters.", ex.Message);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Build_ValidatesDirectiveName_InvalidCharacter()
|
||||
public void Build_ValidatesDirectiveKeyword_InvalidCharacter()
|
||||
{
|
||||
// Arrange & Act
|
||||
var ex = Assert.Throws<InvalidOperationException>(() => DirectiveDescriptor.CreateSingleLineDirective("test_directive"));
|
||||
|
||||
// Assert
|
||||
Assert.Equal("Invalid directive name 'test_directive'. Directives must have a non-empty name that consists only of letters.", ex.Message);
|
||||
Assert.Equal("Invalid directive keyword 'test_directive'. Directives must have a non-empty keyword that consists only of letters.", ex.Message);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
|
|||
Factory.MetaCode("functions").Accepts(AcceptedCharactersInternal.None),
|
||||
Factory.MetaCode("{").AutoCompleteWith("}", atEndOfSpan: true).Accepts(AcceptedCharactersInternal.None)),
|
||||
new RazorError(
|
||||
LegacyResources.FormatParseError_Expected_EndOfBlock_Before_EOF(CSharpCodeParser.FunctionsDirectiveDescriptor.Name, "}", "{"),
|
||||
LegacyResources.FormatParseError_Expected_EndOfBlock_Before_EOF(CSharpCodeParser.FunctionsDirectiveDescriptor.Directive, "}", "{"),
|
||||
new SourceLocation(10, 0, 10),
|
||||
length: 1));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
|
|||
Factory.MetaCode("section").Accepts(AcceptedCharactersInternal.None)),
|
||||
Factory.Markup(Environment.NewLine)),
|
||||
new RazorError(
|
||||
LegacyResources.FormatDirectiveExpectsIdentifier(CSharpCodeParser.SectionDirectiveDescriptor.Name),
|
||||
LegacyResources.FormatDirectiveExpectsIdentifier(CSharpCodeParser.SectionDirectiveDescriptor.Directive),
|
||||
new SourceLocation(8, 0, 8),
|
||||
length: Environment.NewLine.Length));
|
||||
}
|
||||
|
|
@ -39,7 +39,7 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
|
|||
Factory.Span(SpanKindInternal.Markup, " " + Environment.NewLine + " ", markup: false).Accepts(AcceptedCharactersInternal.AllWhiteSpace)),
|
||||
Factory.EmptyHtml()),
|
||||
new RazorError(
|
||||
LegacyResources.FormatUnexpectedEOFAfterDirective(CSharpCodeParser.SectionDirectiveDescriptor.Name, "{"),
|
||||
LegacyResources.FormatUnexpectedEOFAfterDirective(CSharpCodeParser.SectionDirectiveDescriptor.Directive, "{"),
|
||||
new SourceLocation(25 + Environment.NewLine.Length, 0, 25 + Environment.NewLine.Length),
|
||||
length: 1));
|
||||
}
|
||||
|
|
@ -56,7 +56,7 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
|
|||
Factory.Span(SpanKindInternal.Code, " ", CSharpSymbolType.WhiteSpace).Accepts(AcceptedCharactersInternal.WhiteSpace)),
|
||||
Factory.Markup(Environment.NewLine + " ")),
|
||||
new RazorError(
|
||||
LegacyResources.FormatDirectiveExpectsIdentifier(CSharpCodeParser.SectionDirectiveDescriptor.Name),
|
||||
LegacyResources.FormatDirectiveExpectsIdentifier(CSharpCodeParser.SectionDirectiveDescriptor.Directive),
|
||||
new SourceLocation(17, 0, 17),
|
||||
length: Environment.NewLine.Length));
|
||||
}
|
||||
|
|
@ -93,7 +93,7 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
|
|||
Factory.Markup("</p>")),
|
||||
Factory.Markup(" }")),
|
||||
new RazorError(
|
||||
LegacyResources.FormatDirectiveExpectsIdentifier(CSharpCodeParser.SectionDirectiveDescriptor.Name),
|
||||
LegacyResources.FormatDirectiveExpectsIdentifier(CSharpCodeParser.SectionDirectiveDescriptor.Directive),
|
||||
new SourceLocation(9, 0, 9),
|
||||
length: 1));
|
||||
}
|
||||
|
|
@ -117,7 +117,7 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
|
|||
Factory.Markup("</p>")),
|
||||
Factory.Markup(" }")),
|
||||
new RazorError(
|
||||
LegacyResources.FormatUnexpectedDirectiveLiteral(CSharpCodeParser.SectionDirectiveDescriptor.Name, "{"),
|
||||
LegacyResources.FormatUnexpectedDirectiveLiteral(CSharpCodeParser.SectionDirectiveDescriptor.Directive, "{"),
|
||||
new SourceLocation(12, 0, 12),
|
||||
length: 1));
|
||||
}
|
||||
|
|
@ -182,7 +182,7 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
|
|||
new MarkupBlock(
|
||||
Factory.EmptyHtml()))),
|
||||
new RazorError(
|
||||
LegacyResources.FormatParseError_Expected_EndOfBlock_Before_EOF(CSharpCodeParser.SectionDirectiveDescriptor.Name, "}", "{"),
|
||||
LegacyResources.FormatParseError_Expected_EndOfBlock_Before_EOF(CSharpCodeParser.SectionDirectiveDescriptor.Directive, "}", "{"),
|
||||
new SourceLocation(13, 0, 13),
|
||||
length: 1));
|
||||
}
|
||||
|
|
@ -291,7 +291,7 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
|
|||
Factory.Span(SpanKindInternal.Markup, " " + Environment.NewLine, markup: false).Accepts(AcceptedCharactersInternal.AllWhiteSpace)),
|
||||
Factory.EmptyHtml()),
|
||||
new RazorError(
|
||||
LegacyResources.FormatUnexpectedEOFAfterDirective(CSharpCodeParser.SectionDirectiveDescriptor.Name, "{"),
|
||||
LegacyResources.FormatUnexpectedEOFAfterDirective(CSharpCodeParser.SectionDirectiveDescriptor.Directive, "{"),
|
||||
new SourceLocation(18 + Environment.NewLine.Length, 0, 18 + Environment.NewLine.Length),
|
||||
length: 1));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
|
|||
new DirectiveBlock(new DirectiveChunkGenerator(CSharpCodeParser.InheritsDirectiveDescriptor),
|
||||
Factory.MetaCode("inherits").Accepts(AcceptedCharactersInternal.None)),
|
||||
new RazorError(
|
||||
LegacyResources.FormatUnexpectedEOFAfterDirective(CSharpCodeParser.InheritsDirectiveDescriptor.Name, "type"),
|
||||
LegacyResources.FormatUnexpectedEOFAfterDirective(CSharpCodeParser.InheritsDirectiveDescriptor.Directive, "type"),
|
||||
new SourceLocation(8, 0, 8), 1));
|
||||
}
|
||||
|
||||
|
|
@ -37,7 +37,7 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
|
|||
new DirectiveBlock(new DirectiveChunkGenerator(CSharpCodeParser.InheritsDirectiveDescriptor),
|
||||
Factory.MetaCode("inherits").Accepts(AcceptedCharactersInternal.None),
|
||||
Factory.Span(SpanKindInternal.Code, " ", CSharpSymbolType.WhiteSpace).Accepts(AcceptedCharactersInternal.WhiteSpace)),
|
||||
new RazorError(LegacyResources.FormatDirectiveExpectsTypeName(CSharpCodeParser.InheritsDirectiveDescriptor.Name), 24, 0, 24, Environment.NewLine.Length));
|
||||
new RazorError(LegacyResources.FormatDirectiveExpectsTypeName(CSharpCodeParser.InheritsDirectiveDescriptor.Directive), 24, 0, 24, Environment.NewLine.Length));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
|
|
|||
|
|
@ -27,7 +27,7 @@ namespace Microsoft.AspNetCore.Razor.Language
|
|||
Assert.Same(expected, actual);
|
||||
|
||||
var directive = Assert.Single(actual.Directives);
|
||||
Assert.Equal("test", directive.Name);
|
||||
Assert.Equal("test", directive.Directive);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
|
@ -45,7 +45,7 @@ namespace Microsoft.AspNetCore.Razor.Language
|
|||
Assert.IsType<DefaultRazorDirectiveFeature>(actual);
|
||||
|
||||
var directive = Assert.Single(actual.Directives);
|
||||
Assert.Equal("test", directive.Name);
|
||||
Assert.Equal("test", directive.Directive);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@ namespace Microsoft.VisualStudio.RazorExtension.RazorInfo
|
|||
|
||||
var builder = new StringBuilder();
|
||||
builder.Append("@");
|
||||
builder.Append(_directive.Name);
|
||||
builder.Append(_directive.Directive);
|
||||
|
||||
foreach (var token in _directive.Tokens)
|
||||
{
|
||||
|
|
@ -36,7 +36,7 @@ namespace Microsoft.VisualStudio.RazorExtension.RazorInfo
|
|||
|
||||
public string DisplayText { get; }
|
||||
|
||||
public string Name => _directive.Name;
|
||||
public string Name => _directive.Directive;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
Loading…
Reference in New Issue