React to aspnet/Razor#1017
This commit is contained in:
parent
927e75870d
commit
0f5d5ff3b5
|
|
@ -139,13 +139,13 @@ namespace Microsoft.AspNetCore.Mvc.Razor.Internal
|
||||||
// Internal for unit testing
|
// Internal for unit testing
|
||||||
public CompilationResult GetCompilationFailedResult(
|
public CompilationResult GetCompilationFailedResult(
|
||||||
string relativePath,
|
string relativePath,
|
||||||
IEnumerable<Microsoft.AspNetCore.Razor.Evolution.Legacy.RazorError> errors)
|
IEnumerable<RazorDiagnostic> errors)
|
||||||
{
|
{
|
||||||
// If a SourceLocation does not specify a file path, assume it is produced
|
// If a SourceLocation does not specify a file path, assume it is produced
|
||||||
// from parsing the current file.
|
// from parsing the current file.
|
||||||
var messageGroups = errors
|
var messageGroups = errors
|
||||||
.GroupBy(razorError =>
|
.GroupBy(razorError =>
|
||||||
razorError.Location.FilePath ?? relativePath,
|
razorError.Span.FilePath ?? relativePath,
|
||||||
StringComparer.Ordinal);
|
StringComparer.Ordinal);
|
||||||
|
|
||||||
var failures = new List<CompilationFailure>();
|
var failures = new List<CompilationFailure>();
|
||||||
|
|
@ -165,18 +165,18 @@ namespace Microsoft.AspNetCore.Mvc.Razor.Internal
|
||||||
}
|
}
|
||||||
|
|
||||||
private DiagnosticMessage CreateDiagnosticMessage(
|
private DiagnosticMessage CreateDiagnosticMessage(
|
||||||
Microsoft.AspNetCore.Razor.Evolution.Legacy.RazorError error,
|
RazorDiagnostic error,
|
||||||
string filePath)
|
string filePath)
|
||||||
{
|
{
|
||||||
var location = error.Location;
|
var sourceSpan = error.Span;
|
||||||
return new DiagnosticMessage(
|
return new DiagnosticMessage(
|
||||||
message: error.Message,
|
message: error.GetMessage(),
|
||||||
formattedMessage: $"{error} ({location.LineIndex},{location.CharacterIndex}) {error.Message}",
|
formattedMessage: $"{error} ({sourceSpan.LineIndex},{sourceSpan.CharacterIndex}) {error.GetMessage()}",
|
||||||
filePath: filePath,
|
filePath: filePath,
|
||||||
startLine: error.Location.LineIndex + 1,
|
startLine: sourceSpan.LineIndex + 1,
|
||||||
startColumn: error.Location.CharacterIndex,
|
startColumn: sourceSpan.CharacterIndex,
|
||||||
endLine: error.Location.LineIndex + 1,
|
endLine: sourceSpan.LineIndex + 1,
|
||||||
endColumn: error.Location.CharacterIndex + error.Length);
|
endColumn: sourceSpan.CharacterIndex + sourceSpan.Length);
|
||||||
}
|
}
|
||||||
|
|
||||||
private string ReadFileContentsSafely(string relativePath)
|
private string ReadFileContentsSafely(string relativePath)
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,6 @@ using Microsoft.AspNetCore.Razor.Evolution;
|
||||||
using Microsoft.AspNetCore.Razor.Evolution.Intermediate;
|
using Microsoft.AspNetCore.Razor.Evolution.Intermediate;
|
||||||
using Microsoft.AspNetCore.Razor.Evolution.Legacy;
|
using Microsoft.AspNetCore.Razor.Evolution.Legacy;
|
||||||
using Xunit;
|
using Xunit;
|
||||||
using ErrorSink = Microsoft.AspNetCore.Razor.Evolution.Legacy.ErrorSink;
|
|
||||||
|
|
||||||
namespace Microsoft.AspNetCore.Mvc.Razor.Host
|
namespace Microsoft.AspNetCore.Mvc.Razor.Host
|
||||||
{
|
{
|
||||||
|
|
@ -251,7 +250,7 @@ namespace Microsoft.AspNetCore.Mvc.Razor.Host
|
||||||
|
|
||||||
public TagHelperDescriptor[] TagHelpers { get; }
|
public TagHelperDescriptor[] TagHelpers { get; }
|
||||||
|
|
||||||
public IEnumerable<TagHelperDescriptor> Resolve(ErrorSink errorSink)
|
public IEnumerable<TagHelperDescriptor> Resolve(IList<RazorDiagnostic> errors)
|
||||||
{
|
{
|
||||||
return TagHelpers;
|
return TagHelpers;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,6 @@ using Microsoft.AspNetCore.Razor.Evolution;
|
||||||
using Microsoft.AspNetCore.Razor.Evolution.Intermediate;
|
using Microsoft.AspNetCore.Razor.Evolution.Intermediate;
|
||||||
using Microsoft.AspNetCore.Razor.Evolution.Legacy;
|
using Microsoft.AspNetCore.Razor.Evolution.Legacy;
|
||||||
using Xunit;
|
using Xunit;
|
||||||
using ErrorSink = Microsoft.AspNetCore.Razor.Evolution.Legacy.ErrorSink;
|
|
||||||
|
|
||||||
namespace Microsoft.AspNetCore.Mvc.Razor.Host
|
namespace Microsoft.AspNetCore.Mvc.Razor.Host
|
||||||
{
|
{
|
||||||
|
|
@ -415,7 +414,7 @@ public class __Generated__TagCloudViewComponentTagHelper : Microsoft.AspNetCore.
|
||||||
|
|
||||||
public TagHelperDescriptor[] TagHelpers { get; }
|
public TagHelperDescriptor[] TagHelpers { get; }
|
||||||
|
|
||||||
public IEnumerable<TagHelperDescriptor> Resolve(ErrorSink errorSink)
|
public IEnumerable<TagHelperDescriptor> Resolve(IList<RazorDiagnostic> errors)
|
||||||
{
|
{
|
||||||
return TagHelpers;
|
return TagHelpers;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,6 @@ using System.Collections.Generic;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using Microsoft.AspNetCore.Mvc.Razor.Compilation;
|
using Microsoft.AspNetCore.Mvc.Razor.Compilation;
|
||||||
using Microsoft.AspNetCore.Razor.Evolution;
|
using Microsoft.AspNetCore.Razor.Evolution;
|
||||||
using Microsoft.AspNetCore.Razor.Evolution.Legacy;
|
|
||||||
using Microsoft.Extensions.FileProviders;
|
using Microsoft.Extensions.FileProviders;
|
||||||
using Microsoft.Extensions.Logging.Testing;
|
using Microsoft.Extensions.Logging.Testing;
|
||||||
using Moq;
|
using Moq;
|
||||||
|
|
@ -39,7 +38,7 @@ namespace Microsoft.AspNetCore.Mvc.Razor.Internal
|
||||||
{
|
{
|
||||||
document.SetCSharpDocument(new RazorCSharpDocument()
|
document.SetCSharpDocument(new RazorCSharpDocument()
|
||||||
{
|
{
|
||||||
Diagnostics = new List<RazorError>()
|
Diagnostics = new List<RazorDiagnostic>()
|
||||||
});
|
});
|
||||||
|
|
||||||
Assert.Equal(viewPath, document.Source.Filename); // Assert if source file name is the root relative path
|
Assert.Equal(viewPath, document.Source.Filename); // Assert if source file name is the root relative path
|
||||||
|
|
@ -78,9 +77,9 @@ namespace Microsoft.AspNetCore.Mvc.Razor.Internal
|
||||||
{
|
{
|
||||||
document.SetCSharpDocument(new RazorCSharpDocument()
|
document.SetCSharpDocument(new RazorCSharpDocument()
|
||||||
{
|
{
|
||||||
Diagnostics = new List<RazorError>()
|
Diagnostics = new List<RazorDiagnostic>()
|
||||||
{
|
{
|
||||||
new RazorError("some message", 1, 1, 1, 1)
|
GetRazorDiagnostic("some message", new SourceLocation(1, 1, 1), length: 1)
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}).Verifiable();
|
}).Verifiable();
|
||||||
|
|
@ -128,7 +127,7 @@ namespace Microsoft.AspNetCore.Mvc.Razor.Internal
|
||||||
{
|
{
|
||||||
document.SetCSharpDocument(new RazorCSharpDocument()
|
document.SetCSharpDocument(new RazorCSharpDocument()
|
||||||
{
|
{
|
||||||
Diagnostics = new List<RazorError>()
|
Diagnostics = new List<RazorDiagnostic>()
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
@ -165,10 +164,10 @@ namespace Microsoft.AspNetCore.Mvc.Razor.Internal
|
||||||
NullLoggerFactory.Instance);
|
NullLoggerFactory.Instance);
|
||||||
var errors = new[]
|
var errors = new[]
|
||||||
{
|
{
|
||||||
new RazorError("message-1", new SourceLocation(1, 2, 17), length: 1),
|
GetRazorDiagnostic("message-1", new SourceLocation(1, 2, 17), length: 1),
|
||||||
new RazorError("message-2", new SourceLocation(viewPath, 1, 4, 6), 7),
|
GetRazorDiagnostic("message-2", new SourceLocation(viewPath, 1, 4, 6), length: 7),
|
||||||
new RazorError { Message = "message-3" },
|
GetRazorDiagnostic("message-3", SourceLocation.Undefined, length: -1),
|
||||||
new RazorError("message-4", new SourceLocation(viewImportsPath, 1, 3, 8), 4),
|
GetRazorDiagnostic("message-4", new SourceLocation(viewImportsPath, 1, 3, 8), length: 4),
|
||||||
};
|
};
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
|
|
@ -184,7 +183,7 @@ namespace Microsoft.AspNetCore.Mvc.Razor.Internal
|
||||||
Assert.Collection(failure.Messages,
|
Assert.Collection(failure.Messages,
|
||||||
message =>
|
message =>
|
||||||
{
|
{
|
||||||
Assert.Equal(errors[0].Message, message.Message);
|
Assert.Equal(errors[0].GetMessage(), message.Message);
|
||||||
Assert.Equal(viewPath, message.SourceFilePath);
|
Assert.Equal(viewPath, message.SourceFilePath);
|
||||||
Assert.Equal(3, message.StartLine);
|
Assert.Equal(3, message.StartLine);
|
||||||
Assert.Equal(17, message.StartColumn);
|
Assert.Equal(17, message.StartColumn);
|
||||||
|
|
@ -193,7 +192,7 @@ namespace Microsoft.AspNetCore.Mvc.Razor.Internal
|
||||||
},
|
},
|
||||||
message =>
|
message =>
|
||||||
{
|
{
|
||||||
Assert.Equal(errors[1].Message, message.Message);
|
Assert.Equal(errors[1].GetMessage(), message.Message);
|
||||||
Assert.Equal(viewPath, message.SourceFilePath);
|
Assert.Equal(viewPath, message.SourceFilePath);
|
||||||
Assert.Equal(5, message.StartLine);
|
Assert.Equal(5, message.StartLine);
|
||||||
Assert.Equal(6, message.StartColumn);
|
Assert.Equal(6, message.StartColumn);
|
||||||
|
|
@ -202,7 +201,7 @@ namespace Microsoft.AspNetCore.Mvc.Razor.Internal
|
||||||
},
|
},
|
||||||
message =>
|
message =>
|
||||||
{
|
{
|
||||||
Assert.Equal(errors[2].Message, message.Message);
|
Assert.Equal(errors[2].GetMessage(), message.Message);
|
||||||
Assert.Equal(viewPath, message.SourceFilePath);
|
Assert.Equal(viewPath, message.SourceFilePath);
|
||||||
Assert.Equal(0, message.StartLine);
|
Assert.Equal(0, message.StartLine);
|
||||||
Assert.Equal(-1, message.StartColumn);
|
Assert.Equal(-1, message.StartColumn);
|
||||||
|
|
@ -217,7 +216,7 @@ namespace Microsoft.AspNetCore.Mvc.Razor.Internal
|
||||||
Assert.Collection(failure.Messages,
|
Assert.Collection(failure.Messages,
|
||||||
message =>
|
message =>
|
||||||
{
|
{
|
||||||
Assert.Equal(errors[3].Message, message.Message);
|
Assert.Equal(errors[3].GetMessage(), message.Message);
|
||||||
Assert.Equal(viewImportsPath, message.SourceFilePath);
|
Assert.Equal(viewImportsPath, message.SourceFilePath);
|
||||||
Assert.Equal(4, message.StartLine);
|
Assert.Equal(4, message.StartLine);
|
||||||
Assert.Equal(8, message.StartColumn);
|
Assert.Equal(8, message.StartColumn);
|
||||||
|
|
@ -235,5 +234,13 @@ namespace Microsoft.AspNetCore.Mvc.Razor.Internal
|
||||||
|
|
||||||
return options.Object;
|
return options.Object;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static RazorDiagnostic GetRazorDiagnostic(string message, SourceLocation sourceLocation, int length)
|
||||||
|
{
|
||||||
|
var diagnosticDescriptor = new RazorDiagnosticDescriptor("test-id", () => message, RazorDiagnosticSeverity.Error);
|
||||||
|
var sourceSpan = new SourceSpan(sourceLocation, length);
|
||||||
|
|
||||||
|
return RazorDiagnostic.Create(diagnosticDescriptor, sourceSpan);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue