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

Add line mappings to project TagHelper attribute values. #244

Merged
merged 1 commit into from
Dec 22, 2014

Conversation

NTaylorMullen
Copy link

  • 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.
    Tag Helpers: Add design time projections for attributes #207

/cc @dougbu

{
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.
Copy link
Contributor

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

Copy link
Author

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

Copy link
Contributor

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.

@dougbu
Copy link
Contributor

dougbu commented Dec 2, 2014

@@ -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;
Copy link
Contributor

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

Copy link
Author

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.

@NTaylorMullen
Copy link
Author

Updated.

{
name = symbol.Content;
// When symbols are accepted into SpanBuilders their locations get altered to be offset by the
Copy link
Contributor

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.

Copy link
Contributor

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.

writer.Write(value);
if (_context.Host.DesignTimeMode)
{
using (new CSharpLineMappingWriter(_writer, documentLocation, value.Length))
Copy link
Contributor

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

Copy link
Author

Choose a reason for hiding this comment

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

👍

@dougbu
Copy link
Contributor

dougbu commented Dec 19, 2014

:shipit: after at least adding code comment about writer versus _writer or otherwise addressing that question

// 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;
Copy link
Contributor

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.

@pranavkm
Copy link
Contributor

:shipit: once comments are addressed.

- 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
@NTaylorMullen NTaylorMullen merged commit a86b0dc into dev Dec 22, 2014
@NTaylorMullen NTaylorMullen deleted the thprojections.207 branch December 22, 2014 22: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.

3 participants