Skip to content

Commit 7580777

Browse files
authored
[FUSE] Fix C# completion in empty explicit expression blocks (#11282)
Fixes #11280 Commit at a time is recommended, since the fix itself is really very simple, and the last commit is updating all of the baselines.
2 parents 5c6e320 + 7715748 commit 7580777

File tree

49 files changed

+634
-61
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+634
-61
lines changed

src/Compiler/Microsoft.AspNetCore.Razor.Language/test/IntegrationTests/ComponentCodeGenerationTestBase.cs

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2329,6 +2329,37 @@ public void InvalidCode_EmptyTransition()
23292329
]);
23302330
}
23312331

2332+
[IntegrationTestFact]
2333+
public void ExplicitExpression_HtmlOnly()
2334+
{
2335+
// Act
2336+
var generated = CompileToCSharp("""
2337+
@{
2338+
<p></p>
2339+
}
2340+
""");
2341+
2342+
// Assert
2343+
AssertDocumentNodeMatchesBaseline(generated.CodeDocument);
2344+
AssertCSharpDocumentMatchesBaseline(generated.CodeDocument);
2345+
CompileToAssembly(generated);
2346+
}
2347+
2348+
[IntegrationTestFact]
2349+
public void ExplicitExpression_Whitespace()
2350+
{
2351+
// Act
2352+
var generated = CompileToCSharp("""
2353+
@{
2354+
}
2355+
""");
2356+
2357+
// Assert
2358+
AssertDocumentNodeMatchesBaseline(generated.CodeDocument);
2359+
AssertCSharpDocumentMatchesBaseline(generated.CodeDocument);
2360+
CompileToAssembly(generated);
2361+
}
2362+
23322363
#endregion
23332364

23342365
#region Bind
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
// <auto-generated/>
2+
#pragma warning disable 1591
3+
namespace Test
4+
{
5+
#line default
6+
using global::System;
7+
using global::System.Collections.Generic;
8+
using global::System.Linq;
9+
using global::System.Threading.Tasks;
10+
using global::Microsoft.AspNetCore.Components;
11+
#line default
12+
#line hidden
13+
#nullable restore
14+
public partial class TestComponent : global::Microsoft.AspNetCore.Components.ComponentBase
15+
#nullable disable
16+
{
17+
#pragma warning disable 219
18+
private void __RazorDirectiveTokenHelpers__() {
19+
}
20+
#pragma warning restore 219
21+
#pragma warning disable 0414
22+
private static object __o = null;
23+
#pragma warning restore 0414
24+
#pragma warning disable 1998
25+
protected override void BuildRenderTree(global::Microsoft.AspNetCore.Components.Rendering.RenderTreeBuilder __builder)
26+
{
27+
28+
29+
30+
31+
}
32+
#pragma warning restore 1998
33+
}
34+
}
35+
#pragma warning restore 1591
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
Document -
2+
NamespaceDeclaration - - Test
3+
UsingDirective - (3:1,1 [20] ) - global::System
4+
UsingDirective - (26:2,1 [40] ) - global::System.Collections.Generic
5+
UsingDirective - (69:3,1 [25] ) - global::System.Linq
6+
UsingDirective - (97:4,1 [36] ) - global::System.Threading.Tasks
7+
UsingDirective - (136:5,1 [45] ) - global::Microsoft.AspNetCore.Components
8+
ClassDeclaration - - public partial - TestComponent - global::Microsoft.AspNetCore.Components.ComponentBase -
9+
DesignTimeDirective -
10+
CSharpCode -
11+
IntermediateToken - - CSharp - #pragma warning disable 0414
12+
CSharpCode -
13+
IntermediateToken - - CSharp - private static object __o = null;
14+
CSharpCode -
15+
IntermediateToken - - CSharp - #pragma warning restore 0414
16+
MethodDeclaration - - protected override - void - BuildRenderTree
17+
CSharpCode - (2:0,2 [6] x:\dir\subdir\Test\TestComponent.cshtml)
18+
LazyIntermediateToken - (2:0,2 [6] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - \n
19+
MarkupElement - (8:1,4 [7] x:\dir\subdir\Test\TestComponent.cshtml) - p
20+
CSharpCode - (15:1,11 [2] x:\dir\subdir\Test\TestComponent.cshtml)
21+
LazyIntermediateToken - (15:1,11 [2] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - \n
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
Source Location: (2:0,2 [6] x:\dir\subdir\Test\TestComponent.cshtml)
2+
|
3+
|
4+
Generated Location: (917:26,2 [6] )
5+
|
6+
|
7+
8+
Source Location: (15:1,11 [2] x:\dir\subdir\Test\TestComponent.cshtml)
9+
|
10+
|
11+
Generated Location: (936:28,11 [2] )
12+
|
13+
|
14+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
// <auto-generated/>
2+
#pragma warning disable 1591
3+
namespace Test
4+
{
5+
#line default
6+
using global::System;
7+
using global::System.Collections.Generic;
8+
using global::System.Linq;
9+
using global::System.Threading.Tasks;
10+
using global::Microsoft.AspNetCore.Components;
11+
#line default
12+
#line hidden
13+
#nullable restore
14+
public partial class TestComponent : global::Microsoft.AspNetCore.Components.ComponentBase
15+
#nullable disable
16+
{
17+
#pragma warning disable 219
18+
private void __RazorDirectiveTokenHelpers__() {
19+
}
20+
#pragma warning restore 219
21+
#pragma warning disable 0414
22+
private static object __o = null;
23+
#pragma warning restore 0414
24+
#pragma warning disable 1998
25+
protected override void BuildRenderTree(global::Microsoft.AspNetCore.Components.Rendering.RenderTreeBuilder __builder)
26+
{
27+
28+
29+
}
30+
#pragma warning restore 1998
31+
}
32+
}
33+
#pragma warning restore 1591
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
Document -
2+
NamespaceDeclaration - - Test
3+
UsingDirective - (3:1,1 [20] ) - global::System
4+
UsingDirective - (26:2,1 [40] ) - global::System.Collections.Generic
5+
UsingDirective - (69:3,1 [25] ) - global::System.Linq
6+
UsingDirective - (97:4,1 [36] ) - global::System.Threading.Tasks
7+
UsingDirective - (136:5,1 [45] ) - global::Microsoft.AspNetCore.Components
8+
ClassDeclaration - - public partial - TestComponent - global::Microsoft.AspNetCore.Components.ComponentBase -
9+
DesignTimeDirective -
10+
CSharpCode -
11+
IntermediateToken - - CSharp - #pragma warning disable 0414
12+
CSharpCode -
13+
IntermediateToken - - CSharp - private static object __o = null;
14+
CSharpCode -
15+
IntermediateToken - - CSharp - #pragma warning restore 0414
16+
MethodDeclaration - - protected override - void - BuildRenderTree
17+
CSharpCode - (2:0,2 [2] x:\dir\subdir\Test\TestComponent.cshtml)
18+
LazyIntermediateToken - (2:0,2 [2] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - \n
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
Source Location: (2:0,2 [2] x:\dir\subdir\Test\TestComponent.cshtml)
2+
|
3+
|
4+
Generated Location: (917:26,2 [2] )
5+
|
6+
|
7+
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
1-
Source Location: (2:0,2 [13] x:\dir\subdir\Test\TestComponent.razor)
1+
Source Location: (2:0,2 [13] x:\dir\subdir\Test\TestComponent.razor)
22
|
33
#if true
4-
|
5-
Generated Location: (986:28,2 [13] )
4+
|
5+
Generated Location: (986:28,2 [13] )
66
|
77
#if true
8-
|
9-
10-
Source Location: (20:3,2 [11] x:\dir\subdir\Test\TestComponent.razor)
8+
|
9+
10+
Source Location: (20:3,2 [11] x:\dir\subdir\Test\TestComponent.razor)
1111
|
1212
#endif
13-
|
14-
Generated Location: (1120:36,2 [11] )
13+
|
14+
Generated Location: (1120:36,2 [11] )
1515
|
1616
#endif
17-
|
18-
17+
|
18+

src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimeCodeGenerationTest/AtTransitions/TestComponent.codegen.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,14 @@ protected override void BuildRenderTree(global::Microsoft.AspNetCore.Components.
5353
#line hidden
5454
#nullable disable
5555
);
56+
#nullable restore
57+
#line (3,23)-(4,1) "x:\dir\subdir\Test\TestComponent.cshtml"
58+
59+
60+
#line default
61+
#line hidden
62+
#nullable disable
63+
5664
}
5765
#pragma warning restore 1998
5866
}

src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimeCodeGenerationTest/AtTransitions/TestComponent.mappings.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,10 @@ Source Location: (51:2,21 [1] x:\dir\subdir\Test\TestComponent.cshtml)
2222
Generated Location: (1276:49,0 [1] )
2323
|x|
2424

25+
Source Location: (52:2,22 [4] x:\dir\subdir\Test\TestComponent.cshtml)
26+
|
27+
|
28+
Generated Location: (1426:57,0 [4] )
29+
|
30+
|
31+

src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimeCodeGenerationTest/CanProduceLinePragmasForComponentWithRenderFragment_01/TestComponent.codegen.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,14 @@ protected override void BuildRenderTree(global::Microsoft.AspNetCore.Components.
3333
#nullable disable
3434
);
3535
__builder.CloseElement();
36+
#nullable restore
37+
#line (3,1)-(3,3) "x:\dir\subdir\Test\TestComponent.cshtml"
38+
39+
40+
#line default
41+
#line hidden
42+
#nullable disable
43+
3644
#nullable restore
3745
#line (3,4)-(5,1) "x:\dir\subdir\Test\TestComponent.cshtml"
3846
if (!Collapsed)

src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimeCodeGenerationTest/CanProduceLinePragmasForComponentWithRenderFragment_01/TestComponent.mappings.txt

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,24 +3,29 @@
33
Generated Location: (1094:28,0 [10] )
44
|ActionText|
55

6+
Source Location: (81:2,0 [2] x:\dir\subdir\Test\TestComponent.cshtml)
7+
| |
8+
Generated Location: (1291:37,0 [2] )
9+
| |
10+
611
Source Location: (84:2,3 [22] x:\dir\subdir\Test\TestComponent.cshtml)
712
|if (!Collapsed)
813
{
914
|
10-
Generated Location: (1291:37,0 [22] )
15+
Generated Location: (1427:45,0 [22] )
1116
|if (!Collapsed)
1217
{
1318
|
1419

1520
Source Location: (154:5,7 [12] x:\dir\subdir\Test\TestComponent.cshtml)
1621
|ChildContent|
17-
Generated Location: (1604:49,0 [12] )
22+
Generated Location: (1740:57,0 [12] )
1823
|ChildContent|
1924

2025
Source Location: (180:7,0 [5] x:\dir\subdir\Test\TestComponent.cshtml)
2126
| }
2227
|
23-
Generated Location: (1803:58,0 [5] )
28+
Generated Location: (1939:66,0 [5] )
2429
| }
2530
|
2631

@@ -36,7 +41,7 @@ Source Location: (201:10,1 [277] x:\dir\subdir\Test\TestComponent.cshtml)
3641
Collapsed = !Collapsed;
3742
}
3843
|
39-
Generated Location: (2030:69,0 [277] )
44+
Generated Location: (2166:77,0 [277] )
4045
|
4146
[Parameter]
4247
public RenderFragment ChildContent { get; set; } = (context) => <p>@context</p>

src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimeCodeGenerationTest/CanProduceLinePragmasForComponentWithRenderFragment_02/TestComponent.codegen.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,14 @@ protected override void BuildRenderTree(global::Microsoft.AspNetCore.Components.
3333
#nullable disable
3434
);
3535
__builder.CloseElement();
36+
#nullable restore
37+
#line (3,1)-(3,3) "x:\dir\subdir\Test\TestComponent.cshtml"
38+
39+
40+
#line default
41+
#line hidden
42+
#nullable disable
43+
3644
#nullable restore
3745
#line (3,4)-(5,1) "x:\dir\subdir\Test\TestComponent.cshtml"
3846
if (!Collapsed)

src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimeCodeGenerationTest/CanProduceLinePragmasForComponentWithRenderFragment_02/TestComponent.mappings.txt

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,39 +3,44 @@
33
Generated Location: (1094:28,0 [10] )
44
|ActionText|
55

6+
Source Location: (81:2,0 [2] x:\dir\subdir\Test\TestComponent.cshtml)
7+
| |
8+
Generated Location: (1291:37,0 [2] )
9+
| |
10+
611
Source Location: (84:2,3 [22] x:\dir\subdir\Test\TestComponent.cshtml)
712
|if (!Collapsed)
813
{
914
|
10-
Generated Location: (1291:37,0 [22] )
15+
Generated Location: (1427:45,0 [22] )
1116
|if (!Collapsed)
1217
{
1318
|
1419

1520
Source Location: (154:5,7 [12] x:\dir\subdir\Test\TestComponent.cshtml)
1621
|ChildContent|
17-
Generated Location: (1604:49,0 [12] )
22+
Generated Location: (1740:57,0 [12] )
1823
|ChildContent|
1924

2025
Source Location: (180:7,0 [5] x:\dir\subdir\Test\TestComponent.cshtml)
2126
| }
2227
|
23-
Generated Location: (1803:58,0 [5] )
28+
Generated Location: (1939:66,0 [5] )
2429
| }
2530
|
2631

