Skip to content

Fixes innaccurate, noisy diffs - #235

Merged
Avni2000 merged 2 commits into
mainfrom
confetti-diff
Apr 29, 2026
Merged

Avni2000 merged 2 commits into
mainfrom
confetti-diff

Conversation

@Avni2000

@Avni2000 Avni2000 commented Apr 29, 2026 •

Copy link
Copy Markdown
Owner

Before:

Screenshot From 2026-04-29 10-36-44

After:

Screenshot From 2026-04-29 10-32-45

Motivation:

Previously, we were (a) diffing twice, (b) producing character-level, instead of word-level diffs. This uses the standard diff package for a 2-pass line, then word, level diff.

Side-benefits:

  • Refactors diff logic into packages/core instead of packages/web

- replaces character-level approach `codemirror/merge` was using which produced noisy, largely useless highlights
- 2 pass strategy: diffLines first, and then diffWordsWithSpace for inline stuff
- separation of concerns; core logic should not be in web...
@coderabbitai

coderabbitai Bot commented Apr 29, 2026 •

Copy link
Copy Markdown
Contributor
📝 Walkthrough

Walkthrough

This PR extracts diff mark computation logic from the CellContent component into a reusable utility module (diffMarks.ts) in the core package, adds the diff npm package as a dependency, and updates CellContent to import and use this centralized implementation instead of maintaining local diff logic.

Changes

Cohort / File(s) Summary
Dependency Addition
package.json
Adds diff npm package (^9.0.0) to runtime dependencies.
Core Utility Module
packages/core/src/diffMarks.ts
New module exporting computeDiffMarks() function and related types (DiffSide, DiffMode, InlineDiffRange, DiffMarks) for computing line-level and inline diff highlighting ranges.
Core Package Export
packages/core/src/index.ts
Re-exports all exports from the new diffMarks module to the public API surface.
Component Refactoring
packages/web/client/src/components/CellContent.tsx
Removes local diff computation logic (65 lines) and imports computeDiffMarks from the core package instead.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

  • PR #169: Removes local diff implementation from CellContent and delegates to an external @codemirror/merge-based module, similarly extracting diff computation logic.
  • PR #31: Modifies how CellContent sources diff computation by replacing a local or web-client implementation with a shared module.

Poem

🐰 A diff that lived scattered and spread,
Now hops to the core where it's read,
One function to rule them all bright,
Extracting logic—a modular sight! ✨

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 33.33% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title 'Fixes innaccurate, noisy diffs' is directly related to the main change: extracting diff computation logic into a dedicated utility module to improve accuracy and reduce noise in diff presentation.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.

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

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch confetti-diff

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.

@sonarqubecloud

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@packages/core/src/diffMarks.ts`:
- Around line 51-106: computeDiffMarks is too complex; extract smaller helper
functions to reduce cognitive complexity: move the line-marking logic into a
helper like markHunkLines(lineOfPos, hunkStart, hunkEnd, lineClasses), move
class selection into chooseClasses(side, diffMode, isWhitespaceOnly) that
returns {lineClass, inlineClass}, move inline range construction into
buildInlineRangesForHunk({pendingRemoved, hunkValue, hunkStart, inlineClass})
which returns inlineRanges to append, and move bOffset/pendingRemoved
orchestration into the top-level computeDiffMarks that simply iterates hunks and
calls markHunkLines, chooseClasses, and buildInlineRangesForHunk (also add a
small helper advanceOffset(bOffset, hunk) if helpful); ensure exported behavior
and symbols computeDiffMarks, diffWordsWithSpace usage, and
SIDE_CLASSES/CONFLICT_CLASSES semantics remain unchanged.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: a4fcd4b3-302e-4857-b9a9-770b3802db3b

📥 Commits

Reviewing files that changed from the base of the PR and between 2c73a37 and 9561711.

⛔ Files ignored due to path filters (1)
  • package-lock.json is excluded by !**/package-lock.json
📒 Files selected for processing (4)
  • package.json
  • packages/core/src/diffMarks.ts
  • packages/core/src/index.ts
  • packages/web/client/src/components/CellContent.tsx

Comment thread packages/core/src/diffMarks.ts Resolved
@Avni2000
Avni2000 merged commit 246c29c into main Apr 29, 2026
7 checks passed
@Avni2000
Avni2000 deleted the confetti-diff branch April 29, 2026 15:58
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