Skip to content

Conversation

@davidwengier
Copy link
Member

@davidwengier davidwengier commented Feb 15, 2023

To celebrate finally being able to build on my machine, I took a break from firefighting to write some code.

Fixes #8227
Fixes #8229

I cannot explain why this doesn't fix the third skipped test, but I wanted to timebox the work so I did.

Thanks @LunicLynx for creating the tests for these, made it much easier

@davidwengier davidwengier requested a review from a team as a code owner February 15, 2023 04:12
var lineStart = line.GetFirstNonWhitespacePosition() ?? line.Start;
var lineStartSpan = new TextSpan(lineStart, 0);
if (!ShouldFormat(context, lineStartSpan, allowImplicitStatements: true))
if (!ShouldFormatLine(context, lineStartSpan, allowImplicitStatements: true))
Copy link
Member Author

Choose a reason for hiding this comment

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

This ShouldFormat method is arguably still doing too much, but this particular usage has annoyed me before, so I done fixed it.

}

bool IsInHtmlAttributeName()
bool IsInBoundComponentAttributeName()
Copy link
Member Author

Choose a reason for hiding this comment

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

This method name was doing a poor job of describing what it did. Also expanded the comment below to be clearer.

public override void VisitMarkupTagHelperAttribute(MarkupTagHelperAttributeSyntax node)
{
Visit(node.Value);
WriteBlock(node, FormattingBlockKind.Tag, n =>
Copy link
Member Author

Choose a reason for hiding this comment

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

This updates tag helper attributes to match the logic of html tag attributes, in the method above.

I don't fully understand:

  • What this is doing
  • Why it wasn't doing it before
  • Why only one of the tests was fixed with this change
  • Why none of the existing tests broke with this change

Formatting! :)

@if (true)
{
<a_really_long_tag_name Id="comp1"
Copy link
Member Author

Choose a reason for hiding this comment

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

Added this because html tags formatted correctly, and component tags didn't, so it was convenient when debugging to see what was happening that was different. Figured I'd leave it 🤷‍♂️

@LunicLynx
Copy link
Contributor

LunicLynx commented Feb 15, 2023

Awesome. I tried myself on this, but was not getting anywhere, only more confused.

Great that you made progress on this!

@davidwengier
Copy link
Member Author

@dotnet/razor-tooling would appreciate a review if you have time :)

@davidwengier davidwengier merged commit d8c7149 into dotnet:main Feb 21, 2023
@davidwengier davidwengier deleted the FixComponentAttributeFormatting branch February 21, 2023 22:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Razor formatting wrong for components nested in ChildContent and @{ } block. Razor formatting wrong for components nested in @if block

3 participants