diff --git a/src/Microsoft.AspNetCore.Razor.Evolution/DefaultDirectiveSyntaxTreePass.cs b/src/Microsoft.AspNetCore.Razor.Evolution/DefaultDirectiveSyntaxTreePass.cs index db5383cd62..6686ca4f14 100644 --- a/src/Microsoft.AspNetCore.Razor.Evolution/DefaultDirectiveSyntaxTreePass.cs +++ b/src/Microsoft.AspNetCore.Razor.Evolution/DefaultDirectiveSyntaxTreePass.cs @@ -20,7 +20,10 @@ namespace Microsoft.AspNetCore.Razor.Evolution if (errorSink.Errors.Count > 0) { - var combinedErrors = syntaxTree.Diagnostics.Concat(errorSink.Errors).ToList(); + // Temporary code while we're still using legacy diagnostics in the SyntaxTree. + var errors = errorSink.Errors.Select(error => RazorDiagnostic.Create(error)); + + var combinedErrors = syntaxTree.Diagnostics.Concat(errors); syntaxTree = RazorSyntaxTree.Create(syntaxTree.Root, syntaxTree.Source, combinedErrors, syntaxTree.Options); } diff --git a/src/Microsoft.AspNetCore.Razor.Evolution/DefaultRazorCSharpLoweringPhase.cs b/src/Microsoft.AspNetCore.Razor.Evolution/DefaultRazorCSharpLoweringPhase.cs index d03a2d852b..cdb76b39bf 100644 --- a/src/Microsoft.AspNetCore.Razor.Evolution/DefaultRazorCSharpLoweringPhase.cs +++ b/src/Microsoft.AspNetCore.Razor.Evolution/DefaultRazorCSharpLoweringPhase.cs @@ -2,10 +2,11 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; +using System.Collections.Generic; using System.Linq; using Microsoft.AspNetCore.Razor.Evolution.CodeGeneration; -using Microsoft.AspNetCore.Razor.Evolution.Legacy; using Microsoft.AspNetCore.Razor.Evolution.Intermediate; +using Microsoft.AspNetCore.Razor.Evolution.Legacy; namespace Microsoft.AspNetCore.Razor.Evolution { @@ -60,12 +61,17 @@ namespace Microsoft.AspNetCore.Razor.Evolution renderer.VisitDocument(irDocument); - var combinedErrors = syntaxTree.Diagnostics.Concat(renderingContext.ErrorSink.Errors).ToList(); + var diagnostics = new List(); + diagnostics.AddRange(syntaxTree.Diagnostics); + + // Temporary code while we're still using legacy diagnostics in the SyntaxTree. + diagnostics.AddRange(renderingContext.ErrorSink.Errors.Select(error => RazorDiagnostic.Create(error))); + var csharpDocument = new RazorCSharpDocument() { GeneratedCode = renderingContext.Writer.GenerateCode(), LineMappings = renderingContext.LineMappings, - Diagnostics = combinedErrors + Diagnostics = diagnostics }; codeDocument.SetCSharpDocument(csharpDocument); diff --git a/src/Microsoft.AspNetCore.Razor.Evolution/DefaultRazorSyntaxTree.cs b/src/Microsoft.AspNetCore.Razor.Evolution/DefaultRazorSyntaxTree.cs index 51d74f66ca..66631bb545 100644 --- a/src/Microsoft.AspNetCore.Razor.Evolution/DefaultRazorSyntaxTree.cs +++ b/src/Microsoft.AspNetCore.Razor.Evolution/DefaultRazorSyntaxTree.cs @@ -11,7 +11,7 @@ namespace Microsoft.AspNetCore.Razor.Evolution public DefaultRazorSyntaxTree( Block root, RazorSourceDocument source, - IReadOnlyList diagnostics, + IReadOnlyList diagnostics, RazorParserOptions options) { Root = root; @@ -20,7 +20,7 @@ namespace Microsoft.AspNetCore.Razor.Evolution Options = options; } - internal override IReadOnlyList Diagnostics { get; } + public override IReadOnlyList Diagnostics { get; } public override RazorParserOptions Options { get; } diff --git a/src/Microsoft.AspNetCore.Razor.Evolution/Legacy/ErrorSink.cs b/src/Microsoft.AspNetCore.Razor.Evolution/Legacy/ErrorSink.cs index 78157ea37f..7a37ab3159 100644 --- a/src/Microsoft.AspNetCore.Razor.Evolution/Legacy/ErrorSink.cs +++ b/src/Microsoft.AspNetCore.Razor.Evolution/Legacy/ErrorSink.cs @@ -8,7 +8,7 @@ namespace Microsoft.AspNetCore.Razor.Evolution.Legacy /// /// Used to manage s encountered during the Razor parsing phase. /// - public class ErrorSink + internal class ErrorSink { private readonly List _errors; diff --git a/src/Microsoft.AspNetCore.Razor.Evolution/Legacy/ITagHelperDescriptorResolver.cs b/src/Microsoft.AspNetCore.Razor.Evolution/Legacy/ITagHelperDescriptorResolver.cs index af6c394de6..bec172d6f0 100644 --- a/src/Microsoft.AspNetCore.Razor.Evolution/Legacy/ITagHelperDescriptorResolver.cs +++ b/src/Microsoft.AspNetCore.Razor.Evolution/Legacy/ITagHelperDescriptorResolver.cs @@ -10,6 +10,6 @@ namespace Microsoft.AspNetCore.Razor.Evolution.Legacy /// public interface ITagHelperDescriptorResolver { - IEnumerable Resolve(ErrorSink errorSink); + IEnumerable Resolve(IList errors); } } \ No newline at end of file diff --git a/src/Microsoft.AspNetCore.Razor.Evolution/Legacy/RazorError.cs b/src/Microsoft.AspNetCore.Razor.Evolution/Legacy/RazorError.cs index de7f83791f..be4358b2db 100644 --- a/src/Microsoft.AspNetCore.Razor.Evolution/Legacy/RazorError.cs +++ b/src/Microsoft.AspNetCore.Razor.Evolution/Legacy/RazorError.cs @@ -7,7 +7,7 @@ using Microsoft.Extensions.Internal; namespace Microsoft.AspNetCore.Razor.Evolution.Legacy { - public class RazorError : IEquatable + internal class RazorError : IEquatable { internal static readonly RazorError[] EmptyArray = new RazorError[0]; diff --git a/src/Microsoft.AspNetCore.Razor.Evolution/Legacy/RazorParser.cs b/src/Microsoft.AspNetCore.Razor.Evolution/Legacy/RazorParser.cs index 2da299bf5e..c9734e7c02 100644 --- a/src/Microsoft.AspNetCore.Razor.Evolution/Legacy/RazorParser.cs +++ b/src/Microsoft.AspNetCore.Razor.Evolution/Legacy/RazorParser.cs @@ -2,6 +2,7 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; +using System.Linq; namespace Microsoft.AspNetCore.Razor.Evolution.Legacy { @@ -47,7 +48,10 @@ namespace Microsoft.AspNetCore.Razor.Evolution.Legacy markupParser.ParseDocument(); var root = context.Builder.Build(); - var diagnostics = context.ErrorSink.Errors; + + // Temporary code while we're still using legacy diagnostics in the SyntaxTree. + var diagnostics = context.ErrorSink.Errors.Select(error => RazorDiagnostic.Create(error)); + return RazorSyntaxTree.Create(root, source, diagnostics, Options); } } diff --git a/src/Microsoft.AspNetCore.Razor.Evolution/RazorCSharpDocument.cs b/src/Microsoft.AspNetCore.Razor.Evolution/RazorCSharpDocument.cs index ab0b396337..4663ec9b09 100644 --- a/src/Microsoft.AspNetCore.Razor.Evolution/RazorCSharpDocument.cs +++ b/src/Microsoft.AspNetCore.Razor.Evolution/RazorCSharpDocument.cs @@ -12,6 +12,6 @@ namespace Microsoft.AspNetCore.Razor.Evolution public IReadOnlyList LineMappings { get; set; } - public IReadOnlyList Diagnostics { get; set; } + public IReadOnlyList Diagnostics { get; set; } } } diff --git a/src/Microsoft.AspNetCore.Razor.Evolution/RazorDiagnostic.cs b/src/Microsoft.AspNetCore.Razor.Evolution/RazorDiagnostic.cs index 5724e134ee..465adf40fb 100644 --- a/src/Microsoft.AspNetCore.Razor.Evolution/RazorDiagnostic.cs +++ b/src/Microsoft.AspNetCore.Razor.Evolution/RazorDiagnostic.cs @@ -68,7 +68,7 @@ namespace Microsoft.AspNetCore.Razor.Evolution string IFormattable.ToString(string ignore, IFormatProvider formatProvider) { // Our indices are 0-based, but we we want to print them as 1-based. - return string.Format($"{Span.FilePath}({Span.LineIndex + 1},{Span.CharacterIndex + 1}): {Severity} {Id}: {GetMessage(formatProvider)}"); + return $"{Span.FilePath}({Span.LineIndex + 1},{Span.CharacterIndex + 1}): {Severity} {Id}: {GetMessage(formatProvider)}"; } } } diff --git a/src/Microsoft.AspNetCore.Razor.Evolution/RazorSyntaxTree.cs b/src/Microsoft.AspNetCore.Razor.Evolution/RazorSyntaxTree.cs index 9ec849c11e..e5f56bd97d 100644 --- a/src/Microsoft.AspNetCore.Razor.Evolution/RazorSyntaxTree.cs +++ b/src/Microsoft.AspNetCore.Razor.Evolution/RazorSyntaxTree.cs @@ -12,7 +12,7 @@ namespace Microsoft.AspNetCore.Razor.Evolution internal static RazorSyntaxTree Create( Block root, RazorSourceDocument source, - IEnumerable diagnostics, + IEnumerable diagnostics, RazorParserOptions options) { if (root == null) @@ -35,7 +35,7 @@ namespace Microsoft.AspNetCore.Razor.Evolution throw new ArgumentNullException(nameof(options)); } - return new DefaultRazorSyntaxTree(root, source, new List(diagnostics), options); + return new DefaultRazorSyntaxTree(root, source, new List(diagnostics), options); } public static RazorSyntaxTree Parse(RazorSourceDocument source) @@ -59,7 +59,7 @@ namespace Microsoft.AspNetCore.Razor.Evolution return parser.Parse(source); } - internal abstract IReadOnlyList Diagnostics { get; } + public abstract IReadOnlyList Diagnostics { get; } public abstract RazorParserOptions Options { get; } diff --git a/src/Microsoft.AspNetCore.Razor.Evolution/TagHelperBinderSyntaxTreePass.cs b/src/Microsoft.AspNetCore.Razor.Evolution/TagHelperBinderSyntaxTreePass.cs index 7c839c6b9d..0b229ddeaa 100644 --- a/src/Microsoft.AspNetCore.Razor.Evolution/TagHelperBinderSyntaxTreePass.cs +++ b/src/Microsoft.AspNetCore.Razor.Evolution/TagHelperBinderSyntaxTreePass.cs @@ -45,35 +45,36 @@ namespace Microsoft.AspNetCore.Razor.Evolution visitor.VisitBlock(syntaxTree.Root); + var errorList = new List(); + var descriptors = (IReadOnlyList)resolver.Resolve(errorList).ToList(); + var errorSink = new ErrorSink(); var directives = visitor.Directives; - var descriptors = (IReadOnlyList)resolver.Resolve(errorSink).ToList(); - descriptors = ProcessDirectives(directives, descriptors, errorSink); + var root = syntaxTree.Root; + if (descriptors.Count == 0) { - // No TagHelpers, add any errors if we have them. - if (errorSink.Errors.Count > 0) + if (errorSink.Errors.Count == 0 && errorList.Count == 0) { - var errors = CombineErrors(syntaxTree.Diagnostics, errorSink.Errors); - return RazorSyntaxTree.Create(syntaxTree.Root, syntaxTree.Source, errors, syntaxTree.Options); + // No TagHelpers and errors, no op. + return syntaxTree; } - - return syntaxTree; + } + else + { + var descriptorProvider = new TagHelperDescriptorProvider(descriptors); + var rewriter = new TagHelperParseTreeRewriter(descriptorProvider); + root = rewriter.Rewrite(root, errorSink); } - var descriptorProvider = new TagHelperDescriptorProvider(descriptors); - var rewriter = new TagHelperParseTreeRewriter(descriptorProvider); - var rewrittenRoot = rewriter.Rewrite(syntaxTree.Root, errorSink); - var diagnostics = syntaxTree.Diagnostics; + // Temporary code while we're still using legacy diagnostics in the SyntaxTree. + errorList.AddRange(errorSink.Errors.Select(error => RazorDiagnostic.Create(error))); - if (errorSink.Errors.Count > 0) - { - diagnostics = CombineErrors(diagnostics, errorSink.Errors); - } + var diagnostics = CombineErrors(syntaxTree.Diagnostics, errorList); - var newSyntaxTree = RazorSyntaxTree.Create(rewrittenRoot, syntaxTree.Source, diagnostics, syntaxTree.Options); + var newSyntaxTree = RazorSyntaxTree.Create(root, syntaxTree.Source, diagnostics, syntaxTree.Options); return newSyntaxTree; } @@ -299,9 +300,9 @@ namespace Microsoft.AspNetCore.Razor.Evolution return normalizeEmptyStringLength; } - private IReadOnlyList CombineErrors(IReadOnlyList errors1, IReadOnlyList errors2) + private IReadOnlyList CombineErrors(IReadOnlyList errors1, IReadOnlyList errors2) { - var combinedErrors = new List(errors1.Count + errors2.Count); + var combinedErrors = new List(errors1.Count + errors2.Count); combinedErrors.AddRange(errors1); combinedErrors.AddRange(errors2); diff --git a/src/Microsoft.CodeAnalysis.Razor/DefaultTagHelperFeature.cs b/src/Microsoft.CodeAnalysis.Razor/DefaultTagHelperFeature.cs index 3e072f6255..de2e541997 100644 --- a/src/Microsoft.CodeAnalysis.Razor/DefaultTagHelperFeature.cs +++ b/src/Microsoft.CodeAnalysis.Razor/DefaultTagHelperFeature.cs @@ -43,7 +43,7 @@ namespace Microsoft.CodeAnalysis.Razor { _referenceFeature = referenceFeature; } - public IEnumerable Resolve(ErrorSink errorSink) + public IEnumerable Resolve(IList errors) { var compilation = CSharpCompilation.Create("__TagHelpers", references: _referenceFeature.References); return TagHelpers.GetTagHelpers(compilation); diff --git a/test/Microsoft.AspNetCore.Razor.Evolution.Test/DefaultDirectiveSyntaxTreePassTest.cs b/test/Microsoft.AspNetCore.Razor.Evolution.Test/DefaultDirectiveSyntaxTreePassTest.cs index 0085646fbf..ab5e66332b 100644 --- a/test/Microsoft.AspNetCore.Razor.Evolution.Test/DefaultDirectiveSyntaxTreePassTest.cs +++ b/test/Microsoft.AspNetCore.Razor.Evolution.Test/DefaultDirectiveSyntaxTreePassTest.cs @@ -1,8 +1,9 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -using Microsoft.AspNetCore.Razor.Evolution.Legacy; using System; +using System.Linq; +using Microsoft.AspNetCore.Razor.Evolution.Legacy; using Xunit; namespace Microsoft.AspNetCore.Razor.Evolution @@ -49,6 +50,7 @@ namespace Microsoft.AspNetCore.Razor.Evolution new SourceLocation(41 + Environment.NewLine.Length * 4, 4, 4), length: 8), }; + var expectedDiagnostics = expectedErrors.Select(error => RazorDiagnostic.Create(error)); var engine = RazorEngine.Create(); var pass = new DefaultDirectiveSyntaxTreePass() { @@ -72,7 +74,7 @@ namespace Microsoft.AspNetCore.Razor.Evolution // Assert Assert.Empty(originalTree.Diagnostics); Assert.NotSame(originalTree, outputTree); - Assert.Equal(expectedErrors, outputTree.Diagnostics); + Assert.Equal(expectedDiagnostics, outputTree.Diagnostics); } [Fact] @@ -90,6 +92,7 @@ namespace Microsoft.AspNetCore.Razor.Evolution new SourceLocation(41 + Environment.NewLine.Length * 4, 4, 4), length: 8), }; + var expectedDiagnostics = expectedErrors.Select(error => RazorDiagnostic.Create(error)).ToList(); var engine = RazorEngine.Create(); var pass = new DefaultDirectiveSyntaxTreePass() { @@ -109,7 +112,7 @@ namespace Microsoft.AspNetCore.Razor.Evolution var erroredOriginalTree = RazorSyntaxTree.Create( originalTree.Root, originalTree.Source, - new[] { expectedErrors[0] }, + new[] { expectedDiagnostics[0] }, originalTree.Options); // Act @@ -118,7 +121,7 @@ namespace Microsoft.AspNetCore.Razor.Evolution // Assert Assert.Empty(originalTree.Diagnostics); Assert.NotSame(originalTree, outputTree); - Assert.Equal(expectedErrors, outputTree.Diagnostics); + Assert.Equal(expectedDiagnostics, outputTree.Diagnostics); } } } diff --git a/test/Microsoft.AspNetCore.Razor.Evolution.Test/IntegrationTests/BasicIntegrationTest.cs b/test/Microsoft.AspNetCore.Razor.Evolution.Test/IntegrationTests/BasicIntegrationTest.cs index 595334297e..7caa0a4865 100644 --- a/test/Microsoft.AspNetCore.Razor.Evolution.Test/IntegrationTests/BasicIntegrationTest.cs +++ b/test/Microsoft.AspNetCore.Razor.Evolution.Test/IntegrationTests/BasicIntegrationTest.cs @@ -80,18 +80,18 @@ namespace Microsoft.AspNetCore.Razor.Evolution.IntegrationTests var document = RazorCodeDocument.Create(TestRazorSourceDocument.Create("@!!!")); + var expected = RazorDiagnostic.Create(new RazorError( + LegacyResources.FormatParseError_Unexpected_Character_At_Start_Of_CodeBlock_CS("!"), + new SourceLocation(1, 0, 1), + length: 1)); + // Act engine.Process(document); // Assert var csharpDocument = document.GetCSharpDocument(); var error = Assert.Single(csharpDocument.Diagnostics); - Assert.Equal( - new RazorError( - LegacyResources.FormatParseError_Unexpected_Character_At_Start_Of_CodeBlock_CS("!"), - new SourceLocation(1, 0, 1), - length: 1), - error); + Assert.Equal(expected, error); } [Fact] @@ -102,18 +102,18 @@ namespace Microsoft.AspNetCore.Razor.Evolution.IntegrationTests var document = RazorCodeDocument.Create(TestRazorSourceDocument.Create("@{")); + var expected = RazorDiagnostic.Create(new RazorError( + LegacyResources.FormatParseError_Expected_EndOfBlock_Before_EOF(LegacyResources.BlockName_Code, "}", "{"), + new SourceLocation(1, 0, 1), + length: 1)); + // Act engine.Process(document); // Assert var csharpDocument = document.GetCSharpDocument(); var error = Assert.Single(csharpDocument.Diagnostics); - Assert.Equal( - new RazorError( - LegacyResources.FormatParseError_Expected_EndOfBlock_Before_EOF(LegacyResources.BlockName_Code, "}", "{"), - new SourceLocation(1, 0, 1), - length: 1), - error); + Assert.Equal(expected, error); } } } diff --git a/test/Microsoft.AspNetCore.Razor.Evolution.Test/Legacy/CSharpDirectivesTest.cs b/test/Microsoft.AspNetCore.Razor.Evolution.Test/Legacy/CSharpDirectivesTest.cs index 348a0739a5..f841638053 100644 --- a/test/Microsoft.AspNetCore.Razor.Evolution.Test/Legacy/CSharpDirectivesTest.cs +++ b/test/Microsoft.AspNetCore.Razor.Evolution.Test/Legacy/CSharpDirectivesTest.cs @@ -883,7 +883,7 @@ namespace Microsoft.AspNetCore.Razor.Evolution.Legacy { var result = ParseCodeBlock(document, descriptors, designTime: false); - EvaluateResults(result, expected, expectedErrors); + EvaluateResults(result, expected, expectedErrors.Select(error => RazorDiagnostic.Create(error)).ToList()); } } } diff --git a/test/Microsoft.AspNetCore.Razor.Evolution.Test/Legacy/ParserTestBase.cs b/test/Microsoft.AspNetCore.Razor.Evolution.Test/Legacy/ParserTestBase.cs index fec20cc3d6..5ff3556240 100644 --- a/test/Microsoft.AspNetCore.Razor.Evolution.Test/Legacy/ParserTestBase.cs +++ b/test/Microsoft.AspNetCore.Razor.Evolution.Test/Legacy/ParserTestBase.cs @@ -66,7 +66,7 @@ namespace Microsoft.AspNetCore.Razor.Evolution.Legacy parser.ParseBlock(); var root = context.Builder.Build(); - var diagnostics = context.ErrorSink.Errors; + var diagnostics = context.ErrorSink.Errors?.Select(error => RazorDiagnostic.Create(error)); var options = RazorParserOptions.CreateDefaultOptions(); options.DesignTimeMode = designTime; @@ -99,7 +99,7 @@ namespace Microsoft.AspNetCore.Razor.Evolution.Legacy parser.ParseBlock(); var root = context.Builder.Build(); - var diagnostics = context.ErrorSink.Errors; + var diagnostics = context.ErrorSink.Errors?.Select(error => RazorDiagnostic.Create(error)); var options = RazorParserOptions.CreateDefaultOptions(); options.DesignTimeMode = designTime; @@ -173,7 +173,7 @@ namespace Microsoft.AspNetCore.Razor.Evolution.Legacy if (!ReferenceEquals(expected, IgnoreOutput)) { - EvaluateResults(result, expected, expectedErrors); + EvaluateResults(result, expected, expectedErrors?.Select(error => RazorDiagnostic.Create(error)).ToList()); } } @@ -223,7 +223,7 @@ namespace Microsoft.AspNetCore.Razor.Evolution.Legacy if (!ReferenceEquals(expected, IgnoreOutput)) { - EvaluateResults(result, expected, expectedErrors); + EvaluateResults(result, expected, expectedErrors?.Select(error => RazorDiagnostic.Create(error)).ToList()); } } @@ -269,7 +269,7 @@ namespace Microsoft.AspNetCore.Razor.Evolution.Legacy if (!ReferenceEquals(expected, IgnoreOutput)) { - EvaluateResults(result, expected, expectedErrors); + EvaluateResults(result, expected, expectedErrors?.Select(error => RazorDiagnostic.Create(error)).ToList()); } } @@ -300,7 +300,7 @@ namespace Microsoft.AspNetCore.Razor.Evolution.Legacy EvaluateResults(result, expectedRoot, null); } - internal static void EvaluateResults(RazorSyntaxTree result, Block expectedRoot, IList expectedErrors) + internal static void EvaluateResults(RazorSyntaxTree result, Block expectedRoot, IList expectedErrors) { EvaluateParseTree(result.Root, expectedRoot); EvaluateRazorErrors(result.Diagnostics, expectedErrors); @@ -494,7 +494,7 @@ namespace Microsoft.AspNetCore.Razor.Evolution.Legacy collector.AddError("{0} - FAILED :: Actual: << Null >>", expected); } - internal static void EvaluateRazorErrors(IEnumerable actualErrors, IList expectedErrors) + internal static void EvaluateRazorErrors(IEnumerable actualErrors, IList expectedErrors) { var realCount = actualErrors.Count(); @@ -517,7 +517,7 @@ namespace Microsoft.AspNetCore.Razor.Evolution.Legacy WriteTraceLine("Expected Errors were raised:" + Environment.NewLine + FormatErrors(expectedErrors)); } - internal static string FormatErrors(IEnumerable errors) + internal static string FormatErrors(IEnumerable errors) { if (errors == null) { @@ -525,9 +525,9 @@ namespace Microsoft.AspNetCore.Razor.Evolution.Legacy } var builder = new StringBuilder(); - foreach (RazorError err in errors) + foreach (var error in errors) { - builder.AppendFormat("\t{0}", err); + builder.AppendFormat("\t{0}", error); builder.AppendLine(); } return builder.ToString(); diff --git a/test/Microsoft.AspNetCore.Razor.Evolution.Test/Legacy/TagHelperRewritingTestBase.cs b/test/Microsoft.AspNetCore.Razor.Evolution.Test/Legacy/TagHelperRewritingTestBase.cs index ece3052388..3081f1b726 100644 --- a/test/Microsoft.AspNetCore.Razor.Evolution.Test/Legacy/TagHelperRewritingTestBase.cs +++ b/test/Microsoft.AspNetCore.Razor.Evolution.Test/Legacy/TagHelperRewritingTestBase.cs @@ -64,12 +64,12 @@ namespace Microsoft.AspNetCore.Razor.Evolution.Legacy var parseTreeRewriter = new TagHelperParseTreeRewriter(provider); var actualTree = parseTreeRewriter.Rewrite(syntaxTree.Root, errorSink); - var allErrors = syntaxTree.Diagnostics.Concat(errorSink.Errors); + var allErrors = syntaxTree.Diagnostics.Concat(errorSink.Errors.Select(error => RazorDiagnostic.Create(error))); var actualErrors = allErrors - .OrderBy(error => error.Location.AbsoluteIndex) + .OrderBy(error => error.Span.AbsoluteIndex) .ToList(); - EvaluateRazorErrors(actualErrors, expectedErrors.ToList()); + EvaluateRazorErrors(actualErrors, expectedErrors.Select(error => RazorDiagnostic.Create(error)).ToList()); EvaluateParseTree(actualTree, expectedOutput); } } diff --git a/test/Microsoft.AspNetCore.Razor.Evolution.Test/TagHelperBinderSyntaxTreePassTest.cs b/test/Microsoft.AspNetCore.Razor.Evolution.Test/TagHelperBinderSyntaxTreePassTest.cs index 4b0fe630c1..d6b793d7d1 100644 --- a/test/Microsoft.AspNetCore.Razor.Evolution.Test/TagHelperBinderSyntaxTreePassTest.cs +++ b/test/Microsoft.AspNetCore.Razor.Evolution.Test/TagHelperBinderSyntaxTreePassTest.cs @@ -275,10 +275,11 @@ namespace Microsoft.AspNetCore.Razor.Evolution var codeDocument = RazorCodeDocument.Create(sourceDocument); var originalTree = RazorSyntaxTree.Parse(sourceDocument); - var expectedError = new RazorError( - Resources.FormatTagHelperAssemblyCouldNotBeResolved("TestAssembly"), - new SourceLocation(Environment.NewLine.Length + 17, 1, 1), - length: 12); + var expectedError = RazorDiagnostic.Create( + new RazorError( + Resources.FormatTagHelperAssemblyCouldNotBeResolved("TestAssembly"), + new SourceLocation(Environment.NewLine.Length + 17, 1, 1), + length: 12)); // Act var outputTree = pass.Execute(codeDocument, originalTree); @@ -294,7 +295,7 @@ namespace Microsoft.AspNetCore.Razor.Evolution public void Execute_RecreatesSyntaxTreeOnResolverErrors() { // Arrange - var resolverError = new RazorError("Test error", new SourceLocation(19, 1, 17), length: 12); + var resolverError = RazorDiagnostic.Create(new RazorError("Test error", new SourceLocation(19, 1, 17), length: 12)); var engine = RazorEngine.Create(builder => { var resolver = new ErrorLoggingTagHelperDescriptorResolver(resolverError); @@ -310,7 +311,7 @@ namespace Microsoft.AspNetCore.Razor.Evolution var codeDocument = RazorCodeDocument.Create(sourceDocument); var originalTree = RazorSyntaxTree.Parse(sourceDocument); - var initialError = new RazorError("Initial test error", SourceLocation.Zero, length: 1); + var initialError = RazorDiagnostic.Create(new RazorError("Initial test error", SourceLocation.Zero, length: 1)); var erroredOriginalTree = RazorSyntaxTree.Create( originalTree.Root, originalTree.Source, @@ -362,11 +363,12 @@ namespace Microsoft.AspNetCore.Razor.Evolution var originalTree = RazorSyntaxTree.Parse(sourceDocument); - var initialError = new RazorError("Initial test error", SourceLocation.Zero, length: 1); - var expectedRewritingError = new RazorError( - LegacyResources.FormatTagHelpersParseTreeRewriter_FoundMalformedTagHelper("form"), - new SourceLocation(Environment.NewLine.Length * 2 + 30, 2, 1), - length: 4); + var initialError = RazorDiagnostic.Create(new RazorError("Initial test error", SourceLocation.Zero, length: 1)); + var expectedRewritingError = RazorDiagnostic.Create( + new RazorError( + LegacyResources.FormatTagHelpersParseTreeRewriter_FoundMalformedTagHelper("form"), + new SourceLocation(Environment.NewLine.Length * 2 + 30, 2, 1), + length: 4)); var erroredOriginalTree = RazorSyntaxTree.Create(originalTree.Root, originalTree.Source, new[] { initialError }, originalTree.Options); @@ -1357,16 +1359,16 @@ namespace Microsoft.AspNetCore.Razor.Evolution private class ErrorLoggingTagHelperDescriptorResolver : ITagHelperDescriptorResolver { - private readonly RazorError _error; + private readonly RazorDiagnostic _error; - public ErrorLoggingTagHelperDescriptorResolver(RazorError error) + public ErrorLoggingTagHelperDescriptorResolver(RazorDiagnostic error) { _error = error; } - public IEnumerable Resolve(ErrorSink errorSink) + public IEnumerable Resolve(IList errors) { - errorSink.OnError(_error); + errors.Add(_error); return new[] { new TagHelperDescriptor() { AssemblyName = "TestAssembly" } }; } diff --git a/test/Microsoft.AspNetCore.Razor.Evolution.Test/TestTagHelperDescriptorResolver.cs b/test/Microsoft.AspNetCore.Razor.Evolution.Test/TestTagHelperDescriptorResolver.cs index 5e676db902..2305e357d6 100644 --- a/test/Microsoft.AspNetCore.Razor.Evolution.Test/TestTagHelperDescriptorResolver.cs +++ b/test/Microsoft.AspNetCore.Razor.Evolution.Test/TestTagHelperDescriptorResolver.cs @@ -19,7 +19,7 @@ namespace Microsoft.AspNetCore.Razor.Evolution public List TagHelpers { get; } = new List(); - public IEnumerable Resolve(ErrorSink errorSink) + public IEnumerable Resolve(IList errors) { return TagHelpers; } diff --git a/test/Microsoft.AspNetCore.Razor.Test/Framework/ParserTestBase.cs b/test/Microsoft.AspNetCore.Razor.Test/Framework/ParserTestBase.cs index eb83a9926b..5d22d33a4f 100644 --- a/test/Microsoft.AspNetCore.Razor.Test/Framework/ParserTestBase.cs +++ b/test/Microsoft.AspNetCore.Razor.Test/Framework/ParserTestBase.cs @@ -492,9 +492,9 @@ namespace Microsoft.AspNetCore.Razor.Test.Framework } var builder = new StringBuilder(); - foreach (RazorError err in errors) + foreach (var error in errors) { - builder.AppendFormat("\t{0}", err); + builder.AppendFormat("\t{0}", error); builder.AppendLine(); } return builder.ToString();