-
Notifications
You must be signed in to change notification settings - Fork 220
Reacted to descriptor changes in product code. #1054
Reacted to descriptor changes in product code. #1054
Conversation
} | ||
|
||
var visitor = new MainSourceVisitor(document, builder, namespaces) | ||
var tagHelperPrefix = codeDocument.GetTagHelperPrefix(); |
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.
gross 😝
public string PropertyName { get; set; } | ||
|
||
public TagHelperAttributeDescriptor Descriptor { get; set; } | ||
public BoundAttributeDescriptor Descriptor { get; set; } |
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.
It would be really nice if this had a backreference to the taghelperdescriptor as well. This is pretty cumbersome when working with the IR.
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.
The IR node I mean
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.
Spoke offline. Going to add a reference to TagHelperBinding
aka TagBindingResult
|
||
namespace Microsoft.AspNetCore.Razor.Evolution.Legacy | ||
{ | ||
internal sealed class TagBindingResult |
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.
TagHelperBinding
?
/// <param name="tagHelperPrefix">The tag helper prefix being used by the document.</param> | ||
/// <param name="descriptors">The descriptors that the <see cref="TagHelperDescriptorProvider"/> will pull from.</param> | ||
public TagHelperDescriptorProvider(IEnumerable<TagHelperDescriptor> descriptors) | ||
public TagHelperDescriptorProvider(string tagHelperPrefix, IEnumerable<TagHelperDescriptor> descriptors) |
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.
We'll want to clean this up as well in the future as part of the extensibility for discovery.
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.
OK I'm avoiding commenting here after reading further. This needs a lot of simplification.
} | ||
|
||
var descriptors = Enumerable.Empty<TagHelperDescriptor>(); | ||
TagBindingResult tagHelperBinding; |
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.
See you already knew what to call it.
{ | ||
_index++; | ||
} | ||
} |
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.
It's really nice overall to see the changes to this class, this is much cleaner than before.
var descriptors = factory.CreateDescriptors(type, errors); | ||
results.AddRange(descriptors); | ||
var descriptor = factory.CreateDescriptor(type); | ||
results.Add(descriptor); |
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.
What if the factory returns null?
var symbol = compilation.GetTypeByMetadataName(tagHelper.TypeName); | ||
if (tagHelper.Documentation != null) | ||
{ | ||
goto AddDocumentedTagHelper; |
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.
No. you haven't earned this.
AddXmlDocumentation(compilation, result.Descriptors); | ||
return result; | ||
var documentedTagHelpers = GetDocumentedTagHelpers(compilation, result.Descriptors); | ||
var documentedResult = new TagHelperResolutionResult(documentedTagHelpers, result.Diagnostics); |
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.
Why change this data flow? Just because of immutability?
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.
Yup
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'd suggest just writing it in a sane, albeit inefficient way.
- Get the descriptors
- Create the objects
- Loop over each one that's missing docs and add them
- return
Alternatively you could loop over the builders in stage 3.
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.
NVM I am a sillypants
return documentedTagHelpers; | ||
} | ||
|
||
private ITagHelperBoundAttributeDescriptorBuilder ShallowCopy(string tagHelperTypeName, BoundAttributeDescriptor attribute) |
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.
Think about making this an internal method on the abstract class. Then each descriptor type can 'copy' itself to a builder.
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.
Thought about doing that and then realized this was the only part of the API that'd use it. Decided against it until we need it.
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.
Sounds good.
26f75a6
to
4306def
Compare
- Added a new `RazorDiagnosticFactory` abstraction to handle `RazorDiagnostic`s and their corresponding errors/ids etc. This new API should allow for easy addition of new `RazorDiagnostic` errors. - Updated the `DefaultTagHelperDescriptorFactory` to construct `TagHelperDescriptor`s using the new builder APIs and in the new descriptor format (1 descriptor per type). - Updated `ViewComponentTagHelperDescriptorFactory` to construct `TagHelperDescriptor`s with the builder API. - With both factory implementations code was duplicated because the ViewComponent work will be moving outside of Razor once we have the proper hooks. - Updated `TagHelper` binding bits to capture a binding result in order to query which rules appy to a given tag name. - Still need to handle deserialization of `TagHelperDescriptor` types within the Razor extension. #973
- Renamed TagBindingResult to TagHelperBinding - Added reference to TagHelperBinding in SetTagHelperPropertyIRNode - Cleanup
9ce4e8e
to
62fad09
Compare
🆙 📅 |
- Finished migrating the `Microsoft.CodeAnalysis.Razor.Test` project. Major work here was getting the various factory tests constructing `TagHelperDescriptor`s correctly in a 1 -> 1 format with types. - Migrated integration tests for confidence in our product code changes. - Deleted several tests that raised themselves as being duplicates. - Updated case sensitive comparers to understand new `TagHelperDescriptor` API. - Removed design time comparers. #973
- Cleanup Validate() in builders - Remove case sensitive comparers and some cleanup
- Fixed legacy tests - Added TagHelperDescriptorJsonConverter and added serialization tests
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.
|
||
AddTagHelperCreation(tagHelperBlock.Descriptors); | ||
AddTagHelperAttributes(tagHelperBlock.Attributes, tagHelperBlock.Descriptors); | ||
AddTagHelperCreation(tagHelperBlock.BindingResult); |
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.
This should just be .Binding
|
||
namespace Microsoft.AspNetCore.Razor.Evolution.Legacy | ||
{ | ||
internal sealed class TagHelperBinding |
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.
This should be public, maybe with an internal constructor? IR Visitors will want to be able to see this
|
||
public TagHelperBinding(IReadOnlyDictionary<TagHelperDescriptor, IEnumerable<TagMatchingRule>> applicableDescriptorMappings) | ||
{ | ||
_applicableDescriptorMappings = applicableDescriptorMappings; |
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.
how about just mappings
?
* REVIEWERS: This needs to be public or IVT for tooling to consume until we flesh | ||
* out a proper API to decouple tooling from Razors intrinsics. They use these to | ||
* determine if their HTML elements match a descriptor or not to provide IntelliSense. | ||
*/ |
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 leave this comment here
namespace Microsoft.CodeAnalysis.Razor | ||
{ | ||
// Internal for testing | ||
internal static class RequiredAttributeParser |
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.
This whole thing should be independent of the builder... The builder should call into this class, not the other way around.
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.
That'd put the logic of CSS based required attributes in the builder and not in the DefaultTagHelperDescriptorFactory
. That sounds a little backwards compared to how all other declarative information on TagHelper's is consumed.
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.
Filed an issue to track this. https://github.com/aspnet/Razor/issues/1082
@ajaybhargavb and I are getting PRs out now for the descriptor changes so they can be looked in consumable pieces over as we finish the test reaction work.
RazorDiagnosticFactory
abstraction to handleRazorDiagnostic
s and their corresponding errors/ids etc. This new API should allow for easy addition of newRazorDiagnostic
errors.DefaultTagHelperDescriptorFactory
to constructTagHelperDescriptor
s using the new builder APIs and in the new descriptor format (1 descriptor per type).ViewComponentTagHelperDescriptorFactory
to constructTagHelperDescriptor
s with the builder API.TagHelper
binding bits to capture a binding result in order to query which rules appy to a given tag name.TagHelperDescriptor
types within the Razor extension.#973