Collate diagnositcs from Imports
This commit is contained in:
parent
871f9e43ca
commit
a034b2ed04
|
|
@ -3,7 +3,6 @@
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
|
||||||
using Microsoft.AspNetCore.Razor.Evolution.CodeGeneration;
|
using Microsoft.AspNetCore.Razor.Evolution.CodeGeneration;
|
||||||
using Microsoft.AspNetCore.Razor.Evolution.Intermediate;
|
using Microsoft.AspNetCore.Razor.Evolution.Intermediate;
|
||||||
using Microsoft.AspNetCore.Razor.Evolution.Legacy;
|
using Microsoft.AspNetCore.Razor.Evolution.Legacy;
|
||||||
|
|
@ -61,6 +60,12 @@ namespace Microsoft.AspNetCore.Razor.Evolution
|
||||||
|
|
||||||
var diagnostics = new List<RazorDiagnostic>();
|
var diagnostics = new List<RazorDiagnostic>();
|
||||||
diagnostics.AddRange(syntaxTree.Diagnostics);
|
diagnostics.AddRange(syntaxTree.Diagnostics);
|
||||||
|
|
||||||
|
var importSyntaxTrees = codeDocument.GetImportSyntaxTrees();
|
||||||
|
for (var i = 0; i < importSyntaxTrees?.Count; i++)
|
||||||
|
{
|
||||||
|
diagnostics.AddRange(importSyntaxTrees[i].Diagnostics);
|
||||||
|
}
|
||||||
diagnostics.AddRange(renderingContext.Diagnostics);
|
diagnostics.AddRange(renderingContext.Diagnostics);
|
||||||
|
|
||||||
var csharpDocument = new RazorCSharpDocument()
|
var csharpDocument = new RazorCSharpDocument()
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,6 @@
|
||||||
// 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.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using Microsoft.AspNetCore.Razor.Evolution.Legacy;
|
|
||||||
|
|
||||||
namespace Microsoft.AspNetCore.Razor.Evolution
|
namespace Microsoft.AspNetCore.Razor.Evolution
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -2,11 +2,10 @@
|
||||||
// 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 Microsoft.AspNetCore.Razor.Evolution.CodeGeneration;
|
||||||
using Microsoft.AspNetCore.Razor.Evolution.Intermediate;
|
using Microsoft.AspNetCore.Razor.Evolution.Intermediate;
|
||||||
using Microsoft.AspNetCore.Testing;
|
using Microsoft.AspNetCore.Testing;
|
||||||
using Xunit;
|
using Xunit;
|
||||||
using Microsoft.AspNetCore.Razor.Evolution.Legacy;
|
|
||||||
using Microsoft.AspNetCore.Razor.Evolution.CodeGeneration;
|
|
||||||
|
|
||||||
namespace Microsoft.AspNetCore.Razor.Evolution
|
namespace Microsoft.AspNetCore.Razor.Evolution
|
||||||
{
|
{
|
||||||
|
|
@ -75,5 +74,73 @@ namespace Microsoft.AspNetCore.Razor.Evolution
|
||||||
$"The document of kind 'test' does not have a '{nameof(RuntimeTarget)}'. " +
|
$"The document of kind 'test' does not have a '{nameof(RuntimeTarget)}'. " +
|
||||||
$"The document classifier must set a value for '{nameof(DocumentIRNode.Target)}'.");
|
$"The document classifier must set a value for '{nameof(DocumentIRNode.Target)}'.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void Execute_CollatesSyntaxDiagnosticsFromSourceDocument()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var phase = new DefaultRazorCSharpLoweringPhase();
|
||||||
|
var engine = RazorEngine.CreateEmpty(b => b.Phases.Add(phase));
|
||||||
|
var codeDocument = TestRazorCodeDocument.Create("<p class=@(");
|
||||||
|
codeDocument.SetSyntaxTree(RazorSyntaxTree.Parse(codeDocument.Source));
|
||||||
|
var options = RazorParserOptions.CreateDefaultOptions();
|
||||||
|
var irDocument = new DocumentIRNode()
|
||||||
|
{
|
||||||
|
DocumentKind = "test",
|
||||||
|
Target = RuntimeTarget.CreateDefault(codeDocument, options),
|
||||||
|
Options = options,
|
||||||
|
};
|
||||||
|
codeDocument.SetIRDocument(irDocument);
|
||||||
|
|
||||||
|
// Act
|
||||||
|
phase.Execute(codeDocument);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
var csharpDocument = codeDocument.GetCSharpDocument();
|
||||||
|
var diagnostic = Assert.Single(csharpDocument.Diagnostics);
|
||||||
|
Assert.Equal(@"The explicit expression block is missing a closing "")"" character. Make sure you have a matching "")"" character for all the ""("" characters within this block, and that none of the "")"" characters are being interpreted as markup.",
|
||||||
|
diagnostic.GetMessage());
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void Execute_CollatesSyntaxDiagnosticsFromImportDocuments()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var phase = new DefaultRazorCSharpLoweringPhase();
|
||||||
|
var engine = RazorEngine.CreateEmpty(b => b.Phases.Add(phase));
|
||||||
|
|
||||||
|
var codeDocument = TestRazorCodeDocument.CreateEmpty();
|
||||||
|
codeDocument.SetSyntaxTree(RazorSyntaxTree.Parse(codeDocument.Source));
|
||||||
|
codeDocument.SetImportSyntaxTrees(new[]
|
||||||
|
{
|
||||||
|
RazorSyntaxTree.Parse(TestRazorSourceDocument.Create("@ ")),
|
||||||
|
RazorSyntaxTree.Parse(TestRazorSourceDocument.Create("<p @(")),
|
||||||
|
});
|
||||||
|
var options = RazorParserOptions.CreateDefaultOptions();
|
||||||
|
var irDocument = new DocumentIRNode()
|
||||||
|
{
|
||||||
|
DocumentKind = "test",
|
||||||
|
Target = RuntimeTarget.CreateDefault(codeDocument, options),
|
||||||
|
Options = options,
|
||||||
|
};
|
||||||
|
codeDocument.SetIRDocument(irDocument);
|
||||||
|
|
||||||
|
// Act
|
||||||
|
phase.Execute(codeDocument);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
var csharpDocument = codeDocument.GetCSharpDocument();
|
||||||
|
Assert.Collection(csharpDocument.Diagnostics,
|
||||||
|
diagnostic =>
|
||||||
|
{
|
||||||
|
Assert.Equal(@"A space or line break was encountered after the ""@"" character. Only valid identifiers, keywords, comments, ""("" and ""{"" are valid at the start of a code block and they must occur immediately following ""@"" with no space in between.",
|
||||||
|
diagnostic.GetMessage());
|
||||||
|
},
|
||||||
|
diagnostic =>
|
||||||
|
{
|
||||||
|
Assert.Equal(@"The explicit expression block is missing a closing "")"" character. Make sure you have a matching "")"" character for all the ""("" characters within this block, and that none of the "")"" characters are being interpreted as markup.",
|
||||||
|
diagnostic.GetMessage());
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue