diff --git a/src/Microsoft.AspNetCore.Razor.Language/Legacy/HtmlMarkupParser.cs b/src/Microsoft.AspNetCore.Razor.Language/Legacy/HtmlMarkupParser.cs
index 0a7d84efd3..c1f21905f3 100644
--- a/src/Microsoft.AspNetCore.Razor.Language/Legacy/HtmlMarkupParser.cs
+++ b/src/Microsoft.AspNetCore.Razor.Language/Legacy/HtmlMarkupParser.cs
@@ -310,9 +310,8 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
else
{
Context.ErrorSink.OnError(
- CurrentStart,
- LegacyResources.ParseError_MarkupBlock_Must_Start_With_Tag,
- CurrentSymbol.Content.Length);
+ RazorDiagnosticFactory.CreateParsing_MarkupBlockMustStartWithTag(
+ new SourceSpan(CurrentStart, CurrentSymbol.Content.Length)));
}
Output(SpanKindInternal.Markup);
}
@@ -472,9 +471,8 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
if (tags.Count == 0)
{
Context.ErrorSink.OnError(
- CurrentStart,
- LegacyResources.ParseError_OuterTagMissingName,
- length: 1 /* end of file */);
+ RazorDiagnosticFactory.CreateParsing_OuterTagMissingName(
+ new SourceSpan(CurrentStart, contentLength: 1 /* end of file */)));
}
return false;
}
@@ -634,9 +632,8 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
if (!seenCloseAngle)
{
Context.ErrorSink.OnError(
- textLocation,
- LegacyResources.ParseError_TextTagCannotContainAttributes,
- length: 4 /* text */);
+ RazorDiagnosticFactory.CreateParsing_TextTagCannotContainAttributes(
+ new SourceSpan(textLocation, contentLength: 4 /* text */)));
Span.EditHandler.AcceptedCharacters = AcceptedCharactersInternal.Any;
RecoverTextTag();
@@ -1089,9 +1086,8 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
Context.Source.Position = bookmark;
NextToken();
Context.ErrorSink.OnError(
- textLocation,
- LegacyResources.ParseError_TextTagCannotContainAttributes,
- length: 4 /* text */);
+ RazorDiagnosticFactory.CreateParsing_TextTagCannotContainAttributes(
+ new SourceSpan(textLocation, contentLength: 4 /* text */)));
RecoverTextTag();
}
@@ -1142,9 +1138,11 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
if (!seenClose)
{
Context.ErrorSink.OnError(
- SourceLocationTracker.Advance(tag.Item2, "<"),
- LegacyResources.FormatParseError_UnfinishedTag(tag.Item1.Content),
- Math.Max(tag.Item1.Content.Length, 1));
+ RazorDiagnosticFactory.CreateParsing_UnfinishedTag(
+ new SourceSpan(
+ SourceLocationTracker.Advance(tag.Item2, "<"),
+ Math.Max(tag.Item1.Content.Length, 1)),
+ tag.Item1.Content));
}
else
{
@@ -1277,9 +1275,9 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
if (!Optional(HtmlSymbolType.CloseAngle))
{
Context.ErrorSink.OnError(
- SourceLocationTracker.Advance(tagStart, ""),
- LegacyResources.FormatParseError_UnfinishedTag(ScriptTagName),
- ScriptTagName.Length);
+ RazorDiagnosticFactory.CreateParsing_UnfinishedTag(
+ new SourceSpan(SourceLocationTracker.Advance(tagStart, ""), ScriptTagName.Length),
+ ScriptTagName));
}
Output(SpanKindInternal.Markup);
}
@@ -1335,16 +1333,17 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
if (currentTag != null)
{
Context.ErrorSink.OnError(
- SourceLocationTracker.Advance(currentTag.Item2, "<"),
- LegacyResources.FormatParseError_MissingEndTag(currentTag.Item1.Content),
- currentTag.Item1.Content.Length);
+ RazorDiagnosticFactory.CreateParsing_MissingEndTag(
+ new SourceSpan(
+ SourceLocationTracker.Advance(currentTag.Item2, "<"),
+ currentTag.Item1.Content.Length),
+ currentTag.Item1.Content));
}
else
{
Context.ErrorSink.OnError(
- SourceLocationTracker.Advance(tagStart, ""),
- LegacyResources.FormatParseError_UnexpectedEndTag(tagName),
- tagName.Length);
+ RazorDiagnosticFactory.CreateParsing_UnexpectedEndTag(
+ new SourceSpan(SourceLocationTracker.Advance(tagStart, ""), tagName.Length), tagName));
}
return false;
}
@@ -1360,9 +1359,11 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
}
var tag = tags.Pop();
Context.ErrorSink.OnError(
- SourceLocationTracker.Advance(tag.Item2, "<"),
- LegacyResources.FormatParseError_MissingEndTag(tag.Item1.Content),
- tag.Item1.Content.Length);
+ RazorDiagnosticFactory.CreateParsing_MissingEndTag(
+ new SourceSpan(
+ SourceLocationTracker.Advance(tag.Item2, "<"),
+ tag.Item1.Content.Length),
+ tag.Item1.Content));
}
else if (complete)
{
diff --git a/src/Microsoft.AspNetCore.Razor.Language/RazorDiagnosticFactory.cs b/src/Microsoft.AspNetCore.Razor.Language/RazorDiagnosticFactory.cs
index 21b977af1b..2f7226fd94 100644
--- a/src/Microsoft.AspNetCore.Razor.Language/RazorDiagnosticFactory.cs
+++ b/src/Microsoft.AspNetCore.Razor.Language/RazorDiagnosticFactory.cs
@@ -250,6 +250,66 @@ namespace Microsoft.AspNetCore.Razor.Language
return RazorDiagnostic.Create(Parsing_InvalidTagHelperLookupText, location, lookupText);
}
+ internal static readonly RazorDiagnosticDescriptor Parsing_MarkupBlockMustStartWithTag =
+ new RazorDiagnosticDescriptor(
+ $"{DiagnosticPrefix}1021",
+ () => LegacyResources.ParseError_MarkupBlock_Must_Start_With_Tag,
+ RazorDiagnosticSeverity.Error);
+ public static RazorDiagnostic CreateParsing_MarkupBlockMustStartWithTag(SourceSpan location)
+ {
+ return RazorDiagnostic.Create(Parsing_MarkupBlockMustStartWithTag, location);
+ }
+
+ internal static readonly RazorDiagnosticDescriptor Parsing_OuterTagMissingName =
+ new RazorDiagnosticDescriptor(
+ $"{DiagnosticPrefix}1022",
+ () => LegacyResources.ParseError_OuterTagMissingName,
+ RazorDiagnosticSeverity.Error);
+ public static RazorDiagnostic CreateParsing_OuterTagMissingName(SourceSpan location)
+ {
+ return RazorDiagnostic.Create(Parsing_OuterTagMissingName, location);
+ }
+
+ internal static readonly RazorDiagnosticDescriptor Parsing_TextTagCannotContainAttributes =
+ new RazorDiagnosticDescriptor(
+ $"{DiagnosticPrefix}1023",
+ () => LegacyResources.ParseError_TextTagCannotContainAttributes,
+ RazorDiagnosticSeverity.Error);
+ public static RazorDiagnostic CreateParsing_TextTagCannotContainAttributes(SourceSpan location)
+ {
+ return RazorDiagnostic.Create(Parsing_TextTagCannotContainAttributes, location);
+ }
+
+ internal static readonly RazorDiagnosticDescriptor Parsing_UnfinishedTag =
+ new RazorDiagnosticDescriptor(
+ $"{DiagnosticPrefix}1024",
+ () => LegacyResources.ParseError_UnfinishedTag,
+ RazorDiagnosticSeverity.Error);
+ public static RazorDiagnostic CreateParsing_UnfinishedTag(SourceSpan location, string tagName)
+ {
+ return RazorDiagnostic.Create(Parsing_UnfinishedTag, location, tagName);
+ }
+
+ internal static readonly RazorDiagnosticDescriptor Parsing_MissingEndTag =
+ new RazorDiagnosticDescriptor(
+ $"{DiagnosticPrefix}1025",
+ () => LegacyResources.ParseError_MissingEndTag,
+ RazorDiagnosticSeverity.Error);
+ public static RazorDiagnostic CreateParsing_MissingEndTag(SourceSpan location, string tagName)
+ {
+ return RazorDiagnostic.Create(Parsing_MissingEndTag, location, tagName);
+ }
+
+ internal static readonly RazorDiagnosticDescriptor Parsing_UnexpectedEndTag =
+ new RazorDiagnosticDescriptor(
+ $"{DiagnosticPrefix}1026",
+ () => LegacyResources.ParseError_UnexpectedEndTag,
+ RazorDiagnosticSeverity.Error);
+ public static RazorDiagnostic CreateParsing_UnexpectedEndTag(SourceSpan location, string tagName)
+ {
+ return RazorDiagnostic.Create(Parsing_UnexpectedEndTag, location, tagName);
+ }
+
#endregion
#region Semantic Errors
diff --git a/test/Microsoft.AspNetCore.Razor.Language.Test/Legacy/CSharpBlockTest.cs b/test/Microsoft.AspNetCore.Razor.Language.Test/Legacy/CSharpBlockTest.cs
index 97ceb54221..4ffce5e293 100644
--- a/test/Microsoft.AspNetCore.Razor.Language.Test/Legacy/CSharpBlockTest.cs
+++ b/test/Microsoft.AspNetCore.Razor.Language.Test/Legacy/CSharpBlockTest.cs
@@ -1145,10 +1145,8 @@ catch(bar) { baz(); }", BlockKindInternal.Statement, SpanKindInternal.Code);
Factory.EmptyHtml()));
var expectedErrors = new RazorDiagnostic[]
{
- RazorDiagnostic.Create(new RazorError(
- @"End of file or an unexpected character was reached before the ""span"" tag could be parsed. Elements inside markup blocks must be complete. They must either be self-closing (""
"") or have matching end tags (""
Hello
""). If you intended to display a ""<"" character, use the ""<"" HTML entity.", - new SourceLocation(2, 0, 2), - length: 4)), + RazorDiagnosticFactory.CreateParsing_UnfinishedTag( + new SourceSpan(new SourceLocation(2, 0, 2), contentLength: 4), "span"), RazorDiagnosticFactory.CreateParsing_ExpectedEndOfBlockBeforeEOF( new SourceSpan(SourceLocation.Zero, contentLength: 1), LegacyResources.BlockName_Code, "}", "{"), }; diff --git a/test/Microsoft.AspNetCore.Razor.Language.Test/Legacy/CSharpRazorCommentsTest.cs b/test/Microsoft.AspNetCore.Razor.Language.Test/Legacy/CSharpRazorCommentsTest.cs index 9bbb28d55d..6afe3662e4 100644 --- a/test/Microsoft.AspNetCore.Razor.Language.Test/Legacy/CSharpRazorCommentsTest.cs +++ b/test/Microsoft.AspNetCore.Razor.Language.Test/Legacy/CSharpRazorCommentsTest.cs @@ -149,14 +149,10 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy .Accepts(AcceptedCharactersInternal.None)), Factory.Markup(Environment.NewLine).With(SpanChunkGenerator.Null), Factory.Markup("}")))), - RazorDiagnostic.Create(new RazorError( - LegacyResources.ParseError_TextTagCannotContainAttributes, - new SourceLocation(7 + Environment.NewLine.Length, 1, 5), - length: 4)), - RazorDiagnostic.Create(new RazorError( - LegacyResources.FormatParseError_MissingEndTag("text"), - new SourceLocation(7 + Environment.NewLine.Length, 1, 5), - length: 4)), + RazorDiagnosticFactory.CreateParsing_TextTagCannotContainAttributes( + new SourceSpan(new SourceLocation(7 + Environment.NewLine.Length, 1, 5), contentLength: 4)), + RazorDiagnosticFactory.CreateParsing_MissingEndTag( + new SourceSpan(new SourceLocation(7 + Environment.NewLine.Length, 1, 5), contentLength: 4), "text"), RazorDiagnosticFactory.CreateParsing_ExpectedEndOfBlockBeforeEOF( new SourceSpan(new SourceLocation(1, 0, 1), contentLength: 1), LegacyResources.BlockName_Code, "}", "{")); } diff --git a/test/Microsoft.AspNetCore.Razor.Language.Test/Legacy/HtmlBlockTest.cs b/test/Microsoft.AspNetCore.Razor.Language.Test/Legacy/HtmlBlockTest.cs index 275364706a..c886e21a7b 100644 --- a/test/Microsoft.AspNetCore.Razor.Language.Test/Legacy/HtmlBlockTest.cs +++ b/test/Microsoft.AspNetCore.Razor.Language.Test/Legacy/HtmlBlockTest.cs @@ -79,10 +79,8 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy designTime: true, expectedErrors: new[] { - RazorDiagnostic.Create(new RazorError( - LegacyResources.FormatParseError_UnexpectedEndTag("html"), - new SourceLocation(5 + Environment.NewLine.Length * 2, 2, 2), - length: 4)), + RazorDiagnosticFactory.CreateParsing_UnexpectedEndTag( + new SourceSpan(new SourceLocation(5 + Environment.NewLine.Length * 2, 2, 2), contentLength: 4), "html"), RazorDiagnosticFactory.CreateParsing_ExpectedEndOfBlockBeforeEOF( new SourceSpan(new SourceLocation(1, 0, 1), contentLength: 1), LegacyResources.BlockName_Code, "}", "{"), }); @@ -97,10 +95,8 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy new MarkupTagBlock( Factory.Markup($"< {Environment.NewLine} "))), designTime: true, - expectedErrors: RazorDiagnostic.Create(new RazorError( - LegacyResources.FormatParseError_UnfinishedTag(string.Empty), - new SourceLocation(1, 0, 1), - length: 1))); + expectedErrors: RazorDiagnosticFactory.CreateParsing_UnfinishedTag( + new SourceSpan(new SourceLocation(1, 0, 1), contentLength: 1), string.Empty)); } [Fact] @@ -330,10 +326,8 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy new MarkupBlock( new MarkupTagBlock( Factory.Markup("", AcceptedCharactersInternal.None),
BlockFactory.MarkupTagBlock(">", AcceptedCharactersInternal.None),
Factory.Markup(" ").Accepts(AcceptedCharactersInternal.None)),
- RazorDiagnostic.Create(new RazorError(
- LegacyResources.FormatParseError_MissingEndTag("p"),
- new SourceLocation(1, 0, 1),
- length: 1)));
+ RazorDiagnosticFactory.CreateParsing_MissingEndTag(
+ new SourceSpan(new SourceLocation(1, 0, 1), contentLength: 1), "p"));
}
[Fact]
diff --git a/test/Microsoft.AspNetCore.Razor.Language.Test/Legacy/TagHelperBlockRewriterTest.cs b/test/Microsoft.AspNetCore.Razor.Language.Test/Legacy/TagHelperBlockRewriterTest.cs
index 1996c68455..63c6ac1677 100644
--- a/test/Microsoft.AspNetCore.Razor.Language.Test/Legacy/TagHelperBlockRewriterTest.cs
+++ b/test/Microsoft.AspNetCore.Razor.Language.Test/Legacy/TagHelperBlockRewriterTest.cs
@@ -742,9 +742,8 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
absoluteIndex: 3, lineIndex: 0 , columnIndex: 3, length: 30)),
RazorDiagnosticFactory.CreateParsing_ExpectedEndOfBlockBeforeEOF(
new SourceSpan(new SourceLocation(4, 0, 4), contentLength: 1), "do", "}", "{"),
- RazorDiagnostic.Create(new RazorError(
- LegacyResources.FormatParseError_UnexpectedEndTag("p"),
- absoluteIndex: 31, lineIndex: 0, columnIndex: 31, length: 1))
+ RazorDiagnosticFactory.CreateParsing_UnexpectedEndTag(
+ new SourceSpan(filePath: null, absoluteIndex: 31, lineIndex: 0, characterIndex: 31, length: 1), "p")
}
},
{
diff --git a/test/Microsoft.AspNetCore.Razor.Language.Test/Legacy/TagHelperParseTreeRewriterTest.cs b/test/Microsoft.AspNetCore.Razor.Language.Test/Legacy/TagHelperParseTreeRewriterTest.cs
index 2a77d0c83e..80379a8aba 100644
--- a/test/Microsoft.AspNetCore.Razor.Language.Test/Legacy/TagHelperParseTreeRewriterTest.cs
+++ b/test/Microsoft.AspNetCore.Razor.Language.Test/Legacy/TagHelperParseTreeRewriterTest.cs
@@ -2343,9 +2343,6 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
{
var factory = new SpanFactory();
var blockFactory = new BlockFactory(factory);
- var errorFormatNormalUnclosed =
- "The \"{0}\" element was not closed. All elements must be either self-closing or have a " +
- "matching end tag.";
Func Hello Hello
\") or have matching end tags (\"
\") or have matching end tags (\"