2732
Source Location: (201:10,1 [91] x:\dir\subdir\Test\TestComponent.cshtml)
2833
|
2934
[Parameter]
3035
public RenderFragment<string> ChildContent { get; set; } = (context) => |
31-
Generated Location: (2031:69,0 [91] )
36+
Generated Location: (2167:77,0 [91] )
3237
|
3338
[Parameter]
3439
public RenderFragment<string> ChildContent { get; set; } = (context) => |
3540

3641
Source Location: (297:12,79 [7] x:\dir\subdir\Test\TestComponent.cshtml)
3742
|context|
38-
Generated Location: (2373:82,0 [7] )
43+
Generated Location: (2509:90,0 [7] )
3944
|context|
4045

4146
Source Location: (308:12,90 [180] x:\dir\subdir\Test\TestComponent.cshtml)
@@ -48,7 +53,7 @@ Source Location: (308:12,90 [180] x:\dir\subdir\Test\TestComponent.cshtml)
4853
Collapsed = !Collapsed;
4954
}
5055
|
51-
Generated Location: (2582:92,0 [180] )
56+
Generated Location: (2718:100,0 [180] )
5257
|;
5358
[Parameter]
5459
public bool Collapsed { get; set; }

src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimeCodeGenerationTest/Component_WithPreserveWhitespaceDirective_False/TestComponent.codegen.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,14 @@ public partial class TestComponent : global::Microsoft.AspNetCore.Components.Com
1818
protected override void BuildRenderTree(global::Microsoft.AspNetCore.Components.Rendering.RenderTreeBuilder __builder)
1919
{
2020
__builder.OpenElement(0, "ul");
21+
#nullable restore
22+
#line (4,1)-(4,5) "x:\dir\subdir\Test\TestComponent.cshtml"
23+
24+
25+
#line default
26+
#line hidden
27+
#nullable disable
28+
2129
#nullable restore
2230
#line (4,6)-(6,1) "x:\dir\subdir\Test\TestComponent.cshtml"
2331
foreach (var item in Enumerable.Range(1, 100))

0 commit comments

Comments
 (0)