Skip to content

Commit

Permalink
Render more TagHelper code at design time.
Browse files Browse the repository at this point in the history
- This is a pre-requisite to properly warnings users about TagHelpers in code blocks. With this change VS indicates that there's an asynchronous operation happening in a code block but because the code is auto-generated it happens behind the scenes and therefore always gets logged as a line 1 error (unusable). Therefore, to fix this issue there will be a partner PR that will go out in AspNetCore that adds analyzer errors for cases where `__tagHelperRunner.RunAsync` exists in code blocks that do not return `Task` and are not marked with `async` properly.
- Updated test files to reflect the new TagHelper codegen at design time.
- Note: This doesn't solve the `~/` case that will be in a follow up PR.

dotnet/aspnetcore#8630
  • Loading branch information
NTaylorMullen committed May 17, 2019
1 parent 0cbfa9b commit 17af3ef
Show file tree
Hide file tree
Showing 122 changed files with 786 additions and 364 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -151,16 +151,19 @@ public void WriteTagHelperExecute(CodeRenderingContext context, DefaultTagHelper
throw new InvalidOperationException(message);
}

// We always render `await __tagHelperRunner.RunAsync(__tagHelperExecutionContext);` to notify users of the requirement for a method
// to be asynchronous.

context.CodeWriter
.Write("await ")
.WriteStartInstanceMethodInvocation(
RunnerVariableName,
RunnerRunAsyncMethodName)
.Write(ExecutionContextVariableName)
.WriteEndMethodInvocation();

