Skip to content

Show the unified diff for a file that is gone from the workspace - #2875

Merged
vogella merged 1 commit into
eclipse-platform:masterfrom
vogella:unified-diff-deleted-file
Aug 14, 2026
Merged

Show the unified diff for a file that is gone from the workspace#2875
vogella merged 1 commit into
eclipse-platform:masterfrom
vogella:unified-diff-deleted-file

Conversation

@vogella

@vogella vogella commented Aug 13, 2026

Copy link
Copy Markdown
Contributor

Comparing a file that was deleted in the workspace, its state against the git index for example, opened the classic compare editor, because neither side is a workspace file and there was nothing to overlay the diff onto. The version that still exists is now shown read-only instead, with its whole content marked as removed.

The reason such an editor came up without any diff was not the content, which loads fine, but the annotations: an editor on a storage editor input gets no annotation model, since StorageDocumentProvider.createAnnotationModel returns null by design. UnifiedDiffManager now falls back to the model installed on the source viewer and installs a plain AnnotationModel when the document provider has none, so the diffs have somewhere to go. When the remaining version comes up without content at all, the classic compare editor still takes over and the editor opened a moment earlier is closed again.

Which side is absent is decided from the element alone, an element without contents or one whose resource does not exist, so unifiedDiffCandidateOf performs no content reads and canShowAsUnifiedDiff stays cheap. Two sides that both exist keep opening the classic compare editor, so #2876 is deliberately untouched. Three new tests in UnifiedDiffOpenTest use an element whose shared document adapter hands out a storage editor input, mirroring EGit's FileRevisionTypedElement, and cover the deleted file, two versions with content, and an empty remaining version.

Together with eclipse-platform/eclipse.platform.ui#2874 this covers eclipse-platform/eclipse.platform.ui#2868. Rebased on master now that #2854 and eclipse-platform/eclipse.platform.ui#2874 are merged, so this is a single commit.

One point for review: installing an annotation model on an editor the platform owns is a decoration AbstractTextEditor does not know about, so a later setDocument by the editor would drop it, and that editor has no markers or quick diff (it had none before either). @tobiasmelcher, does that seem acceptable to you?

@github-actions

github-actions Bot commented Aug 13, 2026

Copy link
Copy Markdown
Contributor

Test Results

    54 files  ±0      54 suites  ±0   58m 45s ⏱️ -41s
 4 759 tests +3   4 737 ✅ +3   22 💤 ±0  0 ❌ ±0 
12 168 runs  +9  12 015 ✅ +9  153 💤 ±0  0 ❌ ±0 

Results for commit b9a3d34. ± Comparison against base commit 1afe961.

♻️ This comment has been updated with latest results.

@vogella

vogella commented Aug 13, 2026

Copy link
Copy Markdown
Contributor Author
image

@vogella
vogella marked this pull request as ready for review August 13, 2026 13:04
Comparing a file that was deleted in the workspace, its state against the git
index for example, opened the classic compare editor. Neither side is a
workspace file then, so there was nothing to overlay the diff onto.

The version that still exists is shown read-only instead, with its whole
content marked as removed. Its document key is a storage editor input, and
StorageDocumentProvider supplies no annotation model for it, which is the real
reason such an editor came up without any diff: the annotations had nowhere to
go. The unified diff now installs a model on the source viewer when the
document provider has none, and falls back to the classic compare editor when
the version comes up without content at all.

Two sides that both carry content, staged changes for example, keep opening
the classic compare editor, because neither of them is the state on disk.
@vogella
vogella force-pushed the unified-diff-deleted-file branch from 699f5ee to b9a3d34 Compare August 14, 2026 10:12
@tobiasmelcher

Copy link
Copy Markdown
Contributor

Thanks so much for this improvement! I tested it on my machine and unified diff is now used for deleted files in the "Unstaged Changes" view, which is great.

One thing I noticed: if I move the deleted file to the "Staged Changes" view, unified diff is no longer used. Do you have plans to support that scenario as well?

@vogella

vogella commented Aug 14, 2026

Copy link
Copy Markdown
Contributor Author

Thanks @tobiasmelcher for the review and feedback.

The stage situation is #2876 (I just moved it from eclipse.platform.ui to this repo) and has not yet been fixed. This PR is a prerequisite for such support.

@vogella
vogella merged commit 7d8eb62 into eclipse-platform:master Aug 14, 2026
18 checks passed
@vogella
vogella deleted the unified-diff-deleted-file branch August 14, 2026 11:07
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