-
Notifications
You must be signed in to change notification settings - Fork 222
Add line mappings to project TagHelper attribute values. #244
Conversation
{ | ||
RenderAttributeValue( | ||
attributeDescriptor, | ||
valueRenderer: (writer) => | ||
{ | ||
writer.Write(value); | ||
// We only want to do the work of generating a line mapping if we're in design time mode. |
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.
isn't design-time what the CSharpLineMappingWriter(CSharpCodeWriter, SourceLocation, string)
constructor overload is for? otherwise it doesn't look like the debugger will have correct line number pragmas
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.
Purposefully not creating the LinePragmas here. Attributes cannot be debugged normally in Razor and after some talks with Damian we've decided to work on supporting that when we address debugability for ordinary Razor attribute code.
The issue in making TagHelpers attributes debuggable ends up being the same problem as normal HTML attributes: The line that starts the generated code is variable length and therefore doesn't result in a good debugging experience (badly placed yellow highlight).
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.
please remove or reword the comment. "want" isn't relevant. at most the comment should say something about generating line pragmas not being worthwhile because debugging C# in attributes has other issues.
⌚ |
@@ -159,6 +159,8 @@ public override void Reset() | |||
Kind = span.Kind | |||
}; | |||
var htmlSymbols = span.Symbols.OfType<HtmlSymbol>().ToArray(); | |||
var capturedAttributeValueStart = false; | |||
var attributeValueStartLocation = span.Start; |
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.
where exactly will this point when capturedAttributeValueStart == false
and when that's true
?
I suspect it'll point to the start of the attribute name in the false
case and the @
in the true
case. I hope that's not correct...
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.
You were correct, addressed this.
3bafd0d
to
7f2ec08
Compare
Updated. |
7f2ec08
to
871e82c
Compare
{ | ||
name = symbol.Content; | ||
// When symbols are accepted into SpanBuilders their locations get altered to be offset by the |
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.
super nit, split the comment into two lines (or more if you're creative).
When symbols are accepted into SpanBuilders their locations get altered to be offset by the parent. We account for this by marking our start location prior to adding the symbol so we know the location of the attribute value start within the document.
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.
👍 to @pranavkm. I'd go a bit further and add a comma after SpanBuilders
and split the second sentence after symbol
. Perhaps "Thus" instead of "So" but that's a nano-nit.
871e82c
to
6b94a47
Compare
writer.Write(value); | ||
if (_context.Host.DesignTimeMode) | ||
{ | ||
using (new CSharpLineMappingWriter(_writer, documentLocation, value.Length)) |
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.
should this use the lambda parameter writer
and not the _writer
field? if correct as-is, add a code comment
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.
👍
|
// Set the symbol offset to 0 so we don't attempt to skip an end quote that doesn't exist. | ||
symbolOffset = 0; | ||
} | ||
|
||
attributeValueStartLocation = symbolStartLocation + span.Start + SourceLocation.One; |
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.
Is this the only location where SourceLocation.One
is used? Doesn't seem like you'd need to define a public field for that purpose.
|
- We now create LineMappings for instances where a TagHelper's attribute value is not of a string type. - This will enable the Razor editor to create projections from .cshtml => .cs for TagHelper attributes. - Modified the TagHelperCodeGenerator and TagHelperBlockBuiler to accurately track the attribute values start locations so it could flow into code generation. - Modified existing tests to account for the new line mappings. #207
6b94a47
to
a86b0dc
Compare
Tag Helpers: Add design time projections for attributes #207
/cc @dougbu