if (!context.Options.DesignTime)
{
context.CodeWriter
.Write("await ")
.WriteStartInstanceMethodInvocation(
RunnerVariableName,
RunnerRunAsyncMethodName)
.Write(ExecutionContextVariableName)
.WriteEndMethodInvocation();

var tagHelperOutputAccessor = $"{ExecutionContextVariableName}.{ExecutionContextOutputPropertyName}";

context.CodeWriter
Expand Down Expand Up @@ -472,27 +475,28 @@ public void WriteTagHelperProperty(CodeRenderingContext context, DefaultTagHelpe

public void WriteTagHelperRuntime(CodeRenderingContext context, DefaultTagHelperRuntimeIntermediateNode node)
{
context.CodeWriter.WriteLine("#line hidden");
context.CodeWriter.WriteLine("#pragma warning disable 0649");
context.CodeWriter.WriteField(PrivateModifiers, ExecutionContextTypeName, ExecutionContextVariableName);
context.CodeWriter.WriteLine("#pragma warning restore 0649");

context.CodeWriter
.Write("private ")
.Write(TagHelperRunnerTypeName)
.Write(" ")
.Write(RunnerVariableName)
.Write(" = new ")
.Write(TagHelperRunnerTypeName)
.WriteLine("();");

if (!context.Options.DesignTime)
{
context.CodeWriter.WriteLine("#line hidden");

// Need to disable the warning "X is never used." for the value buffer since
// whether it's used depends on how a TagHelper is used.
context.CodeWriter.WriteLine("#pragma warning disable 0169");
context.CodeWriter.WriteField(PrivateModifiers, "string", StringValueBufferVariableName);
context.CodeWriter.WriteLine("#pragma warning restore 0169");

context.CodeWriter.WriteField(PrivateModifiers, ExecutionContextTypeName, ExecutionContextVariableName);

context.CodeWriter
.Write("private ")
.Write(TagHelperRunnerTypeName)
.Write(" ")
.Write(RunnerVariableName)
.Write(" = new ")
.Write(TagHelperRunnerTypeName)
.WriteLine("();");

var backedScopeManageVariableName = "__backed" + ScopeManagerVariableName;
context.CodeWriter
.Write("private ")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ namespace AspNetCore
using Microsoft.AspNetCore.Mvc.ViewFeatures;
public class TestFiles_IntegrationTests_CodeGenerationIntegrationTest_ModelExpressionTagHelper : global::Microsoft.AspNetCore.Mvc.Razor.RazorPage<DateTime>
{
#line hidden
#pragma warning disable 0649
private global::Microsoft.AspNetCore.Razor.Runtime.TagHelpers.TagHelperExecutionContext __tagHelperExecutionContext;
#pragma warning restore 0649
private global::Microsoft.AspNetCore.Razor.Runtime.TagHelpers.TagHelperRunner __tagHelperRunner = new global::Microsoft.AspNetCore.Razor.Runtime.TagHelpers.TagHelperRunner();
private global::InputTestTagHelper __InputTestTagHelper;
#pragma warning disable 219
private void __RazorDirectiveTokenHelpers__() {
Expand Down Expand Up @@ -52,6 +57,7 @@ private void __RazorDirectiveTokenHelpers__() {
#line default
#line hidden
#nullable disable
await __tagHelperRunner.RunAsync(__tagHelperExecutionContext);
__InputTestTagHelper = CreateTagHelper<global::InputTestTagHelper>();
#nullable restore
#line 6 "TestFiles/IntegrationTests/CodeGenerationIntegrationTest/ModelExpressionTagHelper.cshtml"
Expand All @@ -60,6 +66,7 @@ private void __RazorDirectiveTokenHelpers__() {
#line default
#line hidden
#nullable disable
await __tagHelperRunner.RunAsync(__tagHelperExecutionContext);
}
#pragma warning restore 1998
[global::Microsoft.AspNetCore.Mvc.Razor.Internal.RazorInjectAttribute]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
Source Location: (7:0,7 [8] TestFiles/IntegrationTests/CodeGenerationIntegrationTest/ModelExpressionTagHelper.cshtml)
|DateTime|
Generated Location: (870:21,0 [8] )
Generated Location: (1278:26,0 [8] )
|DateTime|

Source Location: (33:2,14 [29] TestFiles/IntegrationTests/CodeGenerationIntegrationTest/ModelExpressionTagHelper.cshtml)
|"InputTestTagHelper, AppCode"|
Generated Location: (1180:31,37 [29] )
Generated Location: (1588:36,37 [29] )
|"InputTestTagHelper, AppCode"|

Source Location: (83:4,17 [4] TestFiles/IntegrationTests/CodeGenerationIntegrationTest/ModelExpressionTagHelper.cshtml)
|Date|
Generated Location: (1897:49,102 [4] )
Generated Location: (2305:54,102 [4] )
|Date|

Source Location: (111:5,18 [5] TestFiles/IntegrationTests/CodeGenerationIntegrationTest/ModelExpressionTagHelper.cshtml)
|Model|
Generated Location: (2251:57,94 [5] )
Generated Location: (2735:63,94 [5] )
|Model|

Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,13 @@ namespace AspNetCore
public class TestFiles_IntegrationTests_CodeGenerationIntegrationTest_ModelExpressionTagHelper : global::Microsoft.AspNetCore.Mvc.Razor.RazorPage<DateTime>
{
#line hidden
#pragma warning disable 0649
private global::Microsoft.AspNetCore.Razor.Runtime.TagHelpers.TagHelperExecutionContext __tagHelperExecutionContext;
#pragma warning restore 0649
private global::Microsoft.AspNetCore.Razor.Runtime.TagHelpers.TagHelperRunner __tagHelperRunner = new global::Microsoft.AspNetCore.Razor.Runtime.TagHelpers.TagHelperRunner();
#pragma warning disable 0169
private string __tagHelperStringValueBuffer;
#pragma warning restore 0169
private global::Microsoft.AspNetCore.Razor.Runtime.TagHelpers.TagHelperExecutionContext __tagHelperExecutionContext;
private global::Microsoft.AspNetCore.Razor.Runtime.TagHelpers.TagHelperRunner __tagHelperRunner = new global::Microsoft.AspNetCore.Razor.Runtime.TagHelpers.TagHelperRunner();
private global::Microsoft.AspNetCore.Razor.Runtime.TagHelpers.TagHelperScopeManager __backed__tagHelperScopeManager = null;
private global::Microsoft.AspNetCore.Razor.Runtime.TagHelpers.TagHelperScopeManager __tagHelperScopeManager
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ namespace AspNetCore
#nullable disable
public class TestFiles_IntegrationTests_CodeGenerationIntegrationTest_RazorPagesWithoutModel : global::Microsoft.AspNetCore.Mvc.RazorPages.Page
{
#line hidden
#pragma warning disable 0649
private global::Microsoft.AspNetCore.Razor.Runtime.TagHelpers.TagHelperExecutionContext __tagHelperExecutionContext;
#pragma warning restore 0649
private global::Microsoft.AspNetCore.Razor.Runtime.TagHelpers.TagHelperRunner __tagHelperRunner = new global::Microsoft.AspNetCore.Razor.Runtime.TagHelpers.TagHelperRunner();
private global::DivTagHelper __DivTagHelper;
#pragma warning disable 219
private void __RazorDirectiveTokenHelpers__() {
Expand All @@ -42,6 +47,7 @@ private void __RazorDirectiveTokenHelpers__() {
public async override global::System.Threading.Tasks.Task ExecuteAsync()
{
__DivTagHelper = CreateTagHelper<global::DivTagHelper>();
await __tagHelperRunner.RunAsync(__tagHelperExecutionContext);
#nullable restore
#line 25 "TestFiles/IntegrationTests/CodeGenerationIntegrationTest/RazorPagesWithoutModel.cshtml"
__o = Name;
Expand All @@ -50,9 +56,13 @@ private void __RazorDirectiveTokenHelpers__() {
#line hidden
#nullable disable
__DivTagHelper = CreateTagHelper<global::DivTagHelper>();
await __tagHelperRunner.RunAsync(__tagHelperExecutionContext);
__DivTagHelper = CreateTagHelper<global::DivTagHelper>();
await __tagHelperRunner.RunAsync(__tagHelperExecutionContext);
__DivTagHelper = CreateTagHelper<global::DivTagHelper>();
await __tagHelperRunner.RunAsync(__tagHelperExecutionContext);
__DivTagHelper = CreateTagHelper<global::DivTagHelper>();
await __tagHelperRunner.RunAsync(__tagHelperExecutionContext);
}
#pragma warning restore 1998
#nullable restore
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ Generated Location: (506:15,0 [41] )

Source Location: (23:2,14 [12] TestFiles/IntegrationTests/CodeGenerationIntegrationTest/RazorPagesWithoutModel.cshtml)
|"*, AppCode"|
Generated Location: (1092:28,37 [12] )
Generated Location: (1500:33,37 [12] )
|"*, AppCode"|

Source Location: (566:24,47 [4] TestFiles/IntegrationTests/CodeGenerationIntegrationTest/RazorPagesWithoutModel.cshtml)
|Name|
Generated Location: (1724:46,47 [4] )
Generated Location: (2208:52,47 [4] )
|Name|

Source Location: (95:5,12 [283] TestFiles/IntegrationTests/CodeGenerationIntegrationTest/RazorPagesWithoutModel.cshtml)
Expand All @@ -28,7 +28,7 @@ Source Location: (95:5,12 [283] TestFiles/IntegrationTests/CodeGenerationIntegra
public string Name { get; set; }
}
|
Generated Location: (2243:59,12 [283] )
Generated Location: (3031:69,12 [283] )
|
public IActionResult OnPost(Customer customer)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,13 @@ public class TestFiles_IntegrationTests_CodeGenerationIntegrationTest_RazorPages
private static readonly global::Microsoft.AspNetCore.Razor.TagHelpers.TagHelperAttribute __tagHelperAttribute_2 = new global::Microsoft.AspNetCore.Razor.TagHelpers.TagHelperAttribute("class", new global::Microsoft.AspNetCore.Html.HtmlString("form-group"), global::Microsoft.AspNetCore.Razor.TagHelpers.HtmlAttributeValueStyle.DoubleQuotes);
private static readonly global::Microsoft.AspNetCore.Razor.TagHelpers.TagHelperAttribute __tagHelperAttribute_3 = new global::Microsoft.AspNetCore.Razor.TagHelpers.TagHelperAttribute("class", new global::Microsoft.AspNetCore.Html.HtmlString("col-md-offset-2 col-md-10"), global::Microsoft.AspNetCore.Razor.TagHelpers.HtmlAttributeValueStyle.DoubleQuotes);
#line hidden
#pragma warning disable 0649
private global::Microsoft.AspNetCore.Razor.Runtime.TagHelpers.TagHelperExecutionContext __tagHelperExecutionContext;
#pragma warning restore 0649
private global::Microsoft.AspNetCore.Razor.Runtime.TagHelpers.TagHelperRunner __tagHelperRunner = new global::Microsoft.AspNetCore.Razor.Runtime.TagHelpers.TagHelperRunner();
#pragma warning disable 0169
private string __tagHelperStringValueBuffer;
#pragma warning restore 0169
private global::Microsoft.AspNetCore.Razor.Runtime.TagHelpers.TagHelperExecutionContext __tagHelperExecutionContext;
private global::Microsoft.AspNetCore.Razor.Runtime.TagHelpers.TagHelperRunner __tagHelperRunner = new global::Microsoft.AspNetCore.Razor.Runtime.TagHelpers.TagHelperRunner();
private global::Microsoft.AspNetCore.Razor.Runtime.TagHelpers.TagHelperScopeManager __backed__tagHelperScopeManager = null;
private global::Microsoft.AspNetCore.Razor.Runtime.TagHelpers.TagHelperScopeManager __tagHelperScopeManager
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ namespace AspNetCore
#nullable disable
public class TestFiles_IntegrationTests_CodeGenerationIntegrationTest_RazorPages : global::Microsoft.AspNetCore.Mvc.RazorPages.Page
{
#line hidden
#pragma warning disable 0649
private global::Microsoft.AspNetCore.Razor.Runtime.TagHelpers.TagHelperExecutionContext __tagHelperExecutionContext;
#pragma warning restore 0649
private global::Microsoft.AspNetCore.Razor.Runtime.TagHelpers.TagHelperRunner __tagHelperRunner = new global::Microsoft.AspNetCore.Razor.Runtime.TagHelpers.TagHelperRunner();
private global::DivTagHelper __DivTagHelper;
#pragma warning disable 219
private void __RazorDirectiveTokenHelpers__() {
Expand Down Expand Up @@ -52,6 +57,7 @@ private void __RazorDirectiveTokenHelpers__() {
public async override global::System.Threading.Tasks.Task ExecuteAsync()
{
__DivTagHelper = CreateTagHelper<global::DivTagHelper>();
await __tagHelperRunner.RunAsync(__tagHelperExecutionContext);
#nullable restore
#line 29 "TestFiles/IntegrationTests/CodeGenerationIntegrationTest/RazorPages.cshtml"
__o = Model.Name;
Expand All @@ -60,9 +66,13 @@ private void __RazorDirectiveTokenHelpers__() {
#line hidden
#nullable disable
__DivTagHelper = CreateTagHelper<global::DivTagHelper>();
await __tagHelperRunner.RunAsync(__tagHelperExecutionContext);
__DivTagHelper = CreateTagHelper<global::DivTagHelper>();
await __tagHelperRunner.RunAsync(__tagHelperExecutionContext);
__DivTagHelper = CreateTagHelper<global::DivTagHelper>();
await __tagHelperRunner.RunAsync(__tagHelperExecutionContext);
__DivTagHelper = CreateTagHelper<global::DivTagHelper>();
await __tagHelperRunner.RunAsync(__tagHelperExecutionContext);
}
#pragma warning restore 1998
#nullable restore
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,17 @@ Generated Location: (494:15,0 [41] )

Source Location: (16:2,7 [8] TestFiles/IntegrationTests/CodeGenerationIntegrationTest/RazorPages.cshtml)
|NewModel|
Generated Location: (1019:28,0 [8] )
Generated Location: (1427:33,0 [8] )
|NewModel|

Source Location: (40:3,14 [12] TestFiles/IntegrationTests/CodeGenerationIntegrationTest/RazorPages.cshtml)
|"*, AppCode"|
Generated Location: (1315:38,37 [12] )
Generated Location: (1723:43,37 [12] )
|"*, AppCode"|

Source Location: (661:28,47 [10] TestFiles/IntegrationTests/CodeGenerationIntegrationTest/RazorPages.cshtml)
|Model.Name|
Generated Location: (1935:56,47 [10] )
Generated Location: (2419:62,47 [10] )
|Model.Name|

Source Location: (112:6,12 [360] TestFiles/IntegrationTests/CodeGenerationIntegrationTest/RazorPages.cshtml)
Expand All @@ -36,7 +36,7 @@ Source Location: (112:6,12 [360] TestFiles/IntegrationTests/CodeGenerationIntegr
public string Name { get; set; }
}
|
Generated Location: (2448:69,12 [360] )
Generated Location: (3236:79,12 [360] )
|
public class NewModel : PageModel
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,13 @@ public class TestFiles_IntegrationTests_CodeGenerationIntegrationTest_RazorPages
private static readonly global::Microsoft.AspNetCore.Razor.TagHelpers.TagHelperAttribute __tagHelperAttribute_2 = new global::Microsoft.AspNetCore.Razor.TagHelpers.TagHelperAttribute("class", new global::Microsoft.AspNetCore.Html.HtmlString("form-group"), global::Microsoft.AspNetCore.Razor.TagHelpers.HtmlAttributeValueStyle.DoubleQuotes);
private static readonly global::Microsoft.AspNetCore.Razor.TagHelpers.TagHelperAttribute __tagHelperAttribute_3 = new global::Microsoft.AspNetCore.Razor.TagHelpers.TagHelperAttribute("class", new global::Microsoft.AspNetCore.Html.HtmlString("col-md-offset-2 col-md-10"), global::Microsoft.AspNetCore.Razor.TagHelpers.HtmlAttributeValueStyle.DoubleQuotes);
#line hidden
#pragma warning disable 0649
private global::Microsoft.AspNetCore.Razor.Runtime.TagHelpers.TagHelperExecutionContext __tagHelperExecutionContext;
#pragma warning restore 0649
private global::Microsoft.AspNetCore.Razor.Runtime.TagHelpers.TagHelperRunner __tagHelperRunner = new global::Microsoft.AspNetCore.Razor.Runtime.TagHelpers.TagHelperRunner();
#pragma warning disable 0169
private string __tagHelperStringValueBuffer;
#pragma warning restore 0169
private global::Microsoft.AspNetCore.Razor.Runtime.TagHelpers.TagHelperExecutionContext __tagHelperExecutionContext;
private global::Microsoft.AspNetCore.Razor.Runtime.TagHelpers.TagHelperRunner __tagHelperRunner = new global::Microsoft.AspNetCore.Razor.Runtime.TagHelpers.TagHelperRunner();
private global::Microsoft.AspNetCore.Razor.Runtime.TagHelpers.TagHelperScopeManager __backed__tagHelperScopeManager = null;
private global::Microsoft.AspNetCore.Razor.Runtime.TagHelpers.TagHelperScopeManager __tagHelperScopeManager
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ namespace AspNetCore
using Microsoft.AspNetCore.Mvc.ViewFeatures;
public class TestFiles_IntegrationTests_CodeGenerationIntegrationTest_Sections : global::Microsoft.AspNetCore.Mvc.Razor.RazorPage<DateTime>
{
#line hidden
#pragma warning disable 0649
private global::Microsoft.AspNetCore.Razor.Runtime.TagHelpers.TagHelperExecutionContext __tagHelperExecutionContext;
#pragma warning restore 0649
private global::Microsoft.AspNetCore.Razor.Runtime.TagHelpers.TagHelperRunner __tagHelperRunner = new global::Microsoft.AspNetCore.Razor.Runtime.TagHelpers.TagHelperRunner();
private global::InputTestTagHelper __InputTestTagHelper;
#pragma warning disable 219
private void __RazorDirectiveTokenHelpers__() {
Expand Down Expand Up @@ -71,6 +76,7 @@ private void __RazorDirectiveTokenHelpers__() {
#line default
#line hidden
#nullable disable
await __tagHelperRunner.RunAsync(__tagHelperExecutionContext);
}
);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,29 +1,29 @@
Source Location: (7:0,7 [8] TestFiles/IntegrationTests/CodeGenerationIntegrationTest/Sections.cshtml)
|DateTime|
Generated Location: (838:21,0 [8] )
Generated Location: (1246:26,0 [8] )
|DateTime|

Source Location: (33:2,14 [29] TestFiles/IntegrationTests/CodeGenerationIntegrationTest/Sections.cshtml)
|"InputTestTagHelper, AppCode"|
Generated Location: (1132:31,37 [29] )
Generated Location: (1540:36,37 [29] )
|"InputTestTagHelper, AppCode"|

Source Location: (152:10,9 [8] TestFiles/IntegrationTests/CodeGenerationIntegrationTest/Sections.cshtml)
|Section1|
Generated Location: (1400:41,22 [8] )
Generated Location: (1808:46,22 [8] )
|Section1|

Source Location: (68:4,2 [46] TestFiles/IntegrationTests/CodeGenerationIntegrationTest/Sections.cshtml)
|
Layout = "_SectionTestLayout.cshtml";
|
Generated Location: (1904:58,2 [46] )
Generated Location: (2312:63,2 [46] )
|
Layout = "_SectionTestLayout.cshtml";
|

Source Location: (222:12,21 [4] TestFiles/IntegrationTests/CodeGenerationIntegrationTest/Sections.cshtml)
|Date|
Generated Location: (2367:68,102 [4] )
Generated Location: (2775:73,102 [4] )
|Date|

Loading

0 comments on commit 17af3ef

Please sign in to comment.