Replace RazorError with RazorDiagnostics in public API
This commit is contained in:
parent
7a2f89b5de
commit
ed9068cef4
|
|
@ -20,7 +20,10 @@ namespace Microsoft.AspNetCore.Razor.Evolution
|
||||||
|
|
||||||
if (errorSink.Errors.Count > 0)
|
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);
|
syntaxTree = RazorSyntaxTree.Create(syntaxTree.Root, syntaxTree.Source, combinedErrors, syntaxTree.Options);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2,10 +2,11 @@
|
||||||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using Microsoft.AspNetCore.Razor.Evolution.CodeGeneration;
|
using Microsoft.AspNetCore.Razor.Evolution.CodeGeneration;
|
||||||
using Microsoft.AspNetCore.Razor.Evolution.Legacy;
|
|
||||||
using Microsoft.AspNetCore.Razor.Evolution.Intermediate;
|
using Microsoft.AspNetCore.Razor.Evolution.Intermediate;
|
||||||
|
using Microsoft.AspNetCore.Razor.Evolution.Legacy;
|
||||||
|
|
||||||
namespace Microsoft.AspNetCore.Razor.Evolution
|
namespace Microsoft.AspNetCore.Razor.Evolution
|
||||||
{
|
{
|
||||||
|
|
@ -60,12 +61,17 @@ namespace Microsoft.AspNetCore.Razor.Evolution
|
||||||
|
|
||||||
renderer.VisitDocument(irDocument);
|
renderer.VisitDocument(irDocument);
|
||||||
|
|
||||||
var combinedErrors = syntaxTree.Diagnostics.Concat(renderingContext.ErrorSink.Errors).ToList();
|
var diagnostics = new List<RazorDiagnostic>();
|
||||||
|
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()
|
var csharpDocument = new RazorCSharpDocument()
|
||||||
{
|
{
|
||||||
GeneratedCode = renderingContext.Writer.GenerateCode(),
|
GeneratedCode = renderingContext.Writer.GenerateCode(),
|
||||||
LineMappings = renderingContext.LineMappings,
|
LineMappings = renderingContext.LineMappings,
|
||||||
Diagnostics = combinedErrors
|
Diagnostics = diagnostics
|
||||||
};
|
};
|
||||||
|
|
||||||
codeDocument.SetCSharpDocument(csharpDocument);
|
codeDocument.SetCSharpDocument(csharpDocument);
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,7 @@ namespace Microsoft.AspNetCore.Razor.Evolution
|
||||||
public DefaultRazorSyntaxTree(
|
public DefaultRazorSyntaxTree(
|
||||||
Block root,
|
Block root,
|
||||||
RazorSourceDocument source,
|
RazorSourceDocument source,
|
||||||
IReadOnlyList<RazorError> diagnostics,
|
IReadOnlyList<RazorDiagnostic> diagnostics,
|
||||||
RazorParserOptions options)
|
RazorParserOptions options)
|
||||||
{
|
{
|
||||||
Root = root;
|
Root = root;
|
||||||
|
|
@ -20,7 +20,7 @@ namespace Microsoft.AspNetCore.Razor.Evolution
|
||||||
Options = options;
|
Options = options;
|
||||||
}
|
}
|
||||||
|
|
||||||
internal override IReadOnlyList<RazorError> Diagnostics { get; }
|
public override IReadOnlyList<RazorDiagnostic> Diagnostics { get; }
|
||||||
|
|
||||||
public override RazorParserOptions Options { get; }
|
public override RazorParserOptions Options { get; }
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,7 @@ namespace Microsoft.AspNetCore.Razor.Evolution.Legacy
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Used to manage <see cref="RazorError"/>s encountered during the Razor parsing phase.
|
/// Used to manage <see cref="RazorError"/>s encountered during the Razor parsing phase.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class ErrorSink
|
internal class ErrorSink
|
||||||
{
|
{
|
||||||
private readonly List<RazorError> _errors;
|
private readonly List<RazorError> _errors;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -10,6 +10,6 @@ namespace Microsoft.AspNetCore.Razor.Evolution.Legacy
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public interface ITagHelperDescriptorResolver
|
public interface ITagHelperDescriptorResolver
|
||||||
{
|
{
|
||||||
IEnumerable<TagHelperDescriptor> Resolve(ErrorSink errorSink);
|
IEnumerable<TagHelperDescriptor> Resolve(IList<RazorDiagnostic> errors);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -7,7 +7,7 @@ using Microsoft.Extensions.Internal;
|
||||||
|
|
||||||
namespace Microsoft.AspNetCore.Razor.Evolution.Legacy
|
namespace Microsoft.AspNetCore.Razor.Evolution.Legacy
|
||||||
{
|
{
|
||||||
public class RazorError : IEquatable<RazorError>
|
internal class RazorError : IEquatable<RazorError>
|
||||||
{
|
{
|
||||||
internal static readonly RazorError[] EmptyArray = new RazorError[0];
|
internal static readonly RazorError[] EmptyArray = new RazorError[0];
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@
|
||||||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
|
using System.Linq;
|
||||||
|
|
||||||
namespace Microsoft.AspNetCore.Razor.Evolution.Legacy
|
namespace Microsoft.AspNetCore.Razor.Evolution.Legacy
|
||||||
{
|
{
|
||||||
|
|
@ -47,7 +48,10 @@ namespace Microsoft.AspNetCore.Razor.Evolution.Legacy
|
||||||
markupParser.ParseDocument();
|
markupParser.ParseDocument();
|
||||||
|
|
||||||
var root = context.Builder.Build();
|
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);
|
return RazorSyntaxTree.Create(root, source, diagnostics, Options);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -12,6 +12,6 @@ namespace Microsoft.AspNetCore.Razor.Evolution
|
||||||
|
|
||||||
public IReadOnlyList<LineMapping> LineMappings { get; set; }
|
public IReadOnlyList<LineMapping> LineMappings { get; set; }
|
||||||
|
|
||||||
public IReadOnlyList<RazorError> Diagnostics { get; set; }
|
public IReadOnlyList<RazorDiagnostic> Diagnostics { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -68,7 +68,7 @@ namespace Microsoft.AspNetCore.Razor.Evolution
|
||||||
string IFormattable.ToString(string ignore, IFormatProvider formatProvider)
|
string IFormattable.ToString(string ignore, IFormatProvider formatProvider)
|
||||||
{
|
{
|
||||||
// Our indices are 0-based, but we we want to print them as 1-based.
|
// 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)}";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -12,7 +12,7 @@ namespace Microsoft.AspNetCore.Razor.Evolution
|
||||||
internal static RazorSyntaxTree Create(
|
internal static RazorSyntaxTree Create(
|
||||||
Block root,
|
Block root,
|
||||||
RazorSourceDocument source,
|
RazorSourceDocument source,
|
||||||
IEnumerable<RazorError> diagnostics,
|
IEnumerable<RazorDiagnostic> diagnostics,
|
||||||
RazorParserOptions options)
|
RazorParserOptions options)
|
||||||
{
|
{
|
||||||
if (root == null)
|
if (root == null)
|
||||||
|
|
@ -35,7 +35,7 @@ namespace Microsoft.AspNetCore.Razor.Evolution
|
||||||
throw new ArgumentNullException(nameof(options));
|
throw new ArgumentNullException(nameof(options));
|
||||||
}
|
}
|
||||||
|
|
||||||
return new DefaultRazorSyntaxTree(root, source, new List<RazorError>(diagnostics), options);
|
return new DefaultRazorSyntaxTree(root, source, new List<RazorDiagnostic>(diagnostics), options);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static RazorSyntaxTree Parse(RazorSourceDocument source)
|
public static RazorSyntaxTree Parse(RazorSourceDocument source)
|
||||||
|
|
@ -59,7 +59,7 @@ namespace Microsoft.AspNetCore.Razor.Evolution
|
||||||
return parser.Parse(source);
|
return parser.Parse(source);
|
||||||
}
|
}
|
||||||
|
|
||||||
internal abstract IReadOnlyList<RazorError> Diagnostics { get; }
|
public abstract IReadOnlyList<RazorDiagnostic> Diagnostics { get; }
|
||||||
|
|
||||||
public abstract RazorParserOptions Options { get; }
|
public abstract RazorParserOptions Options { get; }
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -45,35 +45,36 @@ namespace Microsoft.AspNetCore.Razor.Evolution
|
||||||
|
|
||||||
visitor.VisitBlock(syntaxTree.Root);
|
visitor.VisitBlock(syntaxTree.Root);
|
||||||
|
|
||||||
|
var errorList = new List<RazorDiagnostic>();
|
||||||
|
var descriptors = (IReadOnlyList<TagHelperDescriptor>)resolver.Resolve(errorList).ToList();
|
||||||
|
|
||||||
var errorSink = new ErrorSink();
|
var errorSink = new ErrorSink();
|
||||||
var directives = visitor.Directives;
|
var directives = visitor.Directives;
|
||||||
var descriptors = (IReadOnlyList<TagHelperDescriptor>)resolver.Resolve(errorSink).ToList();
|
|
||||||
|
|
||||||
descriptors = ProcessDirectives(directives, descriptors, errorSink);
|
descriptors = ProcessDirectives(directives, descriptors, errorSink);
|
||||||
|
|
||||||
|
var root = syntaxTree.Root;
|
||||||
|
|
||||||
if (descriptors.Count == 0)
|
if (descriptors.Count == 0)
|
||||||
{
|
{
|
||||||
// No TagHelpers, add any errors if we have them.
|
if (errorSink.Errors.Count == 0 && errorList.Count == 0)
|
||||||
if (errorSink.Errors.Count > 0)
|
|
||||||
{
|
{
|
||||||
var errors = CombineErrors(syntaxTree.Diagnostics, errorSink.Errors);
|
// No TagHelpers and errors, no op.
|
||||||
return RazorSyntaxTree.Create(syntaxTree.Root, syntaxTree.Source, errors, syntaxTree.Options);
|
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);
|
// Temporary code while we're still using legacy diagnostics in the SyntaxTree.
|
||||||
var rewriter = new TagHelperParseTreeRewriter(descriptorProvider);
|
errorList.AddRange(errorSink.Errors.Select(error => RazorDiagnostic.Create(error)));
|
||||||
var rewrittenRoot = rewriter.Rewrite(syntaxTree.Root, errorSink);
|
|
||||||
var diagnostics = syntaxTree.Diagnostics;
|
|
||||||
|
|
||||||
if (errorSink.Errors.Count > 0)
|
var diagnostics = CombineErrors(syntaxTree.Diagnostics, errorList);
|
||||||
{
|
|
||||||
diagnostics = CombineErrors(diagnostics, errorSink.Errors);
|
|
||||||
}
|
|
||||||
|
|
||||||
var newSyntaxTree = RazorSyntaxTree.Create(rewrittenRoot, syntaxTree.Source, diagnostics, syntaxTree.Options);
|
var newSyntaxTree = RazorSyntaxTree.Create(root, syntaxTree.Source, diagnostics, syntaxTree.Options);
|
||||||
return newSyntaxTree;
|
return newSyntaxTree;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -299,9 +300,9 @@ namespace Microsoft.AspNetCore.Razor.Evolution
|
||||||
return normalizeEmptyStringLength;
|
return normalizeEmptyStringLength;
|
||||||
}
|
}
|
||||||
|
|
||||||
private IReadOnlyList<RazorError> CombineErrors(IReadOnlyList<RazorError> errors1, IReadOnlyList<RazorError> errors2)
|
private IReadOnlyList<RazorDiagnostic> CombineErrors(IReadOnlyList<RazorDiagnostic> errors1, IReadOnlyList<RazorDiagnostic> errors2)
|
||||||
{
|
{
|
||||||
var combinedErrors = new List<RazorError>(errors1.Count + errors2.Count);
|
var combinedErrors = new List<RazorDiagnostic>(errors1.Count + errors2.Count);
|
||||||
combinedErrors.AddRange(errors1);
|
combinedErrors.AddRange(errors1);
|
||||||
combinedErrors.AddRange(errors2);
|
combinedErrors.AddRange(errors2);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -43,7 +43,7 @@ namespace Microsoft.CodeAnalysis.Razor
|
||||||
{
|
{
|
||||||
_referenceFeature = referenceFeature;
|
_referenceFeature = referenceFeature;
|
||||||
}
|
}
|
||||||
public IEnumerable<TagHelperDescriptor> Resolve(ErrorSink errorSink)
|
public IEnumerable<TagHelperDescriptor> Resolve(IList<RazorDiagnostic> errors)
|
||||||
{
|
{
|
||||||
var compilation = CSharpCompilation.Create("__TagHelpers", references: _referenceFeature.References);
|
var compilation = CSharpCompilation.Create("__TagHelpers", references: _referenceFeature.References);
|
||||||
return TagHelpers.GetTagHelpers(compilation);
|
return TagHelpers.GetTagHelpers(compilation);
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,9 @@
|
||||||
// Copyright (c) .NET Foundation. All rights reserved.
|
// 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.
|
// 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;
|
||||||
|
using System.Linq;
|
||||||
|
using Microsoft.AspNetCore.Razor.Evolution.Legacy;
|
||||||
using Xunit;
|
using Xunit;
|
||||||
|
|
||||||
namespace Microsoft.AspNetCore.Razor.Evolution
|
namespace Microsoft.AspNetCore.Razor.Evolution
|
||||||
|
|
@ -49,6 +50,7 @@ namespace Microsoft.AspNetCore.Razor.Evolution
|
||||||
new SourceLocation(41 + Environment.NewLine.Length * 4, 4, 4),
|
new SourceLocation(41 + Environment.NewLine.Length * 4, 4, 4),
|
||||||
length: 8),
|
length: 8),
|
||||||
};
|
};
|
||||||
|
var expectedDiagnostics = expectedErrors.Select(error => RazorDiagnostic.Create(error));
|
||||||
var engine = RazorEngine.Create();
|
var engine = RazorEngine.Create();
|
||||||
var pass = new DefaultDirectiveSyntaxTreePass()
|
var pass = new DefaultDirectiveSyntaxTreePass()
|
||||||
{
|
{
|
||||||
|
|
@ -72,7 +74,7 @@ namespace Microsoft.AspNetCore.Razor.Evolution
|
||||||
// Assert
|
// Assert
|
||||||
Assert.Empty(originalTree.Diagnostics);
|
Assert.Empty(originalTree.Diagnostics);
|
||||||
Assert.NotSame(originalTree, outputTree);
|
Assert.NotSame(originalTree, outputTree);
|
||||||
Assert.Equal(expectedErrors, outputTree.Diagnostics);
|
Assert.Equal(expectedDiagnostics, outputTree.Diagnostics);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
|
|
@ -90,6 +92,7 @@ namespace Microsoft.AspNetCore.Razor.Evolution
|
||||||
new SourceLocation(41 + Environment.NewLine.Length * 4, 4, 4),
|
new SourceLocation(41 + Environment.NewLine.Length * 4, 4, 4),
|
||||||
length: 8),
|
length: 8),
|
||||||
};
|
};
|
||||||
|
var expectedDiagnostics = expectedErrors.Select(error => RazorDiagnostic.Create(error)).ToList();
|
||||||
var engine = RazorEngine.Create();
|
var engine = RazorEngine.Create();
|
||||||
var pass = new DefaultDirectiveSyntaxTreePass()
|
var pass = new DefaultDirectiveSyntaxTreePass()
|
||||||
{
|
{
|
||||||
|
|
@ -109,7 +112,7 @@ namespace Microsoft.AspNetCore.Razor.Evolution
|
||||||
var erroredOriginalTree = RazorSyntaxTree.Create(
|
var erroredOriginalTree = RazorSyntaxTree.Create(
|
||||||
originalTree.Root,
|
originalTree.Root,
|
||||||
originalTree.Source,
|
originalTree.Source,
|
||||||
new[] { expectedErrors[0] },
|
new[] { expectedDiagnostics[0] },
|
||||||
originalTree.Options);
|
originalTree.Options);
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
|
|
@ -118,7 +121,7 @@ namespace Microsoft.AspNetCore.Razor.Evolution
|
||||||
// Assert
|
// Assert
|
||||||
Assert.Empty(originalTree.Diagnostics);
|
Assert.Empty(originalTree.Diagnostics);
|
||||||
Assert.NotSame(originalTree, outputTree);
|
Assert.NotSame(originalTree, outputTree);
|
||||||
Assert.Equal(expectedErrors, outputTree.Diagnostics);
|
Assert.Equal(expectedDiagnostics, outputTree.Diagnostics);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -80,18 +80,18 @@ namespace Microsoft.AspNetCore.Razor.Evolution.IntegrationTests
|
||||||
|
|
||||||
var document = RazorCodeDocument.Create(TestRazorSourceDocument.Create("@!!!"));
|
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
|
// Act
|
||||||
engine.Process(document);
|
engine.Process(document);
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
var csharpDocument = document.GetCSharpDocument();
|
var csharpDocument = document.GetCSharpDocument();
|
||||||
var error = Assert.Single(csharpDocument.Diagnostics);
|
var error = Assert.Single(csharpDocument.Diagnostics);
|
||||||
Assert.Equal(
|
Assert.Equal(expected, error);
|
||||||
new RazorError(
|
|
||||||
LegacyResources.FormatParseError_Unexpected_Character_At_Start_Of_CodeBlock_CS("!"),
|
|
||||||
new SourceLocation(1, 0, 1),
|
|
||||||
length: 1),
|
|
||||||
error);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
|
|
@ -102,18 +102,18 @@ namespace Microsoft.AspNetCore.Razor.Evolution.IntegrationTests
|
||||||
|
|
||||||
var document = RazorCodeDocument.Create(TestRazorSourceDocument.Create("@{"));
|
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
|
// Act
|
||||||
engine.Process(document);
|
engine.Process(document);
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
var csharpDocument = document.GetCSharpDocument();
|
var csharpDocument = document.GetCSharpDocument();
|
||||||
var error = Assert.Single(csharpDocument.Diagnostics);
|
var error = Assert.Single(csharpDocument.Diagnostics);
|
||||||
Assert.Equal(
|
Assert.Equal(expected, error);
|
||||||
new RazorError(
|
|
||||||
LegacyResources.FormatParseError_Expected_EndOfBlock_Before_EOF(LegacyResources.BlockName_Code, "}", "{"),
|
|
||||||
new SourceLocation(1, 0, 1),
|
|
||||||
length: 1),
|
|
||||||
error);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -883,7 +883,7 @@ namespace Microsoft.AspNetCore.Razor.Evolution.Legacy
|
||||||
{
|
{
|
||||||
var result = ParseCodeBlock(document, descriptors, designTime: false);
|
var result = ParseCodeBlock(document, descriptors, designTime: false);
|
||||||
|
|
||||||
EvaluateResults(result, expected, expectedErrors);
|
EvaluateResults(result, expected, expectedErrors.Select(error => RazorDiagnostic.Create(error)).ToList());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -66,7 +66,7 @@ namespace Microsoft.AspNetCore.Razor.Evolution.Legacy
|
||||||
parser.ParseBlock();
|
parser.ParseBlock();
|
||||||
|
|
||||||
var root = context.Builder.Build();
|
var root = context.Builder.Build();
|
||||||
var diagnostics = context.ErrorSink.Errors;
|
var diagnostics = context.ErrorSink.Errors?.Select(error => RazorDiagnostic.Create(error));
|
||||||
var options = RazorParserOptions.CreateDefaultOptions();
|
var options = RazorParserOptions.CreateDefaultOptions();
|
||||||
options.DesignTimeMode = designTime;
|
options.DesignTimeMode = designTime;
|
||||||
|
|
||||||
|
|
@ -99,7 +99,7 @@ namespace Microsoft.AspNetCore.Razor.Evolution.Legacy
|
||||||
parser.ParseBlock();
|
parser.ParseBlock();
|
||||||
|
|
||||||
var root = context.Builder.Build();
|
var root = context.Builder.Build();
|
||||||
var diagnostics = context.ErrorSink.Errors;
|
var diagnostics = context.ErrorSink.Errors?.Select(error => RazorDiagnostic.Create(error));
|
||||||
|
|
||||||
var options = RazorParserOptions.CreateDefaultOptions();
|
var options = RazorParserOptions.CreateDefaultOptions();
|
||||||
options.DesignTimeMode = designTime;
|
options.DesignTimeMode = designTime;
|
||||||
|
|
@ -173,7 +173,7 @@ namespace Microsoft.AspNetCore.Razor.Evolution.Legacy
|
||||||
|
|
||||||
if (!ReferenceEquals(expected, IgnoreOutput))
|
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))
|
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))
|
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);
|
EvaluateResults(result, expectedRoot, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
internal static void EvaluateResults(RazorSyntaxTree result, Block expectedRoot, IList<RazorError> expectedErrors)
|
internal static void EvaluateResults(RazorSyntaxTree result, Block expectedRoot, IList<RazorDiagnostic> expectedErrors)
|
||||||
{
|
{
|
||||||
EvaluateParseTree(result.Root, expectedRoot);
|
EvaluateParseTree(result.Root, expectedRoot);
|
||||||
EvaluateRazorErrors(result.Diagnostics, expectedErrors);
|
EvaluateRazorErrors(result.Diagnostics, expectedErrors);
|
||||||
|
|
@ -494,7 +494,7 @@ namespace Microsoft.AspNetCore.Razor.Evolution.Legacy
|
||||||
collector.AddError("{0} - FAILED :: Actual: << Null >>", expected);
|
collector.AddError("{0} - FAILED :: Actual: << Null >>", expected);
|
||||||
}
|
}
|
||||||
|
|
||||||
internal static void EvaluateRazorErrors(IEnumerable<RazorError> actualErrors, IList<RazorError> expectedErrors)
|
internal static void EvaluateRazorErrors(IEnumerable<RazorDiagnostic> actualErrors, IList<RazorDiagnostic> expectedErrors)
|
||||||
{
|
{
|
||||||
var realCount = actualErrors.Count();
|
var realCount = actualErrors.Count();
|
||||||
|
|
||||||
|
|
@ -517,7 +517,7 @@ namespace Microsoft.AspNetCore.Razor.Evolution.Legacy
|
||||||
WriteTraceLine("Expected Errors were raised:" + Environment.NewLine + FormatErrors(expectedErrors));
|
WriteTraceLine("Expected Errors were raised:" + Environment.NewLine + FormatErrors(expectedErrors));
|
||||||
}
|
}
|
||||||
|
|
||||||
internal static string FormatErrors(IEnumerable<RazorError> errors)
|
internal static string FormatErrors(IEnumerable<RazorDiagnostic> errors)
|
||||||
{
|
{
|
||||||
if (errors == null)
|
if (errors == null)
|
||||||
{
|
{
|
||||||
|
|
@ -525,9 +525,9 @@ namespace Microsoft.AspNetCore.Razor.Evolution.Legacy
|
||||||
}
|
}
|
||||||
|
|
||||||
var builder = new StringBuilder();
|
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();
|
builder.AppendLine();
|
||||||
}
|
}
|
||||||
return builder.ToString();
|
return builder.ToString();
|
||||||
|
|
|
||||||
|
|
@ -64,12 +64,12 @@ namespace Microsoft.AspNetCore.Razor.Evolution.Legacy
|
||||||
var parseTreeRewriter = new TagHelperParseTreeRewriter(provider);
|
var parseTreeRewriter = new TagHelperParseTreeRewriter(provider);
|
||||||
var actualTree = parseTreeRewriter.Rewrite(syntaxTree.Root, errorSink);
|
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
|
var actualErrors = allErrors
|
||||||
.OrderBy(error => error.Location.AbsoluteIndex)
|
.OrderBy(error => error.Span.AbsoluteIndex)
|
||||||
.ToList();
|
.ToList();
|
||||||
|
|
||||||
EvaluateRazorErrors(actualErrors, expectedErrors.ToList());
|
EvaluateRazorErrors(actualErrors, expectedErrors.Select(error => RazorDiagnostic.Create(error)).ToList());
|
||||||
EvaluateParseTree(actualTree, expectedOutput);
|
EvaluateParseTree(actualTree, expectedOutput);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -275,10 +275,11 @@ namespace Microsoft.AspNetCore.Razor.Evolution
|
||||||
var codeDocument = RazorCodeDocument.Create(sourceDocument);
|
var codeDocument = RazorCodeDocument.Create(sourceDocument);
|
||||||
var originalTree = RazorSyntaxTree.Parse(sourceDocument);
|
var originalTree = RazorSyntaxTree.Parse(sourceDocument);
|
||||||
|
|
||||||
var expectedError = new RazorError(
|
var expectedError = RazorDiagnostic.Create(
|
||||||
Resources.FormatTagHelperAssemblyCouldNotBeResolved("TestAssembly"),
|
new RazorError(
|
||||||
new SourceLocation(Environment.NewLine.Length + 17, 1, 1),
|
Resources.FormatTagHelperAssemblyCouldNotBeResolved("TestAssembly"),
|
||||||
length: 12);
|
new SourceLocation(Environment.NewLine.Length + 17, 1, 1),
|
||||||
|
length: 12));
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
var outputTree = pass.Execute(codeDocument, originalTree);
|
var outputTree = pass.Execute(codeDocument, originalTree);
|
||||||
|
|
@ -294,7 +295,7 @@ namespace Microsoft.AspNetCore.Razor.Evolution
|
||||||
public void Execute_RecreatesSyntaxTreeOnResolverErrors()
|
public void Execute_RecreatesSyntaxTreeOnResolverErrors()
|
||||||
{
|
{
|
||||||
// Arrange
|
// 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 engine = RazorEngine.Create(builder =>
|
||||||
{
|
{
|
||||||
var resolver = new ErrorLoggingTagHelperDescriptorResolver(resolverError);
|
var resolver = new ErrorLoggingTagHelperDescriptorResolver(resolverError);
|
||||||
|
|
@ -310,7 +311,7 @@ namespace Microsoft.AspNetCore.Razor.Evolution
|
||||||
var codeDocument = RazorCodeDocument.Create(sourceDocument);
|
var codeDocument = RazorCodeDocument.Create(sourceDocument);
|
||||||
var originalTree = RazorSyntaxTree.Parse(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(
|
var erroredOriginalTree = RazorSyntaxTree.Create(
|
||||||
originalTree.Root,
|
originalTree.Root,
|
||||||
originalTree.Source,
|
originalTree.Source,
|
||||||
|
|
@ -362,11 +363,12 @@ namespace Microsoft.AspNetCore.Razor.Evolution
|
||||||
|
|
||||||
var originalTree = RazorSyntaxTree.Parse(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 expectedRewritingError = new RazorError(
|
var expectedRewritingError = RazorDiagnostic.Create(
|
||||||
LegacyResources.FormatTagHelpersParseTreeRewriter_FoundMalformedTagHelper("form"),
|
new RazorError(
|
||||||
new SourceLocation(Environment.NewLine.Length * 2 + 30, 2, 1),
|
LegacyResources.FormatTagHelpersParseTreeRewriter_FoundMalformedTagHelper("form"),
|
||||||
length: 4);
|
new SourceLocation(Environment.NewLine.Length * 2 + 30, 2, 1),
|
||||||
|
length: 4));
|
||||||
|
|
||||||
var erroredOriginalTree = RazorSyntaxTree.Create(originalTree.Root, originalTree.Source, new[] { initialError }, originalTree.Options);
|
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 class ErrorLoggingTagHelperDescriptorResolver : ITagHelperDescriptorResolver
|
||||||
{
|
{
|
||||||
private readonly RazorError _error;
|
private readonly RazorDiagnostic _error;
|
||||||
|
|
||||||
public ErrorLoggingTagHelperDescriptorResolver(RazorError error)
|
public ErrorLoggingTagHelperDescriptorResolver(RazorDiagnostic error)
|
||||||
{
|
{
|
||||||
_error = error;
|
_error = error;
|
||||||
}
|
}
|
||||||
|
|
||||||
public IEnumerable<TagHelperDescriptor> Resolve(ErrorSink errorSink)
|
public IEnumerable<TagHelperDescriptor> Resolve(IList<RazorDiagnostic> errors)
|
||||||
{
|
{
|
||||||
errorSink.OnError(_error);
|
errors.Add(_error);
|
||||||
|
|
||||||
return new[] { new TagHelperDescriptor() { AssemblyName = "TestAssembly" } };
|
return new[] { new TagHelperDescriptor() { AssemblyName = "TestAssembly" } };
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -19,7 +19,7 @@ namespace Microsoft.AspNetCore.Razor.Evolution
|
||||||
|
|
||||||
public List<TagHelperDescriptor> TagHelpers { get; } = new List<TagHelperDescriptor>();
|
public List<TagHelperDescriptor> TagHelpers { get; } = new List<TagHelperDescriptor>();
|
||||||
|
|
||||||
public IEnumerable<TagHelperDescriptor> Resolve(ErrorSink errorSink)
|
public IEnumerable<TagHelperDescriptor> Resolve(IList<RazorDiagnostic> errors)
|
||||||
{
|
{
|
||||||
return TagHelpers;
|
return TagHelpers;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -492,9 +492,9 @@ namespace Microsoft.AspNetCore.Razor.Test.Framework
|
||||||
}
|
}
|
||||||
|
|
||||||
var builder = new StringBuilder();
|
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();
|
builder.AppendLine();
|
||||||
}
|
}
|
||||||
return builder.ToString();
|
return builder.ToString();
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue