Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Experimental support HTML formatting in Razor LSP #2445

Merged
3 commits merged into from
Sep 1, 2020
Merged

Conversation

ajaybhargavb
Copy link
Contributor

@ajaybhargavb ajaybhargavb commented Aug 28, 2020

Part of https://github.com/dotnet/aspnetcore/issues/23530, https://github.com/dotnet/aspnetcore/issues/14271

Summary of the changes

This introduces v1 of HTML and C# mixed formatting support

  • Added support for C# to be formatted on the server
  • Added HtmlFormattingPass
  • Added CSharpFormattingPass
  • Removed legacy C# formatting code
  • Cleanup

Known issues:

  • Mixed blocks don't format correctly in some cases
  • Implicit statements don't format correctly (@if (...){...})
  • C# specific settings on the client will not be respected
  • Other rough edges

In the next PR:

  • Structure validator based on syntax tree structure
  • Tests

Note: Feel free to try out my changes in your experimental instance to look for obvious corner cases I may have missed.

return changedText;
}

private static bool ShouldCleanup(FormattingContext context, Position position)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This method is looks pretty similar to ShouldFormat method in the CSharpFormattingPass but it is slightly different. Leaving it separate for now but will merge them in the future if possible.

Copy link
Contributor

Choose a reason for hiding this comment

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

Is it just the implicit statement difference?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

For now, yes.

return changedText;
}

private static bool ShouldCleanup(FormattingContext context, Position position)
Copy link
Contributor

Choose a reason for hiding this comment

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

Is it just the implicit statement difference?

CancellationToken cancellationToken)
{
var workspace = _projectSnapshotManagerAccessor.Instance.Workspace;
var cSharpOptions = workspace.Options
Copy link
Contributor

Choose a reason for hiding this comment

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

Are we enforcing csharp vs cSharp?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good question. This may have been a copy-paste from somewhere. I like csharp because cSharp kind of takes longer to type 😆. But I am willing to stick to whatever is most used.

Copy link
Contributor

Choose a reason for hiding this comment

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

csharp +1

Copy link
Contributor

Choose a reason for hiding this comment

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

+1 on csharp. Looks cleaner in my opinion.

Known issues:
- Mixed blocks don't format correctly in some cases
- Implicit statements don't format correctly (@if (...){...})
- Other rough edges
Copy link
Contributor Author

@ajaybhargavb ajaybhargavb left a comment

Choose a reason for hiding this comment

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

Updated with latest rebase, bug fixes, existing test fixes and diagnostic validator.

Will send a separate PR for HTML tests.

@@ -60,9 +60,12 @@ public override void VisitCSharpCodeBlock(CSharpCodeBlockSyntax node)
node.Parent is CSharpImplicitExpressionBodySyntax ||
node.Parent is RazorDirectiveBodySyntax ||
(_currentBlockKind == FormattingBlockKind.Directive &&
node.Children.Count == 1 &&
node.Children[0] is CSharpStatementLiteralSyntax))
node.Parent?.Parent is RazorDirectiveBodySyntax))
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 super proud of this if block here. I didn't want to change this too much because I couldn't recall why some of these existed (I added this 6 months ago without comments. My bad). I've left a comment but I want to clean this up soon.

@ajaybhargavb ajaybhargavb added the auto-merge Squash merge once all PR checks are complete and reviewers have approved label Sep 1, 2020
@ghost
Copy link

ghost commented Sep 1, 2020

Hello @ajaybhargavb!

Because this pull request has the auto-merge label, I will be glad to assist with helping to merge this pull request once all check-in policies pass.

p.s. you can customize the way I help with merging this pull request, such as holding this pull request until a specific person approves. Simply @mention me (@msftbot) and give me an instruction to get started! Learn more here.

@ajaybhargavb ajaybhargavb removed the auto-merge Squash merge once all PR checks are complete and reviewers have approved label Sep 1, 2020
@ajaybhargavb ajaybhargavb added the auto-merge Squash merge once all PR checks are complete and reviewers have approved label Sep 1, 2020
@ghost ghost merged commit 5bfdc63 into master Sep 1, 2020
@ghost ghost deleted the ajbaaska/html-formatting branch September 1, 2020 02:51
@NTaylorMullen NTaylorMullen mentioned this pull request Oct 1, 2021
11 tasks
@NTaylorMullen NTaylorMullen mentioned this pull request Oct 9, 2021
12 tasks
This pull request was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
auto-merge Squash merge once all PR checks are complete and reviewers have approved
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants