Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FUSE] Fix C# completion in empty explicit expression blocks #11282

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2329,6 +2329,37 @@ public void InvalidCode_EmptyTransition()
]);
}

[IntegrationTestFact]
public void ExplicitExpression_HtmlOnly()
{
// Act
var generated = CompileToCSharp("""
@{
<p></p>
}
""");

// Assert
AssertDocumentNodeMatchesBaseline(generated.CodeDocument);
AssertCSharpDocumentMatchesBaseline(generated.CodeDocument);
CompileToAssembly(generated);
}

[IntegrationTestFact]
public void ExplicitExpression_Whitespace()
{
// Act
var generated = CompileToCSharp("""
@{
}
""");

// Assert
AssertDocumentNodeMatchesBaseline(generated.CodeDocument);
AssertCSharpDocumentMatchesBaseline(generated.CodeDocument);
CompileToAssembly(generated);
}

#endregion

#region Bind
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// <auto-generated/>
#pragma warning disable 1591
namespace Test
{
#line default
using global::System;
using global::System.Collections.Generic;
using global::System.Linq;
using global::System.Threading.Tasks;
using global::Microsoft.AspNetCore.Components;
#line default
#line hidden
#nullable restore
public partial class TestComponent : global::Microsoft.AspNetCore.Components.ComponentBase
#nullable disable
{
#pragma warning disable 219
private void __RazorDirectiveTokenHelpers__() {
}
#pragma warning restore 219
#pragma warning disable 0414
private static object __o = null;
#pragma warning restore 0414
#pragma warning disable 1998
protected override void BuildRenderTree(global::Microsoft.AspNetCore.Components.Rendering.RenderTreeBuilder __builder)
{




}
#pragma warning restore 1998
}
}
#pragma warning restore 1591
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
Document -
NamespaceDeclaration - - Test
UsingDirective - (3:1,1 [20] ) - global::System
UsingDirective - (26:2,1 [40] ) - global::System.Collections.Generic
UsingDirective - (69:3,1 [25] ) - global::System.Linq
UsingDirective - (97:4,1 [36] ) - global::System.Threading.Tasks
UsingDirective - (136:5,1 [45] ) - global::Microsoft.AspNetCore.Components
ClassDeclaration - - public partial - TestComponent - global::Microsoft.AspNetCore.Components.ComponentBase -
DesignTimeDirective -
CSharpCode -
IntermediateToken - - CSharp - #pragma warning disable 0414
CSharpCode -
IntermediateToken - - CSharp - private static object __o = null;
CSharpCode -
IntermediateToken - - CSharp - #pragma warning restore 0414
MethodDeclaration - - protected override - void - BuildRenderTree
CSharpCode - (2:0,2 [6] x:\dir\subdir\Test\TestComponent.cshtml)
LazyIntermediateToken - (2:0,2 [6] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - \n
MarkupElement - (8:1,4 [7] x:\dir\subdir\Test\TestComponent.cshtml) - p
CSharpCode - (15:1,11 [2] x:\dir\subdir\Test\TestComponent.cshtml)
LazyIntermediateToken - (15:1,11 [2] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - \n
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
Source Location: (2:0,2 [6] x:\dir\subdir\Test\TestComponent.cshtml)
|
|
Generated Location: (917:26,2 [6] )
|
|

Source Location: (15:1,11 [2] x:\dir\subdir\Test\TestComponent.cshtml)
|
|
Generated Location: (936:28,11 [2] )
|
|

Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// <auto-generated/>
#pragma warning disable 1591
namespace Test
{
#line default
using global::System;
using global::System.Collections.Generic;
using global::System.Linq;
using global::System.Threading.Tasks;
using global::Microsoft.AspNetCore.Components;
#line default
#line hidden
#nullable restore
public partial class TestComponent : global::Microsoft.AspNetCore.Components.ComponentBase
#nullable disable
{
#pragma warning disable 219
private void __RazorDirectiveTokenHelpers__() {
}
#pragma warning restore 219
#pragma warning disable 0414
private static object __o = null;
#pragma warning restore 0414
#pragma warning disable 1998
protected override void BuildRenderTree(global::Microsoft.AspNetCore.Components.Rendering.RenderTreeBuilder __builder)
{


}
#pragma warning restore 1998
}
}
#pragma warning restore 1591
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
Document -
NamespaceDeclaration - - Test
UsingDirective - (3:1,1 [20] ) - global::System
UsingDirective - (26:2,1 [40] ) - global::System.Collections.Generic
UsingDirective - (69:3,1 [25] ) - global::System.Linq
UsingDirective - (97:4,1 [36] ) - global::System.Threading.Tasks
UsingDirective - (136:5,1 [45] ) - global::Microsoft.AspNetCore.Components
ClassDeclaration - - public partial - TestComponent - global::Microsoft.AspNetCore.Components.ComponentBase -
DesignTimeDirective -
CSharpCode -
IntermediateToken - - CSharp - #pragma warning disable 0414
CSharpCode -
IntermediateToken - - CSharp - private static object __o = null;
CSharpCode -
IntermediateToken - - CSharp - #pragma warning restore 0414
MethodDeclaration - - protected override - void - BuildRenderTree
CSharpCode - (2:0,2 [2] x:\dir\subdir\Test\TestComponent.cshtml)
LazyIntermediateToken - (2:0,2 [2] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - \n
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Source Location: (2:0,2 [2] x:\dir\subdir\Test\TestComponent.cshtml)
|
|
Generated Location: (917:26,2 [2] )
|
|

Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
Source Location: (2:0,2 [13] x:\dir\subdir\Test\TestComponent.razor)
Source Location: (2:0,2 [13] x:\dir\subdir\Test\TestComponent.razor)
|
#if true
|
Generated Location: (986:28,2 [13] )
|
Generated Location: (986:28,2 [13] )
|
#if true
|

Source Location: (20:3,2 [11] x:\dir\subdir\Test\TestComponent.razor)
|
Source Location: (20:3,2 [11] x:\dir\subdir\Test\TestComponent.razor)
|
#endif
|
Generated Location: (1120:36,2 [11] )
|
Generated Location: (1120:36,2 [11] )
|
#endif
|

|
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,14 @@ protected override void BuildRenderTree(global::Microsoft.AspNetCore.Components.
#line hidden
#nullable disable
);
#nullable restore
#line (3,23)-(4,1) "x:\dir\subdir\Test\TestComponent.cshtml"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we avoid emitting #line pragmas for whitespace nodes? (We only need source mappings right?)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll let @chsienki comment on this, because he recently made it so that line pragmas and source mappings were 1:1 in runtime. Obviously at that point whitespace wouldn't have been part of it, but I'm not sure which priority wins.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My original assumption here was that at some point in the future, we may not have any source mappings: if we're getting the docs from the generator, we might not have the back channel for the mappings.

I think with the current architecture that's actually not going to be true, but I do think its a good idea to maintain a 1-1 mapping, so the source doc contains all the information (especially for some of our strategic partners who are using the line pragmas only)



#line default
#line hidden
#nullable disable

}
#pragma warning restore 1998
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,10 @@ Source Location: (51:2,21 [1] x:\dir\subdir\Test\TestComponent.cshtml)
Generated Location: (1276:49,0 [1] )
|x|

Source Location: (52:2,22 [4] x:\dir\subdir\Test\TestComponent.cshtml)
|
|
Generated Location: (1426:57,0 [4] )
|
|

Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,14 @@ protected override void BuildRenderTree(global::Microsoft.AspNetCore.Components.
#nullable disable
);
__builder.CloseElement();
#nullable restore
#line (3,1)-(3,3) "x:\dir\subdir\Test\TestComponent.cshtml"


#line default
#line hidden
#nullable disable

#nullable restore
#line (3,4)-(5,1) "x:\dir\subdir\Test\TestComponent.cshtml"
if (!Collapsed)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,29 @@
Generated Location: (1094:28,0 [10] )
|ActionText|

Source Location: (81:2,0 [2] x:\dir\subdir\Test\TestComponent.cshtml)
| |
Generated Location: (1291:37,0 [2] )
| |

Source Location: (84:2,3 [22] x:\dir\subdir\Test\TestComponent.cshtml)
|if (!Collapsed)
{
|
Generated Location: (1291:37,0 [22] )
Generated Location: (1427:45,0 [22] )
|if (!Collapsed)
{
|

Source Location: (154:5,7 [12] x:\dir\subdir\Test\TestComponent.cshtml)
|ChildContent|
Generated Location: (1604:49,0 [12] )
Generated Location: (1740:57,0 [12] )
|ChildContent|

Source Location: (180:7,0 [5] x:\dir\subdir\Test\TestComponent.cshtml)
| }
|
Generated Location: (1803:58,0 [5] )
Generated Location: (1939:66,0 [5] )
| }
|

Expand All @@ -36,7 +41,7 @@ Source Location: (201:10,1 [277] x:\dir\subdir\Test\TestComponent.cshtml)
Collapsed = !Collapsed;
}
|
Generated Location: (2030:69,0 [277] )
Generated Location: (2166:77,0 [277] )
|
[Parameter]
public RenderFragment ChildContent { get; set; } = (context) => <p>@context</p>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,14 @@ protected override void BuildRenderTree(global::Microsoft.AspNetCore.Components.
#nullable disable
);
__builder.CloseElement();
#nullable restore
#line (3,1)-(3,3) "x:\dir\subdir\Test\TestComponent.cshtml"


#line default
#line hidden
#nullable disable

#nullable restore
#line (3,4)-(5,1) "x:\dir\subdir\Test\TestComponent.cshtml"
if (!Collapsed)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,39 +3,44 @@
Generated Location: (1094:28,0 [10] )
|ActionText|

Source Location: (81:2,0 [2] x:\dir\subdir\Test\TestComponent.cshtml)
| |
Generated Location: (1291:37,0 [2] )
| |

Source Location: (84:2,3 [22] x:\dir\subdir\Test\TestComponent.cshtml)
|if (!Collapsed)
{
|
Generated Location: (1291:37,0 [22] )
Generated Location: (1427:45,0 [22] )
|if (!Collapsed)
{
|

Source Location: (154:5,7 [12] x:\dir\subdir\Test\TestComponent.cshtml)
|ChildContent|
Generated Location: (1604:49,0 [12] )
Generated Location: (1740:57,0 [12] )
|ChildContent|

Source Location: (180:7,0 [5] x:\dir\subdir\Test\TestComponent.cshtml)
| }
|
Generated Location: (1803:58,0 [5] )
Generated Location: (1939:66,0 [5] )
| }
|

Source Location: (201:10,1 [91] x:\dir\subdir\Test\TestComponent.cshtml)
|
[Parameter]
public RenderFragment<string> ChildContent { get; set; } = (context) => |
Generated Location: (2031:69,0 [91] )
Generated Location: (2167:77,0 [91] )
|
[Parameter]
public RenderFragment<string> ChildContent { get; set; } = (context) => |

Source Location: (297:12,79 [7] x:\dir\subdir\Test\TestComponent.cshtml)
|context|
Generated Location: (2373:82,0 [7] )
Generated Location: (2509:90,0 [7] )
|context|

Source Location: (308:12,90 [180] x:\dir\subdir\Test\TestComponent.cshtml)
Expand All @@ -48,7 +53,7 @@ Source Location: (308:12,90 [180] x:\dir\subdir\Test\TestComponent.cshtml)
Collapsed = !Collapsed;
}
|
Generated Location: (2582:92,0 [180] )
Generated Location: (2718:100,0 [180] )
|;
[Parameter]
public bool Collapsed { get; set; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,14 @@ public partial class TestComponent : global::Microsoft.AspNetCore.Components.Com
protected override void BuildRenderTree(global::Microsoft.AspNetCore.Components.Rendering.RenderTreeBuilder __builder)
{
__builder.OpenElement(0, "ul");
#nullable restore
#line (4,1)-(4,5) "x:\dir\subdir\Test\TestComponent.cshtml"


#line default
#line hidden
#nullable disable

#nullable restore
#line (4,6)-(6,1) "x:\dir\subdir\Test\TestComponent.cshtml"
foreach (var item in Enumerable.Range(1, 100))
Expand Down
Loading
Loading