Skip to content

Add Blazor partial class support in Visual Studio. #1182

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

Merged
merged 1 commit into from
Oct 1, 2019
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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ protected override void OnDocumentStructureCreated(
@class.ClassName = computedClass;
@class.Modifiers.Clear();
@class.Modifiers.Add("public");
@class.Modifiers.Add("partial");
Copy link
Member

Choose a reason for hiding this comment

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

Do we need to target this per-version? I guess not because it's not really a breaking change?

Copy link
Member

Choose a reason for hiding this comment

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

@pranavkm - @ajaybhargavb did we build a 3.1 versioning scheme into the SDK yet?

Copy link
Member

Choose a reason for hiding this comment

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

I think it's simpler for now if we just make this change happen to both 3.0 and 3.1 projects.

Copy link
Contributor

Choose a reason for hiding this comment

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

Don't think so. 3.0 is still the latest.


if (FileKinds.IsComponentImport(codeDocument.GetFileKind()))
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,8 @@ internal virtual void Workspace_WorkspaceChanged(object sender, WorkspaceChangeE

// Using EndsWith because Path.GetExtension will ignore everything before .cs
// Using Ordinal because the SDK generates these filenames.
if (document.FilePath.EndsWith(".cshtml.g.cs", StringComparison.Ordinal) || document.FilePath.EndsWith(".razor.g.cs", StringComparison.Ordinal))
// Stll have .cshtml.g.cs and .razor.g.cs for Razor.VSCode scenarios.
if (document.FilePath.EndsWith(".cshtml.g.cs", StringComparison.Ordinal) || document.FilePath.EndsWith(".razor.g.cs", StringComparison.Ordinal) || document.FilePath.EndsWith(".razor", StringComparison.Ordinal))
{
EnqueueUpdate(e.ProjectId);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,10 +123,6 @@ Copyright (c) .NET Foundation. All rights reserved.
<ItemGroup>
<FileWrites Include="@(_RazorComponentDeclaration)" />
</ItemGroup>

<ItemGroup Condition="'$(DesignTimeBuild)'=='true'">
<Compile Include="@(_RazorComponentDeclaration)" />
</ItemGroup>
</Target>

<Target
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,20 +47,6 @@ Copyright (c) .NET Foundation. All rights reserved.
<ProjectCapability Include="SupportsTypeScriptNuGet" />
</ItemGroup>

<!--
For now we need to treat component files as if they have a single file generator. This will allow us
to trigger a workspace update for the declaration files when they change.
-->
<ItemGroup>
Copy link
Author

Choose a reason for hiding this comment

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

Shoot we need to make this dependent on > 3.0 projects. Otherwise if a user downloads latest VS it will not properly work with older projects.

<Content Update="**\*.razor">
<Generator>MSBuild:RazorGenerateComponentDeclarationDesignTime</Generator>
</Content>

<Content Update="$(_RazorComponentInclude)">
<Generator>MSBuild:RazorGenerateComponentDeclarationDesignTime</Generator>
</Content>
</ItemGroup>

<!--
WebSdk imports these capabilities for nesting in DotNetCoreWeb projects.
Conditinally import these capabilities if the project isn't targeting the WebSdk.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,6 @@ public RazorProjectEngine Create(RazorConfiguration configuration, RazorProjectF
CompilerFeatures.Register(b);

configure?.Invoke(b);

// See comments on MangleClassNames
var componentDocumentClassifier = b.Features.OfType<ComponentDocumentClassifierPass>().FirstOrDefault();
if (componentDocumentClassifier != null)
{
componentDocumentClassifier.MangleClassNames = true;
}
});
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,6 @@ public RazorProjectEngine Create(RazorConfiguration configuration, RazorProjectF

initializer.Initialize(b);
configure?.Invoke(b);

// See comments on MangleClassNames
var componentDocumentClassifier = b.Features.OfType<ComponentDocumentClassifierPass>().FirstOrDefault();
if (componentDocumentClassifier != null)
{
componentDocumentClassifier.MangleClassNames = true;
Copy link
Member

Choose a reason for hiding this comment

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

Can we also remove support for MangleClassNames?

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah but there are some places it is used like in DefaultTagHelperBinderPhase so it will take some time to make sure removing it doesn't break that code. I'm going to address this as part of a new PR targeting preview3.

}
});
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace __GeneratedComponent
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Components;
public class AspNetCore_d3c3d6059615673cb46fc4974164d61eabadb890 : Microsoft.AspNetCore.Components.ComponentBase, IDisposable
public partial class AspNetCore_d3c3d6059615673cb46fc4974164d61eabadb890 : Microsoft.AspNetCore.Components.ComponentBase, IDisposable
{
#pragma warning disable 219
private void __RazorDirectiveTokenHelpers__() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Document -
UsingDirective - (51:2,1 [17] ) - System.Linq
UsingDirective - (71:3,1 [28] ) - System.Threading.Tasks
UsingDirective - (102:4,1 [37] ) - Microsoft.AspNetCore.Components
ClassDeclaration - - public - AspNetCore_d3c3d6059615673cb46fc4974164d61eabadb890 - Microsoft.AspNetCore.Components.ComponentBase - IDisposable
ClassDeclaration - - public partial - AspNetCore_d3c3d6059615673cb46fc4974164d61eabadb890 - Microsoft.AspNetCore.Components.ComponentBase - IDisposable
DesignTimeDirective -
DirectiveToken - (12:0,12 [11] BasicComponent.cshtml) - IDisposable
CSharpCode -
Expand Down
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
Source Location: (12:0,12 [11] TestFiles/IntegrationTests/CodeGenerationIntegrationTest/BasicComponent.cshtml)
|IDisposable|
Generated Location: (641:17,0 [11] )
Generated Location: (649:17,0 [11] )
|IDisposable|

Source Location: (38:1,13 [15] TestFiles/IntegrationTests/CodeGenerationIntegrationTest/BasicComponent.cshtml)
|this.ToString()|
Generated Location: (1240:35,13 [15] )
Generated Location: (1248:35,13 [15] )
|this.ToString()|

Source Location: (79:3,5 [29] TestFiles/IntegrationTests/CodeGenerationIntegrationTest/BasicComponent.cshtml)
|string.Format("{0}", "Hello")|
Generated Location: (1437:43,6 [29] )
Generated Location: (1445:43,6 [29] )
|string.Format("{0}", "Hello")|

Source Location: (132:6,12 [37] TestFiles/IntegrationTests/CodeGenerationIntegrationTest/BasicComponent.cshtml)
|
void IDisposable.Dispose(){ }
|
Generated Location: (1689:52,12 [37] )
Generated Location: (1697:52,12 [37] )
|
void IDisposable.Dispose(){ }
|
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ namespace __GeneratedComponent
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Components;
public class AspNetCore_d3c3d6059615673cb46fc4974164d61eabadb890 : Microsoft.AspNetCore.Components.ComponentBase, IDisposable
public partial class AspNetCore_d3c3d6059615673cb46fc4974164d61eabadb890 : Microsoft.AspNetCore.Components.ComponentBase, IDisposable
{
#pragma warning disable 1998
protected override void BuildRenderTree(Microsoft.AspNetCore.Components.Rendering.RenderTreeBuilder __builder)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Document -
UsingDirective - (51:2,1 [19] ) - System.Linq
UsingDirective - (71:3,1 [30] ) - System.Threading.Tasks
UsingDirective - (102:4,1 [37] ) - Microsoft.AspNetCore.Components
ClassDeclaration - - public - AspNetCore_d3c3d6059615673cb46fc4974164d61eabadb890 - Microsoft.AspNetCore.Components.ComponentBase - IDisposable
ClassDeclaration - - public partial - AspNetCore_d3c3d6059615673cb46fc4974164d61eabadb890 - Microsoft.AspNetCore.Components.ComponentBase - IDisposable
MethodDeclaration - - protected override - void - BuildRenderTree
MarkupElement - (25:1,0 [91] BasicComponent.cshtml) - div
HtmlAttribute - (29:1,4 [25] BasicComponent.cshtml) - class=" - "
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public void ComponentDocumentClassifierPass_SetsClass()

// Assert
Assert.Equal($"{ComponentsApi.ComponentBase.FullTypeName}", visitor.Class.BaseType);
Assert.Equal(new[] { "public", }, visitor.Class.Modifiers);
Assert.Equal(new[] { "public", "partial" }, visitor.Class.Modifiers);
Assert.Equal("Test", visitor.Class.ClassName);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ namespace Test
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Components;
public class TestComponent : Microsoft.AspNetCore.Components.ComponentBase
public partial class TestComponent : Microsoft.AspNetCore.Components.ComponentBase
{
#pragma warning disable 1998
protected override void BuildRenderTree(Microsoft.AspNetCore.Components.Rendering.RenderTreeBuilder __builder)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ namespace Test
#line default
#line hidden
#nullable disable
public class TestComponent : Microsoft.AspNetCore.Components.ComponentBase
public partial class TestComponent : Microsoft.AspNetCore.Components.ComponentBase
{
#pragma warning disable 219
private void __RazorDirectiveTokenHelpers__() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Document -
UsingDirective - (104:5,1 [37] ) - Microsoft.AspNetCore.Components
UsingDirective - (1:0,1 [28] x:\dir\subdir\Test\TestComponent.cshtml) - System.Threading.Tasks
UsingDirective - (32:1,1 [41] x:\dir\subdir\Test\TestComponent.cshtml) - Microsoft.AspNetCore.Components.Web
ClassDeclaration - - public - TestComponent - Microsoft.AspNetCore.Components.ComponentBase -
ClassDeclaration - - public partial - TestComponent - Microsoft.AspNetCore.Components.ComponentBase -
DesignTimeDirective -
CSharpCode -
IntermediateToken - - CSharp - #pragma warning disable 0414
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ Generated Location: (436:18,0 [41] )

Source Location: (94:2,19 [33] x:\dir\subdir\Test\TestComponent.cshtml)
|async (e) => await Task.Delay(10)|
Generated Location: (1282:38,19 [33] )
Generated Location: (1290:38,19 [33] )
|async (e) => await Task.Delay(10)|

Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ namespace Test
#line default
#line hidden
#nullable disable
public class TestComponent : Microsoft.AspNetCore.Components.ComponentBase
public partial class TestComponent : Microsoft.AspNetCore.Components.ComponentBase
{
#pragma warning disable 219
private void __RazorDirectiveTokenHelpers__() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Document -
UsingDirective - (104:5,1 [37] ) - Microsoft.AspNetCore.Components
UsingDirective - (1:0,1 [28] x:\dir\subdir\Test\TestComponent.cshtml) - System.Threading.Tasks
UsingDirective - (32:1,1 [41] x:\dir\subdir\Test\TestComponent.cshtml) - Microsoft.AspNetCore.Components.Web
ClassDeclaration - - public - TestComponent - Microsoft.AspNetCore.Components.ComponentBase -
ClassDeclaration - - public partial - TestComponent - Microsoft.AspNetCore.Components.ComponentBase -
DesignTimeDirective -
CSharpCode -
IntermediateToken - - CSharp - #pragma warning disable 0414
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Generated Location: (436:18,0 [41] )

Source Location: (92:2,17 [7] x:\dir\subdir\Test\TestComponent.cshtml)
|OnClick|
Generated Location: (1280:38,17 [7] )
Generated Location: (1288:38,17 [7] )
|OnClick|

Source Location: (112:3,7 [89] x:\dir\subdir\Test\TestComponent.cshtml)
Expand All @@ -20,7 +20,7 @@ Source Location: (112:3,7 [89] x:\dir\subdir\Test\TestComponent.cshtml)
return Task.CompletedTask;
}
|
Generated Location: (1481:48,7 [89] )
Generated Location: (1489:48,7 [89] )
|
Task OnClick(MouseEventArgs e)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ namespace Test
#line default
#line hidden
#nullable disable
public class TestComponent : Microsoft.AspNetCore.Components.ComponentBase
public partial class TestComponent : Microsoft.AspNetCore.Components.ComponentBase
{
#pragma warning disable 219
private void __RazorDirectiveTokenHelpers__() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Document -
UsingDirective - (104:5,1 [37] ) - Microsoft.AspNetCore.Components
UsingDirective - (1:0,1 [28] x:\dir\subdir\Test\TestComponent.cshtml) - System.Threading.Tasks
UsingDirective - (32:1,1 [41] x:\dir\subdir\Test\TestComponent.cshtml) - Microsoft.AspNetCore.Components.Web
ClassDeclaration - - public - TestComponent - Microsoft.AspNetCore.Components.ComponentBase -
ClassDeclaration - - public partial - TestComponent - Microsoft.AspNetCore.Components.ComponentBase -
DesignTimeDirective -
CSharpCode -
IntermediateToken - - CSharp - #pragma warning disable 0414
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ Generated Location: (436:18,0 [41] )

Source Location: (94:2,19 [32] x:\dir\subdir\Test\TestComponent.cshtml)
|async () => await Task.Delay(10)|
Generated Location: (1282:38,19 [32] )
Generated Location: (1290:38,19 [32] )
|async () => await Task.Delay(10)|

Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ namespace Test
#line default
#line hidden
#nullable disable
public class TestComponent : Microsoft.AspNetCore.Components.ComponentBase
public partial class TestComponent : Microsoft.AspNetCore.Components.ComponentBase
{
#pragma warning disable 219
private void __RazorDirectiveTokenHelpers__() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Document -
UsingDirective - (104:5,1 [37] ) - Microsoft.AspNetCore.Components
UsingDirective - (1:0,1 [28] x:\dir\subdir\Test\TestComponent.cshtml) - System.Threading.Tasks
UsingDirective - (32:1,1 [41] x:\dir\subdir\Test\TestComponent.cshtml) - Microsoft.AspNetCore.Components.Web
ClassDeclaration - - public - TestComponent - Microsoft.AspNetCore.Components.ComponentBase -
ClassDeclaration - - public partial - TestComponent - Microsoft.AspNetCore.Components.ComponentBase -
DesignTimeDirective -
CSharpCode -
IntermediateToken - - CSharp - #pragma warning disable 0414
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Generated Location: (436:18,0 [41] )

Source Location: (92:2,17 [7] x:\dir\subdir\Test\TestComponent.cshtml)
|OnClick|
Generated Location: (1280:38,17 [7] )
Generated Location: (1288:38,17 [7] )
|OnClick|

Source Location: (112:3,7 [73] x:\dir\subdir\Test\TestComponent.cshtml)
Expand All @@ -20,7 +20,7 @@ Source Location: (112:3,7 [73] x:\dir\subdir\Test\TestComponent.cshtml)
return Task.CompletedTask;
}
|
Generated Location: (1481:48,7 [73] )
Generated Location: (1489:48,7 [73] )
|
Task OnClick()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace Test
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Components;
public class TestComponent : Microsoft.AspNetCore.Components.ComponentBase
public partial class TestComponent : Microsoft.AspNetCore.Components.ComponentBase
{
#pragma warning disable 219
private void __RazorDirectiveTokenHelpers__() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Document -
UsingDirective - (53:3,1 [17] ) - System.Linq
UsingDirective - (73:4,1 [28] ) - System.Threading.Tasks
UsingDirective - (104:5,1 [37] ) - Microsoft.AspNetCore.Components
ClassDeclaration - - public - TestComponent - Microsoft.AspNetCore.Components.ComponentBase -
ClassDeclaration - - public partial - TestComponent - Microsoft.AspNetCore.Components.ComponentBase -
DesignTimeDirective -
CSharpCode -
IntermediateToken - - CSharp - #pragma warning disable 0414
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
Source Location: (26:0,26 [11] x:\dir\subdir\Test\TestComponent.cshtml)
|ParentValue|
Generated Location: (978:25,26 [11] )
Generated Location: (986:25,26 [11] )
|ParentValue|

Source Location: (50:1,7 [50] x:\dir\subdir\Test\TestComponent.cshtml)
|
public int ParentValue { get; set; } = 42;
|
Generated Location: (2059:48,7 [50] )
Generated Location: (2067:48,7 [50] )
|
public int ParentValue { get; set; } = 42;
|
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace Test
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Components;
public class TestComponent : Microsoft.AspNetCore.Components.ComponentBase
public partial class TestComponent : Microsoft.AspNetCore.Components.ComponentBase
{
#pragma warning disable 219
private void __RazorDirectiveTokenHelpers__() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Document -
UsingDirective - (53:3,1 [17] ) - System.Linq
UsingDirective - (73:4,1 [28] ) - System.Threading.Tasks
UsingDirective - (104:5,1 [37] ) - Microsoft.AspNetCore.Components
ClassDeclaration - - public - TestComponent - Microsoft.AspNetCore.Components.ComponentBase -
ClassDeclaration - - public partial - TestComponent - Microsoft.AspNetCore.Components.ComponentBase -
DesignTimeDirective -
CSharpCode -
IntermediateToken - - CSharp - #pragma warning disable 0414
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
Source Location: (30:0,30 [11] x:\dir\subdir\Test\TestComponent.cshtml)
|ParentValue|
Generated Location: (969:25,30 [11] )
Generated Location: (977:25,30 [11] )
|ParentValue|

Source Location: (54:1,7 [65] x:\dir\subdir\Test\TestComponent.cshtml)
|
public DateTime ParentValue { get; set; } = DateTime.Now;
|
Generated Location: (1579:43,7 [65] )
Generated Location: (1587:43,7 [65] )
|
public DateTime ParentValue { get; set; } = DateTime.Now;
|
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace Test
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Components;
public class TestComponent : Microsoft.AspNetCore.Components.ComponentBase
public partial class TestComponent : Microsoft.AspNetCore.Components.ComponentBase
{
#pragma warning disable 219
private void __RazorDirectiveTokenHelpers__() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Document -
UsingDirective - (53:3,1 [17] ) - System.Linq
UsingDirective - (73:4,1 [28] ) - System.Threading.Tasks
UsingDirective - (104:5,1 [37] ) - Microsoft.AspNetCore.Components
ClassDeclaration - - public - TestComponent - Microsoft.AspNetCore.Components.ComponentBase -
ClassDeclaration - - public partial - TestComponent - Microsoft.AspNetCore.Components.ComponentBase -
DesignTimeDirective -
CSharpCode -
IntermediateToken - - CSharp - #pragma warning disable 0414
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
Source Location: (26:0,26 [11] x:\dir\subdir\Test\TestComponent.cshtml)
|ParentValue|
Generated Location: (978:25,26 [11] )
Generated Location: (986:25,26 [11] )
|ParentValue|

Source Location: (50:1,7 [50] x:\dir\subdir\Test\TestComponent.cshtml)
|
public int ParentValue { get; set; } = 42;
|
Generated Location: (1883:47,7 [50] )
Generated Location: (1891:47,7 [50] )
|
public int ParentValue { get; set; } = 42;
|
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace Test
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Components;
public class TestComponent : Microsoft.AspNetCore.Components.ComponentBase
public partial class TestComponent : Microsoft.AspNetCore.Components.ComponentBase
{
#pragma warning disable 219
private void __RazorDirectiveTokenHelpers__() {
Expand Down
Loading