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

Refactored CodeGeneratorContext to CodeBuilderContext. #114

Conversation

NTaylorMullen
Copy link
Contributor

  • Needed to separate the context's of "generation" and "building" to enable the communication of the TagHelperProvider.

@NTaylorMullen NTaylorMullen force-pushed the TagHelpers_ParseTreeRewriterTests branch from f75b598 to ebd69e8 Compare September 5, 2014 02:56
@NTaylorMullen NTaylorMullen force-pushed the CodeBuilderContext_Refactor branch 2 times, most recently from 68c434a to 8476d27 Compare September 5, 2014 03:16
@NTaylorMullen NTaylorMullen force-pushed the TagHelpers_ParseTreeRewriterTests branch from ebd69e8 to 84e9e15 Compare September 5, 2014 07:15
@NTaylorMullen NTaylorMullen force-pushed the CodeBuilderContext_Refactor branch from 8476d27 to 96c4089 Compare September 5, 2014 07:15
@@ -34,6 +39,11 @@ protected ParserResults(bool success, Block document, IList<RazorError> errors)
public Block Document { get; private set; }

/// <summary>
/// The tag helper management object used to maintain found tag helpers during parsing.
/// </summary>
public TagHelperProvider TagHelperProvider { get; private set; }
Copy link
Member

Choose a reason for hiding this comment

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

This really seems service-like. Why does it need to be threaded through all of these layers? Why is it part of the results

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Razor doesn't use any sort of DI sadly, therefore this is how end-information is passed.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm trying to think of an alternate use of this object "outside" of generating C# code and depending on how tooling implements their portion of TagHelpers they "MAY" need access to the TagHelperProvider from the parser results, that being said though I see your point. We need a way to get the TagHelperProvider "out" of the parser and the portion of the Parser that will create the TagHelperProvider must be here: https://github.com/aspnet/Razor/blob/CodeBuilderContext_Refactor/src/Microsoft.AspNet.Razor/Parser/RazorParser.cs#L146 OR the last Optimizer.

We pass other information out of the parser like the Document that's needed only code gen and tooling and is really just flowed throughout the application (much like the tag helper provider).

Do you see a better approach to getting this data out of the parser and making it still available to tooling/the code builder (definitely open to suggestions)?

Copy link
Member

Choose a reason for hiding this comment

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

suggest carting this reference around in a context object or passing it directly. Either way, limit the Results classes to actual results

Copy link
Contributor Author

Choose a reason for hiding this comment

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

There's already a context that the parser uses and initializes in its parse method (dependent on its own member values).
Options:

  1. Add an out parameter to the parse method that "provides" the TagHelperProvider.
  2. Add callback for TagHelperProvider (pretty much just like an out param but not an out param lol).
  3. Pass in a TagHelperProvider builder of some sort into the RazorParser's ctor and use it to create the TagHelperProvider when parse is called. We can then pull from the builder.
  4. Expose the TagHelperProvider on the RazorParser itself.
  5. Leave it on ParserResults.
  6. As a part of Tag Helpers: Add @removetaghelper directive and link to registration system #112 and Tag Helpers: Add @addtaghelper directive and link to registration system #111 a tag helper locator can be passed into the ctor which can then be utilized to fetch the TagHelperProvider off of. As a temporary fix for this PR until those issues are completed I can provide a dummy implementation of it.

Copy link
Member

Choose a reason for hiding this comment

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

observations:

  1. since nothing in this PR dereferences the TagHelperProvider instance, its addition seems easily separated from the refactoring done in this review
  2. that'll make this review much less controversial
  3. when we start passing around a TagHelperProvider, the first questions will be "who needs this?" and "where will it come from?" with that info, we can work through how best to make the instance available.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not sure I follow your numbering.

The goal is to communicate the RazorParser generated TagHelperProvider to the CodeBuilderContext that's used by the CSharpCodeBuilder to render TagHelpers. For now I can remove this however. The CodeBuilderContext's TagHelperProvider will be empty for the interim

@NTaylorMullen NTaylorMullen force-pushed the TagHelpers_ParseTreeRewriterTests branch from 84e9e15 to 5f8ef5e Compare September 6, 2014 03:17
@NTaylorMullen NTaylorMullen force-pushed the CodeBuilderContext_Refactor branch from 96c4089 to 89a5146 Compare September 6, 2014 03:18
@NTaylorMullen
Copy link
Contributor Author

Addressed a "few" code review comments, not the "bigger" design questions still mullying around.

@NTaylorMullen
Copy link
Contributor Author

Modify TagHelperAttributeCodeGeneratorTest to use CodeBuilderContext.

@@ -0,0 +1,20 @@
using System;
Copy link
Member

Choose a reason for hiding this comment

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

  • copyright header

@dougbu
Copy link
Member

dougbu commented Sep 6, 2014

@NTaylorMullen
Copy link
Contributor Author

Addressed code review comments except for: #114 (comment)

/// <summary>
/// Instantiates a new instance of the <see cref="CodeBuilderContext"/> object.
/// </summary>
/// <param name="generatorContext">A <see cref="CodeGeneratorContext"/> copy information from.</param>
Copy link
Member

Choose a reason for hiding this comment

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

"copy" -> "to copy"

string.Empty,
shouldGenerateLinePragmas: false);
var codeBuilderContext = new CodeBuilderContext(
generatorContext, new TagHelperProvider(Enumerable.Empty<TagHelperDescriptor>()));
Copy link
Member

Choose a reason for hiding this comment

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

need an internal test-only constructor for CodeBuilderContext that avoids need to create a base CodeGeneratorContext just to instantiate the CodeBuilderContext

@dougbu
Copy link
Member

dougbu commented Sep 7, 2014

@NTaylorMullen NTaylorMullen force-pushed the TagHelpers_ParseTreeRewriterTests branch from 8145a8f to fb1befb Compare September 8, 2014 02:51
@NTaylorMullen NTaylorMullen force-pushed the CodeBuilderContext_Refactor branch from 58f1d1f to bbca396 Compare September 8, 2014 03:09
@NTaylorMullen
Copy link
Contributor Author

Addressed code review comments except for outstanding issue.

@NTaylorMullen NTaylorMullen force-pushed the TagHelpers_ParseTreeRewriterTests branch from fb1befb to e6e30f6 Compare September 9, 2014 00:47
@NTaylorMullen NTaylorMullen force-pushed the CodeBuilderContext_Refactor branch from bbca396 to 3a0c399 Compare September 9, 2014 00:50
@NTaylorMullen NTaylorMullen force-pushed the TagHelpers_ParseTreeRewriterTests branch from e6e30f6 to 52411e9 Compare September 9, 2014 21:19
@NTaylorMullen NTaylorMullen force-pushed the CodeBuilderContext_Refactor branch from 3a0c399 to 458982d Compare September 9, 2014 21:29
@NTaylorMullen
Copy link
Contributor Author

Addressed all CR comments.

@@ -9,6 +9,7 @@
using System.Linq;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Undo changes to this file

@NTaylorMullen NTaylorMullen force-pushed the TagHelpers_ParseTreeRewriterTests branch from 52411e9 to a49a010 Compare September 10, 2014 23:38
- Needed to separate the context's of "generation" and "building" to enable the communication of the TagHelperProvider.
- Removed tag helper provider from parser results and codebuildercontext.
@NTaylorMullen NTaylorMullen force-pushed the CodeBuilderContext_Refactor branch from 58a885b to 9711c9e Compare September 10, 2014 23:47
/// If <see cref="TargetWriterName"/> is <c>null</c> values will be written using a default write method
/// i.e. WriteLiteral("Hello World").
/// If <see cref="TargetWriterName"/> is not <c>null</c> values will be written to the given
/// <see cref="TargetWriterName"/>, i.e. WriteLiteralTo(myWriter, "Hello World").
Copy link
Member

Choose a reason for hiding this comment

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

"i.e." -> "e.g."

@dougbu
Copy link
Member

dougbu commented Sep 11, 2014

:shipit: w/ the one small comment fix

@NTaylorMullen NTaylorMullen deleted the CodeBuilderContext_Refactor branch September 11, 2014 21:33
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