Skip to content
This repository was archived by the owner on Dec 19, 2018. It is now read-only.

Conversation

NTaylorMullen
Copy link

@NTaylorMullen NTaylorMullen commented Mar 7, 2017

@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.

  • Added a new RazorDiagnosticFactory abstraction to handle RazorDiagnostics and their corresponding errors/ids etc. This new API should allow for easy addition of new RazorDiagnostic errors.
  • Updated the DefaultTagHelperDescriptorFactory to construct TagHelperDescriptors using the new builder APIs and in the new descriptor format (1 descriptor per type).
  • Updated ViewComponentTagHelperDescriptorFactory to construct TagHelperDescriptors 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

@NTaylorMullen NTaylorMullen changed the title [Design] Reacted to descriptor changes in product code. Reacted to descriptor changes in product code. Mar 7, 2017
}

var visitor = new MainSourceVisitor(document, builder, namespaces)
var tagHelperPrefix = codeDocument.GetTagHelperPrefix();
Copy link
Member

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; }
Copy link
Member

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.

Copy link
Member

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

Copy link
Contributor

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
Copy link
Member

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)
Copy link
Member

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.

Copy link
Member

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;
Copy link
Member

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++;
}
}
Copy link
Member

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);
Copy link
Member

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;
Copy link
Member

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);
Copy link
Member

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?

Copy link
Author

Choose a reason for hiding this comment

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

Yup

Copy link
Member

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.

  1. Get the descriptors
  2. Create the objects
  3. Loop over each one that's missing docs and add them
  4. return

Alternatively you could loop over the builders in stage 3.

Copy link
Member

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)
Copy link
Member

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.

Copy link
Author

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.

Copy link
Member

Choose a reason for hiding this comment

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

Sounds good.

N. Taylor Mullen and others added 2 commits March 13, 2017 16:57
- 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
@ajaybhargavb ajaybhargavb force-pushed the nimullen/thdapi.973.product branch from 9ce4e8e to 62fad09 Compare March 14, 2017 00:58
@ajaybhargavb
Copy link
Contributor

🆙 📅

N. Taylor Mullen and others added 7 commits March 13, 2017 19:36
- 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
Copy link
Member

@rynowak rynowak left a comment

Choose a reason for hiding this comment

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

:shipit:


AddTagHelperCreation(tagHelperBlock.Descriptors);
AddTagHelperAttributes(tagHelperBlock.Attributes, tagHelperBlock.Descriptors);
AddTagHelperCreation(tagHelperBlock.BindingResult);
Copy link
Member

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
Copy link
Member

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;
Copy link
Member

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.
*/
Copy link
Member

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
Copy link
Member

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.

Copy link
Author

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.

Copy link
Contributor

Choose a reason for hiding this comment

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

@ajaybhargavb ajaybhargavb merged commit f453186 into nimullen/thdapi.973.descriptors Mar 16, 2017
@ajaybhargavb ajaybhargavb deleted the nimullen/thdapi.973.product branch March 17, 2017 17:51
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants