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