-
Notifications
You must be signed in to change notification settings - Fork 196
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
Conversation
return changedText; | ||
} | ||
|
||
private static bool ShouldCleanup(FormattingContext context, Position position) |
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.
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.
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 it just the implicit statement difference?
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.
For now, yes.
src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Formatting/CSharpFormatter.cs
Show resolved
Hide resolved
src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Formatting/CSharpFormatter.cs
Outdated
Show resolved
Hide resolved
src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Formatting/CSharpFormatter.cs
Outdated
Show resolved
Hide resolved
src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Formatting/CSharpFormatter.cs
Show resolved
Hide resolved
src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Formatting/CSharpFormattingPass.cs
Show resolved
Hide resolved
src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Formatting/CSharpFormattingPass.cs
Show resolved
Hide resolved
return changedText; | ||
} | ||
|
||
private static bool ShouldCleanup(FormattingContext context, Position position) |
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 it just the implicit statement difference?
src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Formatting/HtmlFormattingPass.cs
Show resolved
Hide resolved
src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Formatting/HtmlFormattingPass.cs
Outdated
Show resolved
Hide resolved
src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Formatting/CSharpFormattingPass.cs
Outdated
Show resolved
Hide resolved
CancellationToken cancellationToken) | ||
{ | ||
var workspace = _projectSnapshotManagerAccessor.Instance.Workspace; | ||
var cSharpOptions = workspace.Options |
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.
Are we enforcing csharp
vs cSharp
?
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.
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.
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.
csharp
+1
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.
+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
6de0dd6
to
40fb27d
Compare
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.
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)) |
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.
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.
Hello @ajaybhargavb! Because this pull request has the 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 (
|
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
Known issues:
In the next PR:
Note: Feel free to try out my changes in your experimental instance to look for obvious corner cases I may have missed.