Suppress unified diff when token comparators ignore all changes - #2936
Open
tobiasmelcher wants to merge 1 commit into
Open
tobiasmelcher wants to merge 1 commit into
tobiasmelcher wants to merge 1 commit into
Conversation
If line-level diffing detects a change but the token comparators report no actual differences (e.g. a case-insensitive comparator on identical text), no parent diff is added to the list. Previously a unified diff was shown to the user without any detailed delta, which was confusing.
Contributor
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The unified diff feature uses two levels of comparison: a line-level diff
to find changed regions, and a token-level diff (via
ITokenComparator) tohighlight the exact words that changed within each region.
A custom
ITokenComparatorcan normalise text before comparing — for exampletreating
"line ONE"and"line one"as equal. In that case the line-leveldiff reports a change, but the token diff finds nothing: all results are
NOCHANGE. Before this fix, the parentUnifiedDiffwas created and shown tothe user anyway, producing a highlighted region with no inline delta. The
annotation was visually present but carried no information, which was
confusing.
The fix moves the token diff computation ahead of the
UnifiedDiffconstruction. If
hasDetailedChanges()returns false the change is skippedentirely, so only diffs with at least one real token difference are ever
presented to the user.
Helped by Claude Code (Anthropic).