Skip to content

Commit

Permalink
Don't emit #line default and #line hidden between consecutive usi…
Browse files Browse the repository at this point in the history
…ng directives (#9991)

Fixes #9946
Fixes #8671

Roslyn won't offer to generate using directives into hidden regions
unless an instance of an `ISpanMappingService` [is
provided](https://github.com/dotnet/roslyn/blob/39848683a068122de144949117a9e5111bfd42ba/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/Core/AddImport/AddImportPlacementOptions.cs#L65).
In VS Code, and in future in cohosting, this is not the case. The fix I
am proposing here is to simply allow the using directive block to not be
in a hidden region. Most using directives are already fully mapped
anyway (with more coming with #9949)
and even for those that aren't mapped, since there is no debuggable code
in the using directive block, there seems to me to be no downside to
having default mappings. The change ensures that whatever comes after
the using directives (attributes, class declaration, something else in
future) is correctly hidden.

The only tooling changes here are tests. We could change the property
that Roslyn checks because it is now redundant, but turns out that is
[hardcoded in
Roslyn](https://github.com/dotnet/roslyn/blob/main/src/Tools/ExternalAccess/Razor/RazorSpanMappingServiceWrapper.cs#L29)
anyway. The tests are a little funny, because they only validate user
scenarios that already work today, but interestingly wouldn't have
worked in our test code before, as our test code does not have a span
mapping service.

NOTE: This will conflict with the above mentioned PR, but not in any
interesting ways.

Reviewing commit-at-a-time might make sense, if only to make things
easier because of the giant commit to update all of the test baselines.
  • Loading branch information
davidwengier authored Mar 6, 2024
2 parents 95dcdf7 + b7db571 commit 0d6d611
Show file tree
Hide file tree
Showing 1,529 changed files with 4,957 additions and 2,843 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#pragma warning disable 1591
namespace AspNetCore
{
#line hidden
#line default
using TModel = global::System.Object;
using System;
using System.Collections.Generic;
Expand All @@ -11,6 +11,8 @@ namespace AspNetCore
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Rendering;
using Microsoft.AspNetCore.Mvc.ViewFeatures;
#line default
#line hidden
public class TestFiles_IntegrationTests_CodeGenerationIntegrationTest_Basic : global::Microsoft.AspNetCore.Mvc.Razor.RazorPage<dynamic>
{
#pragma warning disable 219
Expand Down
Original file line number Diff line number Diff line change
@@ -1,34 +1,34 @@
Source Location: (13:0,13 [15] TestFiles/IntegrationTests/CodeGenerationIntegrationTest/Basic.cshtml)
|this.ToString()|
Generated Location: (1023:26,13 [15] )
Generated Location: (1061:28,13 [15] )
|this.ToString()|

Source Location: (54:2,5 [29] TestFiles/IntegrationTests/CodeGenerationIntegrationTest/Basic.cshtml)
|string.Format("{0}", "Hello")|
Generated Location: (1159:31,6 [29] )
Generated Location: (1197:33,6 [29] )
|string.Format("{0}", "Hello")|

Source Location: (95:4,2 [25] TestFiles/IntegrationTests/CodeGenerationIntegrationTest/Basic.cshtml)
|
var cls = "foo";
|
Generated Location: (1305:36,2 [25] )
Generated Location: (1343:38,2 [25] )
|
var cls = "foo";
|

Source Location: (134:7,11 [18] TestFiles/IntegrationTests/CodeGenerationIntegrationTest/Basic.cshtml)
|if(cls != null) { |
Generated Location: (1453:42,11 [18] )
Generated Location: (1491:44,11 [18] )
|if(cls != null) { |

Source Location: (153:7,30 [3] TestFiles/IntegrationTests/CodeGenerationIntegrationTest/Basic.cshtml)
|cls|
Generated Location: (1615:47,30 [3] )
Generated Location: (1653:49,30 [3] )
|cls|

Source Location: (156:7,33 [2] TestFiles/IntegrationTests/CodeGenerationIntegrationTest/Basic.cshtml)
| }|
Generated Location: (1766:52,33 [2] )
Generated Location: (1804:54,33 [2] )
| }|

Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#pragma warning disable 1591
namespace AspNetCore
{
#line hidden
#line default
using TModel = global::System.Object;
using System;
using System.Collections.Generic;
Expand All @@ -11,6 +11,8 @@ namespace AspNetCore
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Rendering;
using Microsoft.AspNetCore.Mvc.ViewFeatures;
#line default
#line hidden
public class TestFiles_IntegrationTests_CodeGenerationIntegrationTest_IncompleteDirectives : global::Microsoft.AspNetCore.Mvc.Razor.RazorPage<dynamic>
{
#pragma warning disable 219
Expand Down
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
Source Location: (102:3,7 [0] TestFiles/IntegrationTests/CodeGenerationIntegrationTest/IncompleteDirectives.cshtml)
||
Generated Location: (784:19,0 [0] )
Generated Location: (822:21,0 [0] )
||

Source Location: (123:6,8 [0] TestFiles/IntegrationTests/CodeGenerationIntegrationTest/IncompleteDirectives.cshtml)
||
Generated Location: (982:27,0 [0] )
Generated Location: (1020:29,0 [0] )
||

Source Location: (133:7,8 [17] TestFiles/IntegrationTests/CodeGenerationIntegrationTest/IncompleteDirectives.cshtml)
|MyService<TModel>|
Generated Location: (1180:35,0 [17] )
Generated Location: (1218:37,0 [17] )
|MyService<TModel>|

Source Location: (93:2,6 [0] TestFiles/IntegrationTests/CodeGenerationIntegrationTest/IncompleteDirectives.cshtml)
||
Generated Location: (1680:50,6 [0] )
Generated Location: (1718:52,6 [0] )
||

Source Location: (113:5,7 [0] TestFiles/IntegrationTests/CodeGenerationIntegrationTest/IncompleteDirectives.cshtml)
||
Generated Location: (1816:55,7 [0] )
Generated Location: (1854:57,7 [0] )
||

Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#pragma warning disable 1591
namespace AspNetCore
{
#line hidden
#line default
using TModel = global::System.Object;
using System;
using System.Collections.Generic;
Expand All @@ -11,6 +11,8 @@ namespace AspNetCore
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Rendering;
using Microsoft.AspNetCore.Mvc.ViewFeatures;
#line default
#line hidden
public class TestFiles_IntegrationTests_CodeGenerationIntegrationTest_InheritsViewModel : MyBasePageForViews<MyModel>
{
#pragma warning disable 219
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
Source Location: (10:0,10 [26] TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InheritsViewModel.cshtml)
|MyBasePageForViews<TModel>|
Generated Location: (748:19,0 [26] )
Generated Location: (786:21,0 [26] )
|MyBasePageForViews<TModel>|

Source Location: (45:1,7 [7] TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InheritsViewModel.cshtml)
|MyModel|
Generated Location: (992:27,0 [7] )
Generated Location: (1030:29,0 [7] )
|MyModel|

Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#pragma warning disable 1591
namespace AspNetCore
{
#line hidden
#line default
using TModel = global::System.Object;
using System;
using System.Collections.Generic;
Expand All @@ -11,6 +11,8 @@ namespace AspNetCore
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Rendering;
using Microsoft.AspNetCore.Mvc.ViewFeatures;
#line default
#line hidden
public class TestFiles_IntegrationTests_CodeGenerationIntegrationTest_InheritsWithViewImports : MyBasePageForViews<MyModel>
{
#pragma warning disable 219
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Source Location: (7:0,7 [7] TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InheritsWithViewImports.cshtml)
|MyModel|
Generated Location: (760:19,0 [7] )
Generated Location: (798:21,0 [7] )
|MyModel|

Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#pragma warning disable 1591
namespace AspNetCore
{
#line hidden
#line default
using TModel = global::System.Object;
using System;
using System.Collections.Generic;
Expand All @@ -11,6 +11,8 @@ namespace AspNetCore
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Rendering;
using Microsoft.AspNetCore.Mvc.ViewFeatures;
#line default
#line hidden
public class TestFiles_IntegrationTests_CodeGenerationIntegrationTest_InjectWithModel : global::Microsoft.AspNetCore.Mvc.Razor.RazorPage<MyModel>
{
#pragma warning disable 219
Expand Down
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
Source Location: (7:0,7 [7] TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InjectWithModel.cshtml)
|MyModel|
Generated Location: (774:19,0 [7] )
Generated Location: (812:21,0 [7] )
|MyModel|

Source Location: (24:1,8 [5] TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InjectWithModel.cshtml)
|MyApp|
Generated Location: (997:27,0 [5] )
Generated Location: (1035:29,0 [5] )
|MyApp|

Source Location: (30:1,14 [14] TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InjectWithModel.cshtml)
|MyPropertyName|
Generated Location: (1240:35,22 [14] )
Generated Location: (1278:37,22 [14] )
|MyPropertyName|

Source Location: (54:2,8 [17] TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InjectWithModel.cshtml)
|MyService<TModel>|
Generated Location: (1454:43,0 [17] )
Generated Location: (1492:45,0 [17] )
|MyService<TModel>|

Source Location: (72:2,26 [4] TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InjectWithModel.cshtml)
|Html|
Generated Location: (1709:51,22 [4] )
Generated Location: (1747:53,22 [4] )
|Html|

Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#pragma warning disable 1591
namespace AspNetCore
{
#line hidden
#line default
using TModel = global::System.Object;
using System;
using System.Collections.Generic;
Expand All @@ -11,6 +11,8 @@ namespace AspNetCore
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Rendering;
using Microsoft.AspNetCore.Mvc.ViewFeatures;
#line default
#line hidden
public class TestFiles_IntegrationTests_CodeGenerationIntegrationTest_InjectWithSemicolon : global::Microsoft.AspNetCore.Mvc.Razor.RazorPage<MyModel>
{
#pragma warning disable 219
Expand Down
Original file line number Diff line number Diff line change
@@ -1,45 +1,45 @@
Source Location: (7:0,7 [7] TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InjectWithSemicolon.cshtml)
|MyModel|
Generated Location: (782:19,0 [7] )
Generated Location: (820:21,0 [7] )
|MyModel|

Source Location: (24:1,8 [5] TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InjectWithSemicolon.cshtml)
|MyApp|
Generated Location: (1009:27,0 [5] )
Generated Location: (1047:29,0 [5] )
|MyApp|

Source Location: (30:1,14 [14] TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InjectWithSemicolon.cshtml)
|MyPropertyName|
Generated Location: (1256:35,22 [14] )
Generated Location: (1294:37,22 [14] )
|MyPropertyName|

Source Location: (58:2,8 [17] TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InjectWithSemicolon.cshtml)
|MyService<TModel>|
Generated Location: (1474:43,0 [17] )
Generated Location: (1512:45,0 [17] )
|MyService<TModel>|

Source Location: (76:2,26 [4] TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InjectWithSemicolon.cshtml)
|Html|
Generated Location: (1733:51,22 [4] )
Generated Location: (1771:53,22 [4] )
|Html|

Source Location: (93:3,8 [5] TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InjectWithSemicolon.cshtml)
|MyApp|
Generated Location: (1941:59,0 [5] )
Generated Location: (1979:61,0 [5] )
|MyApp|

Source Location: (99:3,14 [15] TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InjectWithSemicolon.cshtml)
|MyPropertyName2|
Generated Location: (2188:67,22 [15] )
Generated Location: (2226:69,22 [15] )
|MyPropertyName2|

Source Location: (129:4,8 [17] TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InjectWithSemicolon.cshtml)
|MyService<TModel>|
Generated Location: (2407:75,0 [17] )
Generated Location: (2445:77,0 [17] )
|MyService<TModel>|

Source Location: (147:4,26 [5] TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InjectWithSemicolon.cshtml)
|Html2|
Generated Location: (2666:83,22 [5] )
Generated Location: (2704:85,22 [5] )
|Html2|

Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#pragma warning disable 1591
namespace AspNetCore
{
#line hidden
#line default
using TModel = global::System.Object;
using System;
using System.Collections.Generic;
Expand All @@ -11,6 +11,8 @@ namespace AspNetCore
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Rendering;
using Microsoft.AspNetCore.Mvc.ViewFeatures;
#line default
#line hidden
public class TestFiles_IntegrationTests_CodeGenerationIntegrationTest_Inject : global::Microsoft.AspNetCore.Mvc.Razor.RazorPage<dynamic>
{
#pragma warning disable 219
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
Source Location: (8:0,8 [5] TestFiles/IntegrationTests/CodeGenerationIntegrationTest/Inject.cshtml)
|MyApp|
Generated Location: (756:19,0 [5] )
Generated Location: (794:21,0 [5] )
|MyApp|

Source Location: (14:0,14 [14] TestFiles/IntegrationTests/CodeGenerationIntegrationTest/Inject.cshtml)
|MyPropertyName|
Generated Location: (990:27,22 [14] )
Generated Location: (1028:29,22 [14] )
|MyPropertyName|

Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#pragma warning disable 1591
namespace AspNetCore
{
#line hidden
#line default
using TModel = global::System.Object;
using System;
using System.Collections.Generic;
Expand All @@ -11,6 +11,8 @@ namespace AspNetCore
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Rendering;
using Microsoft.AspNetCore.Mvc.ViewFeatures;
#line default
#line hidden
public class TestFiles_IntegrationTests_CodeGenerationIntegrationTest_InvalidNamespaceAtEOF : global::Microsoft.AspNetCore.Mvc.Razor.RazorPage<dynamic>
{
#pragma warning disable 219
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#pragma warning disable 1591
namespace AspNetCore
{
#line hidden
#line default
using TModel = global::System.Object;
using System;
using System.Collections.Generic;
Expand All @@ -11,6 +11,8 @@ namespace AspNetCore
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Rendering;
using Microsoft.AspNetCore.Mvc.ViewFeatures;
#line default
#line hidden
public class TestFiles_IntegrationTests_CodeGenerationIntegrationTest_ModelExpressionTagHelper : global::Microsoft.AspNetCore.Mvc.Razor.RazorPage<DateTime>
{
#line hidden
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: (1267:25,0 [8] )
Generated Location: (1305:27,0 [8] )
|DateTime|

Source Location: (33:2,14 [29] TestFiles/IntegrationTests/CodeGenerationIntegrationTest/ModelExpressionTagHelper.cshtml)
|"InputTestTagHelper, AppCode"|
Generated Location: (1537:33,37 [29] )
Generated Location: (1575:35,37 [29] )
|"InputTestTagHelper, AppCode"|

Source Location: (83:4,17 [4] TestFiles/IntegrationTests/CodeGenerationIntegrationTest/ModelExpressionTagHelper.cshtml)
|Date|
Generated Location: (2209:49,102 [4] )
Generated Location: (2247:51,102 [4] )
|Date|

Source Location: (111:5,18 [5] TestFiles/IntegrationTests/CodeGenerationIntegrationTest/ModelExpressionTagHelper.cshtml)
|Model|
Generated Location: (2601:56,94 [5] )
Generated Location: (2639:58,94 [5] )
|Model|

Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#pragma warning disable 1591
namespace AspNetCore
{
#line hidden
#line default
using TModel = global::System.Object;
using System;
using System.Collections.Generic;
Expand All @@ -11,6 +11,8 @@ namespace AspNetCore
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Rendering;
using Microsoft.AspNetCore.Mvc.ViewFeatures;
#line default
#line hidden
public class TestFiles_IntegrationTests_CodeGenerationIntegrationTest_Model : global::Microsoft.AspNetCore.Mvc.Razor.RazorPage<System.Collections.IEnumerable>
{
#pragma warning disable 219
Expand Down
Loading

0 comments on commit 0d6d611

Please sign in to comment.