Skip to content

Rework showDiff to use smart diffing; --show-unchanged; system prompt whitespace fix#424

Merged
bl-ue merged 1 commit intomainfrom
new-showDiff
Jan 28, 2026
Merged

Rework showDiff to use smart diffing; --show-unchanged; system prompt whitespace fix#424
bl-ue merged 1 commit intomainfrom
new-showDiff

Conversation

@bl-ue
Copy link
Member

@bl-ue bl-ue commented Jan 28, 2026

  • showDiff now diffs the old and new input substrings to provide accurate diffing for system prompts, many of which often don't change
  • You can now pass --show-unchanged to show all patches, even ones where the old and new substring are the same
  • fixLspSupport.ts's showDiff usage was incorrect.
  • Leading and trailing whitespace for system prompts is sourced from original system prompts data instead of the markdown files, making system prompt diffs fewer and cleaner

Summary by CodeRabbit

  • New Features

    • Added --show-unchanged CLI option to display unchanged diffs when used with --verbose
    • Enhanced diff visualization with color-coded output (red for removals, green for additions) and contextual previews
  • Improvements

    • Improved whitespace preservation in system prompt synchronization

✏️ Tip: You can customize this high-level summary in your review settings.

… whitespace fix

+ --show-unchanged
+ a fix for lspSupport replacement diffing
+ preserve original leading and trailing whitespace when applying system prompts
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jan 28, 2026

📝 Walkthrough

Walkthrough

This pull request introduces diff visualization capabilities by adding a diff package dependency, creates new showDiff and globalReplace utilities for contextualized patch diffing with optional unchanged content display, refactors patch files to use these utilities, adds a --show-unchanged CLI flag, enhances whitespace preservation in system prompt synchronization, and removes verbose diagnostic logging from patch operations.

Changes

Cohort / File(s) Summary
Package & CLI Setup
package.json, src/index.tsx
Added diff dependency (^8.0.3); introduced --show-unchanged CLI option that invokes enableShowUnchanged() before config migration
Core Diffing Infrastructure
src/patches/patchDiffing.ts
New module with showDiff() (generates context-rich colored diffs with optional unchanged display and Unicode normalization) and globalReplace() (applies replacements in reverse order while displaying per-replacement diffs)
Patch Infrastructure Refactoring
src/patches/index.ts, src/patches/fixLspSupport.ts
Consolidated diffing logic: fixLspSupport.ts now uses globalReplace() instead of direct string replaces; index.ts re-exports showDiff and globalReplace from patchDiffing, removed local showDiff implementation and verbose logging imports
Logging Cleanup
src/patches/systemPrompts.ts
Removed 26 lines of verbose diagnostic logging that displayed character count differences, field details, and match previews
Whitespace Preservation
src/systemPromptSync.ts
Added extractOriginalWhitespace() and applyOriginalWhitespace() functions; enhanced applyIdentifierMapping() to preserve leading/trailing whitespace from original pieces when interpolating content
Utility State Management
src/utils.ts
Added isShowUnchanged getter and enableShowUnchanged() setter to manage the show-unchanged feature flag
Test Updates
src/tests/systemPromptSync.test.ts
Updated test content and expectations to include leading newlines in prompt pieces and interpolated content

Sequence Diagram

sequenceDiagram
    participant CLI as CLI Interface
    participant Utils as Feature Flags<br/>(utils.ts)
    participant Patch as Patch Operation
    participant GlobalReplace as globalReplace()
    participant ShowDiff as showDiff()
    participant Console as Console Output

    CLI->>Utils: --show-unchanged flag received
    Utils->>Utils: enableShowUnchanged()<br/>(set isShowUnchangedOn = true)
    Patch->>GlobalReplace: Call globalReplace(content, pattern, replacement)
    GlobalReplace->>GlobalReplace: Collect all matches<br/>(preserve indices)
    GlobalReplace->>GlobalReplace: Apply replacements<br/>in reverse order
    GlobalReplace->>ShowDiff: For each replacement:<br/>showDiff(old, new, ...)
    ShowDiff->>ShowDiff: Check isShowUnchanged()<br/>and isVerbose()
    alt Verbose Mode Enabled
        ShowDiff->>ShowDiff: Compute word-level diff<br/>with Unicode normalization
        ShowDiff->>ShowDiff: Build context window<br/>around change
        ShowDiff->>Console: Output colored diff<br/>(red for removals,<br/>green for additions)
    end
    GlobalReplace-->>Patch: Return modified content
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

The review requires careful examination of new patchDiffing.ts logic (281 lines) including Unicode normalization, diff computation, and context windowing. Multiple interdependent changes span CLI, patch infrastructure, whitespace handling, and utilities. While many changes follow consistent patterns, the density of algorithmic logic in showDiff() and globalReplace(), plus coordination across multiple files, warrants substantial attention.

Possibly related PRs

Poem

🐰 A diff so fine, with colors bright,
Old in red, new in green light,
--show-unchanged tells the tale,
Of patches patched without fail,
Whitespace preserved, context clear—
Patching magic, hopping near! 🎨

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title comprehensively captures the three main changes: showDiff rework for smart diffing, the new --show-unchanged flag, and the system prompt whitespace fix.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@bl-ue bl-ue merged commit 40acf50 into main Jan 28, 2026
2 checks passed
@bl-ue bl-ue deleted the new-showDiff branch January 28, 2026 02:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant