Suppress unified diff when token comparators ignore all changes - #2936
Conversation
|
Are there any objections? I plan to merge this change tomorrow. |
|
In REPLACE_MODE the document is rewritten from unifiedDiffs, so a suppressed region is never applied. With the case-insensitive comparator from the test, replacing "line one" with "LINE ONE" leaves "line one". Could you limit the suppression to the overlay modes (or still apply the text without the annotation) and add a REPLACE_MODE test? |
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.
04c75e8 to
1c68738
Compare
|
Thanks for the review. I see it differently: the token comparator defines what counts as a difference. If the caller plugs in a case-insensitive comparator, "line one" and "LINE ONE" are the same content, so there is nothing to apply in any mode - including REPLACE_MODE. Rewriting the text to a form the comparator already treats as identical would be wrong, so leaving it untouched is intended, not a lost edit. I added a short comment at the suppression to make this explicit, plus two REPLACE_MODE tests: one with the case-insensitive comparator (document stays unchanged) and one with the default comparator (the case change is a real diff and gets applied). Rebased on latest master. |
Ok, fine for me. :-)
Thanks. |
|
LGTM |
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).