-
Notifications
You must be signed in to change notification settings - Fork 204
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
Conversation
- No longer mark declaration files as single file generators. Prior to this we relied on SingleFileGenerators to dynamically update the declaration files when .razor files changed. However, to make partial classes work we can no longer depend on declaration files being available because their existence causes us to have to mangle class names for opened documents; otherwise you get two files with same name and result in ambiguous definition errors. - Stopped including declaration files as part of the users compilation. This was intended to make the design time experience operate more similar to how Blazor apps function at runtime (directly access each component instead of their declarations). We now rely on the background code generation effort built from the find all references work to supply users with strongly typed component names. - Stop mangling class names for Visual Studio. Razor.VSCode has its own set of configurations which i'm not addressing as part of this changeset. - Start generating components with the partial modifier to their class name to enable partial class support. - Updated existing tests to expect partial modifier. dotnet/aspnetcore#5487
What's the user experience of this like re: switching context between files. Today when you, save, give focus to, or remove focus from a component file, it results in a chain of events that cause us to update component descriptors. This is critical for productivity - that you can add a |
It's exactly the same as today with 1-2 known bugs that I plan to fix later:
|
I'm worried about all of these things. |
I want and plan to fix them as well once i'm back from vaca. |
What are the fixes with these things? I'm nervous about steaming ahead without knowing what the roadmap is. |
For the first case Roslyn has already evaluated the document so we can look to see if the file is a component, if so re-trigger TagHelper completion. For the second case we re-discover TagHelpers after a component has been parsed. I haven't fully thought through each of the solutions above but there's a lot of ways we can fix either one of the probs |
We tested this kind of stuff out in realtime, and it works pretty well 👍 |
@@ -81,6 +81,7 @@ protected override CodeTarget CreateTarget(RazorCodeDocument codeDocument, Razor | |||
@class.ClassName = computedClass; | |||
@class.Modifiers.Clear(); | |||
@class.Modifiers.Add("public"); | |||
@class.Modifiers.Add("partial"); |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
var componentDocumentClassifier = b.Features.OfType<ComponentDocumentClassifierPass>().FirstOrDefault(); | ||
if (componentDocumentClassifier != null) | ||
{ | ||
componentDocumentClassifier.MangleClassNames = true; |
There was a problem hiding this comment.
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
?
There was a problem hiding this comment.
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.
Merging for preview2. Will address feedback in a new PR for preview3. |
- No longer mark declaration files as single file generators. Prior to this we relied on SingleFileGenerators to dynamically update the declaration files when .razor files changed. However, to make partial classes work we can no longer depend on declaration files being available because their existence causes us to have to mangle class names for opened documents; otherwise you get two files with same name and result in ambiguous definition errors. - Stopped including declaration files as part of the users compilation. This was intended to make the design time experience operate more similar to how Blazor apps function at runtime (directly access each component instead of their declarations). We now rely on the background code generation effort built from the find all references work to supply users with strongly typed component names. - Stop mangling class names for Visual Studio. Razor.VSCode has its own set of configurations which i'm not addressing as part of this changeset. - Start generating components with the partial modifier to their class name to enable partial class support. - Updated existing tests to expect partial modifier. dotnet/aspnetcore#5487
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> |
There was a problem hiding this comment.
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.
- No longer mark declaration files as single file generators. Prior to this we relied on SingleFileGenerators to dynamically update the declaration files when .razor files changed. However, to make partial classes work we can no longer depend on declaration files being available because their existence causes us to have to mangle class names for opened documents; otherwise you get two files with same name and result in ambiguous definition errors. - Stopped including declaration files as part of the users compilation. This was intended to make the design time experience operate more similar to how Blazor apps function at runtime (directly access each component instead of their declarations). We now rely on the background code generation effort built from the find all references work to supply users with strongly typed component names. - Stop mangling class names for Visual Studio. Razor.VSCode has its own set of configurations which i'm not addressing as part of this changeset. - Start generating components with the partial modifier to their class name to enable partial class support. - Updated existing tests to expect partial modifier. aspnet/AspNetCoredotnet/aspnetcore-tooling#5487\n\nCommit migrated from dotnet/razor@ecb3b1b
- No longer mark declaration files as single file generators. Prior to this we relied on SingleFileGenerators to dynamically update the declaration files when .razor files changed. However, to make partial classes work we can no longer depend on declaration files being available because their existence causes us to have to mangle class names for opened documents; otherwise you get two files with same name and result in ambiguous definition errors. - Stopped including declaration files as part of the users compilation. This was intended to make the design time experience operate more similar to how Blazor apps function at runtime (directly access each component instead of their declarations). We now rely on the background code generation effort built from the find all references work to supply users with strongly typed component names. - Stop mangling class names for Visual Studio. Razor.VSCode has its own set of configurations which i'm not addressing as part of this changeset. - Start generating components with the partial modifier to their class name to enable partial class support. - Updated existing tests to expect partial modifier. aspnet/AspNetCoredotnet/aspnetcore-tooling#5487\n\nCommit migrated from dotnet/razor@73858cd
dotnet/aspnetcore#5487