Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,32 @@ public static string GetSubTextString(this SourceText text, TextSpan span)
return new string(charBuffer, 0, span.Length);
}

public static bool NonWhitespaceContentEquals(this SourceText text, SourceText other)
=> NonWhitespaceContentEquals(text, other, 0, text.Length, 0, other.Length);
public static bool NonWhitespaceContentEquals(this SourceText text, ImmutableArray<TextChange> changes)
{
if (changes.IsEmpty)
{
return true;
}

// Determine the affected spans in the original and changed source texts
var firstChangeSpan = changes[0].Span;
var textStart = firstChangeSpan.Start;
var textEnd = firstChangeSpan.End;

for (var i = 1; i < changes.Length; i++)
{
var changeSpan = changes[i].Span;

textStart = Math.Min(textStart, changeSpan.Start);
textEnd = Math.Max(textEnd, changeSpan.End);
}

var changedText = text.WithChanges(changes);
var changedStart = textStart;
var changedEnd = textEnd + (changedText.Length - text.Length);

return text.NonWhitespaceContentEquals(changedText, textStart, textEnd, changedStart, changedEnd);
}

public static bool NonWhitespaceContentEquals(
this SourceText text,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,8 @@ internal sealed class FormattingContentValidationPass(ILoggerFactory loggerFacto
public Task<bool> IsValidAsync(FormattingContext context, ImmutableArray<TextChange> changes, CancellationToken cancellationToken)
{
var text = context.SourceText;
var changedText = text.WithChanges(changes);

if (!text.NonWhitespaceContentEquals(changedText))
if (!text.NonWhitespaceContentEquals(changes))
{
// Looks like we removed some non-whitespace content as part of formatting. Oops.
// Discard this formatting result.
Expand Down