diff --git a/src/Microsoft.AspNetCore.Mvc.Razor.Extensions/ModelDirective.cs b/src/Microsoft.AspNetCore.Mvc.Razor.Extensions/ModelDirective.cs index a2da8212f2..ac757f129f 100644 --- a/src/Microsoft.AspNetCore.Mvc.Razor.Extensions/ModelDirective.cs +++ b/src/Microsoft.AspNetCore.Mvc.Razor.Extensions/ModelDirective.cs @@ -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); } diff --git a/src/Microsoft.AspNetCore.Razor.Language/DefaultDirectiveIRPass.cs b/src/Microsoft.AspNetCore.Razor.Language/DefaultDirectiveIRPass.cs index a81056ce9d..d441d85adc 100644 --- a/src/Microsoft.AspNetCore.Razor.Language/DefaultDirectiveIRPass.cs +++ b/src/Microsoft.AspNetCore.Razor.Language/DefaultDirectiveIRPass.cs @@ -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); } diff --git a/src/Microsoft.AspNetCore.Razor.Language/DefaultDirectiveSyntaxTreePass.cs b/src/Microsoft.AspNetCore.Razor.Language/DefaultDirectiveSyntaxTreePass.cs index 69869f6492..11397495e1 100644 --- a/src/Microsoft.AspNetCore.Razor.Language/DefaultDirectiveSyntaxTreePass.cs +++ b/src/Microsoft.AspNetCore.Razor.Language/DefaultDirectiveSyntaxTreePass.cs @@ -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), diff --git a/src/Microsoft.AspNetCore.Razor.Language/DefaultRazorIRLoweringPhase.cs b/src/Microsoft.AspNetCore.Razor.Language/DefaultRazorIRLoweringPhase.cs index ac6c15dca2..cd941a851f 100644 --- a/src/Microsoft.AspNetCore.Razor.Language/DefaultRazorIRLoweringPhase.cs +++ b/src/Microsoft.AspNetCore.Razor.Language/DefaultRazorIRLoweringPhase.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), }); diff --git a/src/Microsoft.AspNetCore.Razor.Language/DirectiveDescriptor.cs b/src/Microsoft.AspNetCore.Razor.Language/DirectiveDescriptor.cs index c9d401fde8..afb315948f 100644 --- a/src/Microsoft.AspNetCore.Razor.Language/DirectiveDescriptor.cs +++ b/src/Microsoft.AspNetCore.Razor.Language/DirectiveDescriptor.cs @@ -7,107 +7,185 @@ using System.Linq; namespace Microsoft.AspNetCore.Razor.Language { + /// + /// A descriptor type for a directive that can be parsed by the Razor parser. + /// public abstract class DirectiveDescriptor { - public abstract string Name { get; } + /// + /// Gets the description of the directive. + /// + /// + /// The description is used for information purposes, and has no effect on parsing. + /// + public abstract string Description { get; } + /// + /// Gets the directive keyword without the leading @ token. + /// + public abstract string Directive { get; } + + /// + /// Gets the display name of the directive. + /// + /// + /// The display name is used for information purposes, and has no effect on parsing. + /// + public abstract string DisplayName { get; } + + /// + /// Gets the kind of the directive. The kind determines whether or not a directive has an associated block. + /// public abstract DirectiveKind Kind { get; } + /// + /// Gets the list of directive tokens that can follow the directive keyword. + /// public abstract IReadOnlyList Tokens { get; } - public static DirectiveDescriptor CreateDirective(string name, DirectiveKind kind) + /// + /// Creates a new . + /// + /// The directive keyword. + /// The directive kind. + /// A for the created directive. + 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 configure) + /// + /// Creates a new . + /// + /// The directive keyword. + /// The directive kind. + /// A configuration delegate for the directive. + /// A for the created directive. + public static DirectiveDescriptor CreateDirective(string directive, DirectiveKind kind, Action 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) + /// + /// Creates a new with set to + /// + /// The directive keyword. + /// A for the created directive. + 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 configure) + /// + /// Creates a new with set to + /// + /// The directive keyword. + /// A configuration delegate for the directive. + /// A for the created directive. + public static DirectiveDescriptor CreateSingleLineDirective(string directive, Action 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) + /// + /// Creates a new with set to + /// + /// The directive keyword. + /// A for the created directive. + 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 configure) + /// + /// Creates a new with set to + /// + /// The directive keyword. + /// A configuration delegate for the directive. + /// A for the created directive. + public static DirectiveDescriptor CreateRazorBlockDirective(string directive, Action 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) + /// + /// Creates a new with set to + /// + /// The directive keyword. + /// A for the created directive. + 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 configure) + /// + /// Creates a new with set to + /// + /// The directive keyword. + /// A configuration delegate for the directive. + /// A for the created directive. + public static DirectiveDescriptor CreateCodeBlockDirective(string directive, Action 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(); } - 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; } diff --git a/src/Microsoft.AspNetCore.Razor.Language/DirectiveDescriptorComparer.cs b/src/Microsoft.AspNetCore.Razor.Language/DirectiveDescriptorComparer.cs index d72e36cf0c..c3a9590231 100644 --- a/src/Microsoft.AspNetCore.Razor.Language/DirectiveDescriptorComparer.cs +++ b/src/Microsoft.AspNetCore.Razor.Language/DirectiveDescriptorComparer.cs @@ -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; diff --git a/src/Microsoft.AspNetCore.Razor.Language/IDirectiveDescriptorBuilder.cs b/src/Microsoft.AspNetCore.Razor.Language/IDirectiveDescriptorBuilder.cs index fd60d215a7..c8e79d8d05 100644 --- a/src/Microsoft.AspNetCore.Razor.Language/IDirectiveDescriptorBuilder.cs +++ b/src/Microsoft.AspNetCore.Razor.Language/IDirectiveDescriptorBuilder.cs @@ -5,14 +5,40 @@ using System.Collections.Generic; namespace Microsoft.AspNetCore.Razor.Language { + /// + /// A builder interface for configuring a . + /// public interface IDirectiveDescriptorBuilder { - string Name { get; } + /// + /// Gets or sets the description of the directive. + /// + string Description { get; set; } + /// + /// Gets the directive keyword. + /// + string Directive { get; } + + /// + /// Gets or sets the display name of the directive. + /// + string DisplayName { get; set; } + + /// + /// Gets the directive kind. + /// DirectiveKind Kind { get; } + /// + /// Gets a list of the directive tokens. + /// IList Tokens { get; } + /// + /// Creates a based on the current property values of the builder. + /// + /// The created . DirectiveDescriptor Build(); } } diff --git a/src/Microsoft.AspNetCore.Razor.Language/Legacy/CSharpCodeParser.cs b/src/Microsoft.AspNetCore.Razor.Language/Legacy/CSharpCodeParser.cs index 6dca3d5b6d..e4b49a9784 100644 --- a/src/Microsoft.AspNetCore.Razor.Language/Legacy/CSharpCodeParser.cs +++ b/src/Microsoft.AspNetCore.Razor.Language/Legacy/CSharpCodeParser.cs @@ -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 diff --git a/src/Microsoft.AspNetCore.Razor.Language/Properties/Resources.Designer.cs b/src/Microsoft.AspNetCore.Razor.Language/Properties/Resources.Designer.cs index fbae6b1aad..28940691d1 100644 --- a/src/Microsoft.AspNetCore.Razor.Language/Properties/Resources.Designer.cs +++ b/src/Microsoft.AspNetCore.Razor.Language/Properties/Resources.Designer.cs @@ -389,18 +389,18 @@ namespace Microsoft.AspNetCore.Razor.Language => string.Format(CultureInfo.CurrentCulture, GetString("InvalidOperation_SpanIsNotChangeOwner"), p0, p1); /// - /// 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. /// - internal static string DirectiveDescriptor_InvalidDirectiveName + internal static string DirectiveDescriptor_InvalidDirectiveKeyword { - get => GetString("DirectiveDescriptor_InvalidDirectiveName"); + get => GetString("DirectiveDescriptor_InvalidDirectiveKeyword"); } /// - /// 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. /// - 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); /// /// The feature must be initialized by setting the '{0}' property. diff --git a/src/Microsoft.AspNetCore.Razor.Language/Resources.resx b/src/Microsoft.AspNetCore.Razor.Language/Resources.resx index 3de7f278a6..610215c0f5 100644 --- a/src/Microsoft.AspNetCore.Razor.Language/Resources.resx +++ b/src/Microsoft.AspNetCore.Razor.Language/Resources.resx @@ -198,8 +198,8 @@ The node '{0}' is not the owner of change '{1}'. - - 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. The feature must be initialized by setting the '{0}' property. diff --git a/test/Microsoft.AspNetCore.Razor.Language.Test/DefaultRazorParsingPhaseTest.cs b/test/Microsoft.AspNetCore.Razor.Language.Test/DefaultRazorParsingPhaseTest.cs index 66eed77388..7dbbfde435 100644 --- a/test/Microsoft.AspNetCore.Razor.Language.Test/DefaultRazorParsingPhaseTest.cs +++ b/test/Microsoft.AspNetCore.Razor.Language.Test/DefaultRazorParsingPhaseTest.cs @@ -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 diff --git a/test/Microsoft.AspNetCore.Razor.Language.Test/DirectiveDescriptorTest.cs b/test/Microsoft.AspNetCore.Razor.Language.Test/DirectiveDescriptorTest.cs index a57cc88966..a5bb3c8434 100644 --- a/test/Microsoft.AspNetCore.Razor.Language.Test/DirectiveDescriptorTest.cs +++ b/test/Microsoft.AspNetCore.Razor.Language.Test/DirectiveDescriptorTest.cs @@ -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(() => 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(() => 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] diff --git a/test/Microsoft.AspNetCore.Razor.Language.Test/Legacy/CSharpAutoCompleteTest.cs b/test/Microsoft.AspNetCore.Razor.Language.Test/Legacy/CSharpAutoCompleteTest.cs index 58ee104f94..604b863393 100644 --- a/test/Microsoft.AspNetCore.Razor.Language.Test/Legacy/CSharpAutoCompleteTest.cs +++ b/test/Microsoft.AspNetCore.Razor.Language.Test/Legacy/CSharpAutoCompleteTest.cs @@ -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)); } diff --git a/test/Microsoft.AspNetCore.Razor.Language.Test/Legacy/CSharpSectionTest.cs b/test/Microsoft.AspNetCore.Razor.Language.Test/Legacy/CSharpSectionTest.cs index e0657c1999..1d9fdd6aad 100644 --- a/test/Microsoft.AspNetCore.Razor.Language.Test/Legacy/CSharpSectionTest.cs +++ b/test/Microsoft.AspNetCore.Razor.Language.Test/Legacy/CSharpSectionTest.cs @@ -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("

")), 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("

")), 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)); } diff --git a/test/Microsoft.AspNetCore.Razor.Language.Test/Legacy/CSharpSpecialBlockTest.cs b/test/Microsoft.AspNetCore.Razor.Language.Test/Legacy/CSharpSpecialBlockTest.cs index e51227991f..f9e2eea5ef 100644 --- a/test/Microsoft.AspNetCore.Razor.Language.Test/Legacy/CSharpSpecialBlockTest.cs +++ b/test/Microsoft.AspNetCore.Razor.Language.Test/Legacy/CSharpSpecialBlockTest.cs @@ -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] diff --git a/test/Microsoft.AspNetCore.Razor.Language.Test/RazorEngineBuilderExtensionsTest.cs b/test/Microsoft.AspNetCore.Razor.Language.Test/RazorEngineBuilderExtensionsTest.cs index c2ba72b477..a55d3634f1 100644 --- a/test/Microsoft.AspNetCore.Razor.Language.Test/RazorEngineBuilderExtensionsTest.cs +++ b/test/Microsoft.AspNetCore.Razor.Language.Test/RazorEngineBuilderExtensionsTest.cs @@ -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(actual); var directive = Assert.Single(actual.Directives); - Assert.Equal("test", directive.Name); + Assert.Equal("test", directive.Directive); } [Fact] diff --git a/tooling/Microsoft.VisualStudio.RazorExtension/RazorInfo/DirectiveViewModel.cs b/tooling/Microsoft.VisualStudio.RazorExtension/RazorInfo/DirectiveViewModel.cs index 9e1fbddac6..552c9d5131 100644 --- a/tooling/Microsoft.VisualStudio.RazorExtension/RazorInfo/DirectiveViewModel.cs +++ b/tooling/Microsoft.VisualStudio.RazorExtension/RazorInfo/DirectiveViewModel.cs @@ -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 \ No newline at end of file