Don't generate line mappings for imports
This commit is contained in:
parent
6278dbeac5
commit
ae34e14358
|
|
@ -39,7 +39,9 @@ namespace Microsoft.AspNetCore.Razor.Evolution.CodeGeneration
|
|||
|
||||
internal IList<RazorDiagnostic> Diagnostics { get; } = new List<RazorDiagnostic>();
|
||||
|
||||
internal RazorSourceDocument SourceDocument { get; set; }
|
||||
internal RazorCodeDocument CodeDocument { get; set; }
|
||||
|
||||
internal RazorSourceDocument SourceDocument => CodeDocument?.Source;
|
||||
|
||||
internal RazorParserOptions Options { get; set; }
|
||||
|
||||
|
|
@ -60,6 +62,19 @@ namespace Microsoft.AspNetCore.Razor.Evolution.CodeGeneration
|
|||
return;
|
||||
}
|
||||
|
||||
var imports = CodeDocument.GetImportSyntaxTrees();
|
||||
if (imports != null)
|
||||
{
|
||||
for (var i = 0; i < imports.Count; i++)
|
||||
{
|
||||
if (string.Equals(imports[i].Source.FileName, node.Source.Value.FilePath, StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
// We don't want to generate line mappings for imports.
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var source = node.Source.Value;
|
||||
|
||||
var generatedLocation = new SourceSpan(Writer.GetCurrentSourceLocation(), source.Length);
|
||||
|
|
|
|||
|
|
@ -39,7 +39,7 @@ namespace Microsoft.AspNetCore.Razor.Evolution.CodeGeneration
|
|||
var token = node.Children[i] as RazorIRToken;
|
||||
if (token != null && token.IsCSharp)
|
||||
{
|
||||
AddLineMappingFor(token);
|
||||
Context.AddLineMappingFor(token);
|
||||
Context.Writer.Write(token.Content);
|
||||
}
|
||||
else
|
||||
|
|
@ -84,7 +84,7 @@ namespace Microsoft.AspNetCore.Razor.Evolution.CodeGeneration
|
|||
var padding = BuildOffsetPadding(0, node.Source.Value, Context);
|
||||
Context.Writer.Write(padding);
|
||||
|
||||
AddLineMappingFor(node);
|
||||
Context.AddLineMappingFor(node);
|
||||
Context.Writer.Write(node.Content);
|
||||
}
|
||||
}
|
||||
|
|
@ -117,7 +117,7 @@ namespace Microsoft.AspNetCore.Razor.Evolution.CodeGeneration
|
|||
{
|
||||
case DirectiveTokenKind.Type:
|
||||
|
||||
AddLineMappingFor(node);
|
||||
Context.AddLineMappingFor(node);
|
||||
Context.Writer
|
||||
.Write(node.Content)
|
||||
.Write(" ")
|
||||
|
|
@ -129,7 +129,7 @@ namespace Microsoft.AspNetCore.Razor.Evolution.CodeGeneration
|
|||
.Write(typeof(object).FullName)
|
||||
.Write(" ");
|
||||
|
||||
AddLineMappingFor(node);
|
||||
Context.AddLineMappingFor(node);
|
||||
Context.Writer
|
||||
.Write(node.Content)
|
||||
.WriteLine(" = null;");
|
||||
|
|
@ -142,13 +142,13 @@ namespace Microsoft.AspNetCore.Razor.Evolution.CodeGeneration
|
|||
|
||||
if (node.Content.StartsWith("\"", StringComparison.Ordinal))
|
||||
{
|
||||
AddLineMappingFor(node);
|
||||
Context.AddLineMappingFor(node);
|
||||
Context.Writer.Write(node.Content);
|
||||
}
|
||||
else
|
||||
{
|
||||
Context.Writer.Write("\"");
|
||||
AddLineMappingFor(node);
|
||||
Context.AddLineMappingFor(node);
|
||||
Context.Writer
|
||||
.Write(node.Content)
|
||||
.Write("\"");
|
||||
|
|
@ -287,21 +287,6 @@ namespace Microsoft.AspNetCore.Razor.Evolution.CodeGeneration
|
|||
}
|
||||
}
|
||||
|
||||
private void AddLineMappingFor(RazorIRNode node)
|
||||
{
|
||||
if (node.Source == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var source = node.Source.Value;
|
||||
|
||||
var generatedLocation = new SourceSpan(Context.Writer.GetCurrentSourceLocation(), source.Length);
|
||||
var lineMapping = new LineMapping(source, generatedLocation);
|
||||
|
||||
Context.LineMappings.Add(lineMapping);
|
||||
}
|
||||
|
||||
private void RenderTagHelperAttributeInline(
|
||||
RazorIRNode node,
|
||||
SourceSpan documentLocation)
|
||||
|
|
@ -317,7 +302,7 @@ namespace Microsoft.AspNetCore.Razor.Evolution.CodeGeneration
|
|||
{
|
||||
if (node.Source != null)
|
||||
{
|
||||
AddLineMappingFor(node);
|
||||
Context.AddLineMappingFor(node);
|
||||
}
|
||||
|
||||
Context.Writer.Write(((HtmlContentIRNode)node).Content);
|
||||
|
|
@ -326,7 +311,7 @@ namespace Microsoft.AspNetCore.Razor.Evolution.CodeGeneration
|
|||
{
|
||||
if (node.Source != null)
|
||||
{
|
||||
AddLineMappingFor(node);
|
||||
Context.AddLineMappingFor(node);
|
||||
}
|
||||
|
||||
Context.Writer.Write(token.Content);
|
||||
|
|
|
|||
|
|
@ -44,7 +44,7 @@ namespace Microsoft.AspNetCore.Razor.Evolution
|
|||
var renderingContext = new CSharpRenderingContext()
|
||||
{
|
||||
Writer = codeWriter,
|
||||
SourceDocument = codeDocument.Source,
|
||||
CodeDocument = codeDocument,
|
||||
Options = irDocument.Options,
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -124,11 +124,12 @@ __o = i++;
|
|||
{
|
||||
// Arrange
|
||||
var writer = new DesignTimeBasicWriter();
|
||||
var sourceDocument = TestRazorSourceDocument.Create(" @i++");
|
||||
|
||||
var context = new CSharpRenderingContext()
|
||||
{
|
||||
Options = RazorParserOptions.CreateDefaultOptions(),
|
||||
SourceDocument = TestRazorSourceDocument.Create(" @i++"),
|
||||
CodeDocument = RazorCodeDocument.Create(sourceDocument),
|
||||
Writer = new Legacy.CSharpCodeWriter(),
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -176,11 +176,12 @@ Test(test_writer, i++);
|
|||
{
|
||||
WriteCSharpExpressionMethod = "Test",
|
||||
};
|
||||
var sourceDocument = TestRazorSourceDocument.Create(" @i++");
|
||||
|
||||
var context = new CSharpRenderingContext()
|
||||
{
|
||||
Options = RazorParserOptions.CreateDefaultOptions(),
|
||||
SourceDocument = TestRazorSourceDocument.Create(" @i++"),
|
||||
CodeDocument = RazorCodeDocument.Create(sourceDocument),
|
||||
Writer = new Legacy.CSharpCodeWriter(),
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -136,11 +136,12 @@ Test(i++);
|
|||
{
|
||||
WriteCSharpExpressionMethod = "Test",
|
||||
};
|
||||
var sourceDocument = TestRazorSourceDocument.Create(" @i++");
|
||||
|
||||
var context = new CSharpRenderingContext()
|
||||
{
|
||||
Options = RazorParserOptions.CreateDefaultOptions(),
|
||||
SourceDocument = TestRazorSourceDocument.Create(" @i++"),
|
||||
CodeDocument = RazorCodeDocument.Create(sourceDocument),
|
||||
Writer = new Legacy.CSharpCodeWriter(),
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -18,10 +18,14 @@ using System.Text;
|
|||
|
||||
#line default
|
||||
#line hidden
|
||||
public class TestFiles_IntegrationTests_CodeGenerationIntegrationTest_BasicImports_DesignTime
|
||||
public class TestFiles_IntegrationTests_CodeGenerationIntegrationTest_BasicImports_DesignTime : Hello
|
||||
{
|
||||
#pragma warning disable 219
|
||||
private void __RazorDirectiveTokenHelpers__() {
|
||||
((System.Action)(() => {
|
||||
Hello __typeHelper = null;
|
||||
}
|
||||
))();
|
||||
}
|
||||
#pragma warning restore 219
|
||||
private static System.Object __o = null;
|
||||
|
|
|
|||
|
|
@ -6,10 +6,11 @@ Document -
|
|||
UsingStatement - (31:1,1 [26] BasicImports_Imports0.cshtml) - System.Globalization
|
||||
UsingStatement - (80:3,1 [27] BasicImports_Imports0.cshtml) - System.ComponentModel
|
||||
UsingStatement - (23:1,1 [18] BasicImports_Imports1.cshtml) - System.Text
|
||||
ClassDeclaration - - public - TestFiles_IntegrationTests_CodeGenerationIntegrationTest_BasicImports_DesignTime - -
|
||||
ClassDeclaration - - public - TestFiles_IntegrationTests_CodeGenerationIntegrationTest_BasicImports_DesignTime - Hello -
|
||||
DirectiveTokenHelper -
|
||||
CSharpStatement - - #pragma warning disable 219
|
||||
CSharpStatement - - private void __RazorDirectiveTokenHelpers__() {
|
||||
DirectiveToken - (119:4,10 [5] BasicImports_Imports0.cshtml) - Hello
|
||||
CSharpStatement - - }
|
||||
CSharpStatement - - #pragma warning restore 219
|
||||
CSharpStatement - - private static System.Object __o = null;
|
||||
|
|
|
|||
|
|
@ -2,3 +2,4 @@
|
|||
@using System.Globalization
|
||||
@("And also this")
|
||||
@using System.ComponentModel
|
||||
@inherits Hello
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@ using System.Text;
|
|||
|
||||
#line default
|
||||
#line hidden
|
||||
public class TestFiles_IntegrationTests_CodeGenerationIntegrationTest_BasicImports_Runtime
|
||||
public class TestFiles_IntegrationTests_CodeGenerationIntegrationTest_BasicImports_Runtime : Hello
|
||||
{
|
||||
#pragma warning disable 1998
|
||||
public async System.Threading.Tasks.Task ExecuteAsync()
|
||||
|
|
|
|||
|
|
@ -6,6 +6,6 @@ Document -
|
|||
UsingStatement - (31:1,1 [28] BasicImports_Imports0.cshtml) - System.Globalization
|
||||
UsingStatement - (80:3,1 [29] BasicImports_Imports0.cshtml) - System.ComponentModel
|
||||
UsingStatement - (23:1,1 [20] BasicImports_Imports1.cshtml) - System.Text
|
||||
ClassDeclaration - - public - TestFiles_IntegrationTests_CodeGenerationIntegrationTest_BasicImports_Runtime - -
|
||||
ClassDeclaration - - public - TestFiles_IntegrationTests_CodeGenerationIntegrationTest_BasicImports_Runtime - Hello -
|
||||
RazorMethodDeclaration - - public - async - System.Threading.Tasks.Task - ExecuteAsync
|
||||
HtmlContent - (0:0,0 [18] BasicImports.cshtml) - <p>Hi there!</p>\n
|
||||
|
|
|
|||
Loading…
Reference in New Issue