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

LSP Razor formatting for Razor code block directives #1573

Merged
merged 4 commits into from
Feb 14, 2020

Conversation

ajaybhargavb
Copy link
Contributor

@ajaybhargavb ajaybhargavb commented Feb 12, 2020

https://github.com/dotnet/aspnetcore/issues/14271

I apologize for the large PR but a lot of it is plumbing, extension methods and tests. The bulk of the logic is contained within DefaultRazorFormattingService. I added a fair amount of abstraction but I decided to not abstract away too many things just yet because I expect more changes to the design when we support HTML formatting as well.

  • Support for @code/@functions block formatting
    • Except when it contains Markup or other Razor constructs
  • Added a RazorFormattingService which is invoked by the RazorFormattingEndpoint.
  • Added a custom razor/rangeFormatting command that the server can use to ask the client to format a range of the projected C# or HTML document
  • Added a CSharpFormatter and HTMLFormatter that invoke the above mentioned command
  • Added FormattingSpan and its corresponding visitor to represent Razor understanding of indentation
  • Moved the document mapping code to a separate RazorDocumentMappingService service for ease of use
  • Added necessary extension methods for convenience. Some of them were copied from Roslyn
  • Some cleanup
  • Added a C# test formatter to enable unit testing. Right now it calls Roslyn APIs directly. As far as I've seen its behavior is the same as OmniSharp formatting except it doesn't remove trailing whitespace and empty lines. I am following up with people to understand why that is the case.
  • Added/updated tests

Copy link
Contributor

@NTaylorMullen NTaylorMullen left a comment

Choose a reason for hiding this comment

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

Looking really good. I love the separation you made with a lot of the concepts and the testing strategy you landed on is a perfect middleground.

👏 🎉 🥂

@dotnet dotnet deleted a comment from NTaylorMullen Feb 13, 2020
@ajaybhargavb
Copy link
Contributor Author

🆙 📅

Copy link
Contributor

@NTaylorMullen NTaylorMullen left a comment

Choose a reason for hiding this comment

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

Looks good. Before checking in could you expand this comment to ensure future viewers/readers fully understand the problem.

Copy link
Contributor

@ryanbrandenburg ryanbrandenburg left a comment

Choose a reason for hiding this comment

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

Some questions but nothing groundbreaking.

@ajaybhargavb ajaybhargavb merged commit 62051b9 into master Feb 14, 2020
@ajaybhargavb ajaybhargavb deleted the ajbaaska/better-formatting branch February 14, 2020 00:37
JunTaoLuo pushed a commit to dotnet/aspnetcore that referenced this pull request May 17, 2020
LSP Razor formatting for Razor code block directives
- Support for @code/@functions block formatting
    - Except when it contains Markup or other Razor constructs
- Added a RazorFormattingService which is invoked by the RazorFormattingEndpoint.
- Added a custom razor/rangeFormatting command that the server can use to ask the client to format a range of the projected C# or HTML document
- Added a CSharpFormatter and HTMLFormatter that invoke the above mentioned command
- Added FormattingSpan and its corresponding visitor to represent Razor understanding of indentation
- Moved the document mapping code to a separate RazorDocumentMappingService service for ease of use
- Added necessary extension methods for convenience. Some of them were copied from Roslyn
- Some cleanup
- Added a C# test formatter to enable unit testing. Right now it calls Roslyn APIs directly. As far as I've seen its behavior is the same as OmniSharp formatting except it doesn't remove trailing whitespace and empty lines. I am following up with people to understand why that is the case.
Added/updated tests
\n\nCommit migrated from dotnet/razor@62051b9
dougbu pushed a commit to dougbu/razor-compiler that referenced this pull request Nov 17, 2021
LSP Razor formatting for Razor code block directives
- Support for @code/@functions block formatting
    - Except when it contains Markup or other Razor constructs
- Added a RazorFormattingService which is invoked by the RazorFormattingEndpoint.
- Added a custom razor/rangeFormatting command that the server can use to ask the client to format a range of the projected C# or HTML document
- Added a CSharpFormatter and HTMLFormatter that invoke the above mentioned command
- Added FormattingSpan and its corresponding visitor to represent Razor understanding of indentation
- Moved the document mapping code to a separate RazorDocumentMappingService service for ease of use
- Added necessary extension methods for convenience. Some of them were copied from Roslyn
- Some cleanup
- Added a C# test formatter to enable unit testing. Right now it calls Roslyn APIs directly. As far as I've seen its behavior is the same as OmniSharp formatting except it doesn't remove trailing whitespace and empty lines. I am following up with people to understand why that is the case.
Added/updated tests
\n\nCommit migrated from dotnet/razor@62051b9

Commit migrated from dotnet/aspnetcore@f1ccf855ebfc
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.

3 participants