Skip to content

Fold unchanged regions in the unified diff - #2791

Draft
vogella wants to merge 1 commit into
eclipse-platform:masterfrom
vogella:unified-diff-fold-unchanged
Draft

Fold unchanged regions in the unified diff#2791
vogella wants to merge 1 commit into
eclipse-platform:masterfrom
vogella:unified-diff-fold-unchanged

Conversation

@vogella

@vogella vogella commented Jul 2, 2026

Copy link
Copy Markdown
Contributor

This adds folding of unchanged regions to the experimental unified diff overlay, similar to the collapsed unchanged sections in GitHub's diff view.
A new UnifiedDiff.Builder#foldUnchanged(contextLines) option collapses the unchanged gaps between the displayed changes, keeping a few context lines visible around each change; it is enabled with three context lines where the unified diff is opened.
Each collapsed region shows a clickable "Expand n unchanged lines" code mining that expands it in place; re-collapsing via the folding ruler brings the expander back.
The implementation reuses the editor's projection (folding) model and the folds are tagged with a marker annotation so they can be removed on overlay teardown (Hide All Diffs, switching to the 2-way editor, dismissing the last diff) without touching the editor's own structural folds.
This makes reviewing large files with few changes considerably more compact.

Still a draft for one reason: reusing the projection model means this only takes effect in editors that install projection support, such as the Java editor or the Generic Editor. AbstractDecoratedTextEditor and TextEditor do not, so for a plain text file opened with the default text editor the option is silently a no-op. That needs a decision before this lands: accept it as a limitation, or fall back to something that does not depend on projection.

Part of eclipse-platform/eclipse.platform.ui#3771

@vogella

vogella commented Jul 2, 2026

Copy link
Copy Markdown
Contributor Author

This is a draft so that @tobiasmelcher can join in if he wants.

Current state: Folding works but I have no way to unfold.

image

@vogella
vogella requested a review from tobiasmelcher July 2, 2026 07:56
@vogella
vogella force-pushed the unified-diff-fold-unchanged branch from 9ab3ed5 to b50fcaf Compare July 2, 2026 08:03
@github-actions

github-actions Bot commented Jul 2, 2026

Copy link
Copy Markdown
Contributor

Test Results

    54 files  ±0      54 suites  ±0   58m 35s ⏱️ - 1m 25s
 4 705 tests ±0   4 683 ✅ ±0   22 💤 ±0  0 ❌ ±0 
12 006 runs  ±0  11 853 ✅ ±0  153 💤 ±0  0 ❌ ±0 

Results for commit 909ab3f. ± Comparison against base commit 1ab1f7e.

♻️ This comment has been updated with latest results.

@vogella
vogella force-pushed the unified-diff-fold-unchanged branch 3 times, most recently from a8e0a30 to 0c90f6e Compare July 31, 2026 09:08
Add a foldUnchanged(contextLines) option to UnifiedDiff that collapses the
unchanged gaps between changes, keeping a few context lines around each
change, similar to the unified view on GitHub. It reuses the editor's
projection (folding) model, so it is a no-op when folding is disabled, and
its folds are tagged so they can be removed without touching the editor's
own folds. Each collapsed region shows a clickable "Expand n unchanged
lines" code mining that expands it in place. Enabled with three context
lines on both unified diff paths.
@vogella
vogella force-pushed the unified-diff-fold-unchanged branch from 0c90f6e to 909ab3f Compare August 4, 2026 18:43
@vogella
vogella requested a lite review from Copilot August 10, 2026 08:30

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

This pull request adds folding of unchanged regions to the experimental unified diff overlay in the Eclipse Compare UI, making large files with sparse changes more compact by collapsing unchanged gaps while preserving configurable context around each change.

Changes:

  • Introduces a new UnifiedDiff.Builder#foldUnchanged(int contextLines) option and wires it through to UnifiedDiffManager.open(...).
  • Implements unchanged-region fold computation and lifecycle management using the editor projection (folding) model, including teardown of added fold annotations.
  • Adds “Expand n unchanged lines” code minings for collapsed fold regions and introduces a dedicated test suite for fold-region selection logic.

Reviewed changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
team/tests/org.eclipse.team.tests.core/src/org/eclipse/team/tests/ui/UnifiedDiffFoldRegionsTest.java New unit tests for computing which unchanged lines should be folded given diffs + context.
team/tests/org.eclipse.team.tests.core/src/org/eclipse/team/tests/core/AllTeamUITests.java Registers the new fold-region test in the Team UI test suite.
team/bundles/org.eclipse.compare/compare/org/eclipse/compare/unifieddiff/UnifiedDiff.java Adds the foldUnchanged(int) builder option and passes it to the manager.
team/bundles/org.eclipse.compare/compare/org/eclipse/compare/unifieddiff/internal/UnifiedDiffManager.java Computes unchanged fold regions, adds/removes tagged projection annotations, and updates code minings when folds change.
team/bundles/org.eclipse.compare/compare/org/eclipse/compare/unifieddiff/internal/UnifiedDiffCodeMiningProvider.java Adds fold-expander code minings based on collapsed fold annotations.
team/bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/CompareUIPlugin.java Enables unchanged-region folding with a default of 3 context lines when opening unified diff.
team/bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/CompareMessages.properties Adds NLS message keys for the fold-expander label(s).
team/bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/CompareMessages.java Adds corresponding NLS fields for the new expander messages.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment on lines +93 to +97
/**
* Collapses unchanged regions between diffs, keeping the given number of
* context lines (at least one) around each change. A negative value disables
* folding.
*/
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.

2 participants