Skip to content

Commit 562875e

Browse files
authored
Don't create a new FormattingContext if there weren't any cleanup changes (#12400)
* Don't create a new FormattingContext if there weren't any cleanup changes
1 parent 7abb2ad commit 562875e

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Formatting/Passes/CSharpOnTypeFormattingPass.cs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -132,10 +132,15 @@ public async Task<ImmutableArray<TextChange>> ExecuteAsync(FormattingContext con
132132

133133
// We make an optimistic attempt at fixing corner cases.
134134
var cleanupChanges = CleanupDocument(changedContext, linePositionSpanAfterFormatting);
135-
var cleanedText = formattedText.WithChanges(cleanupChanges);
136-
context.Logger?.LogSourceText("AfterCleanupDocument", cleanedText);
135+
var cleanedText = formattedText;
137136

138-
changedContext = await changedContext.WithTextAsync(cleanedText, cancellationToken).ConfigureAwait(false);
137+
if (!cleanupChanges.IsEmpty)
138+
{
139+
cleanedText = formattedText.WithChanges(cleanupChanges);
140+
context.Logger?.LogSourceText("AfterCleanupDocument", cleanedText);
141+
142+
changedContext = await changedContext.WithTextAsync(cleanedText, cancellationToken).ConfigureAwait(false);
143+
}
139144

140145
// At this point we should have applied all edits that adds/removes newlines.
141146
// Let's now ensure the indentation of each of those lines is correct.

0 commit comments

Comments
 (0)