-
Notifications
You must be signed in to change notification settings - Fork 223
Refactored CodeGeneratorContext to CodeBuilderContext. #114
Refactored CodeGeneratorContext to CodeBuilderContext. #114
Conversation
NTaylorMullen
commented
Sep 4, 2014
- Needed to separate the context's of "generation" and "building" to enable the communication of the TagHelperProvider.
f75b598
to
ebd69e8
Compare
68c434a
to
8476d27
Compare
ebd69e8
to
84e9e15
Compare
8476d27
to
96c4089
Compare
@@ -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; } |
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 really seems service-like. Why does it need to be threaded through all of these layers? Why is it part of the results
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.
Razor doesn't use any sort of DI sadly, therefore this is how end-information is passed.
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'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)?
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.
suggest carting this reference around in a context object or passing it directly. Either way, limit the Results
classes to actual results
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.
There's already a context that the parser uses and initializes in its parse method (dependent on its own member values).
Options:
- Add an
out
parameter to the parse method that "provides" theTagHelperProvider
. - Add callback for
TagHelperProvider
(pretty much just like anout
param but not anout
param lol). - Pass in a
TagHelperProvider
builder of some sort into theRazorParser
's ctor and use it to create the TagHelperProvider when parse is called. We can then pull from the builder. - Expose the
TagHelperProvider
on theRazorParser
itself. - Leave it on
ParserResults
. - 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.
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.
observations:
- since nothing in this PR dereferences the
TagHelperProvider
instance, its addition seems easily separated from the refactoring done in this review - that'll make this review much less controversial
- 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.
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.
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 TagHelper
s. For now I can remove this however. The CodeBuilderContext
's TagHelperProvider
will be empty for the interim
84e9e15
to
5f8ef5e
Compare
96c4089
to
89a5146
Compare
Addressed a "few" code review comments, not the "bigger" design questions still mullying around. |
Modify |
@@ -0,0 +1,20 @@ | |||
using System; |
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.
- copyright header
⌚ |
5f8ef5e
to
8145a8f
Compare
89a5146
to
58f1d1f
Compare
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> |
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.
"copy" -> "to copy"
string.Empty, | ||
shouldGenerateLinePragmas: false); | ||
var codeBuilderContext = new CodeBuilderContext( | ||
generatorContext, new TagHelperProvider(Enumerable.Empty<TagHelperDescriptor>())); |
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.
need an internal
test-only constructor for CodeBuilderContext
that avoids need to create a base CodeGeneratorContext
just to instantiate the CodeBuilderContext
⌚ |
8145a8f
to
fb1befb
Compare
58f1d1f
to
bbca396
Compare
Addressed code review comments except for outstanding issue. |
fb1befb
to
e6e30f6
Compare
bbca396
to
3a0c399
Compare
e6e30f6
to
52411e9
Compare
3a0c399
to
458982d
Compare
Addressed all CR comments. |
@@ -9,6 +9,7 @@ | |||
using System.Linq; |
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.
Undo changes to this file
52411e9
to
a49a010
Compare
- 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.
58a885b
to
9711c9e
Compare
/// 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"). |
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.e." -> "e.g."
|