Skip to content

Enable syntax coloring for footer minings in unified diff - #2949

Open
tobiasmelcher wants to merge 1 commit into
eclipse-platform:masterfrom
tobiasmelcher:d031119/unified-diff-footer-styling
Open

tobiasmelcher wants to merge 1 commit into
eclipse-platform:masterfrom
tobiasmelcher:d031119/unified-diff-footer-styling

Conversation

@tobiasmelcher

Copy link
Copy Markdown
Contributor

Footer minings are used when a diff sits at the end of a document that has no trailing newline — in that case there is no following line to anchor a line-header mining, so a DocumentFooterCodeMining is created instead.

These footer minings were missing the syntax coloring that line-header minings already provide: they fell back to a plain super.draw() call, rendering all text in the default foreground color without any keyword highlighting or font styling.

This change brings footer minings to parity with line-header minings:

  • Syntax coloring is applied via the same computeStyleRanges path.
  • Bold/italic font styles are handled via transformFontStyleToFont.
  • The rendering loop mirrors the header implementation exactly.
  • A shared MouseClickConsumer (introduced via the new IUnifiedDiffCodeMining interface) gives footer minings the same double-click overlay behaviour the header already had.

Assisted by Claude (Anthropic).

@github-actions

github-actions Bot commented Sep 18, 2026

Copy link
Copy Markdown
Contributor

Test Results

    54 files  ±0      54 suites  ±0   56m 51s ⏱️ - 2m 43s
 4 812 tests +2   4 790 ✅ +2   22 💤 ±0  0 ❌ ±0 
12 327 runs  +6  12 174 ✅ +6  153 💤 ±0  0 ❌ ±0 

Results for commit d2569a9. ± Comparison against base commit 2d15cf3.

♻️ This comment has been updated with latest results.

@vogella

vogella commented Sep 18, 2026

Copy link
Copy Markdown
Contributor

You have two dead constructor parameters. UnifiedDiffFooterCodeMining takes Color detailedDiffColor and never stores or uses it, and it takes Consumer action which it silently discards in favour of new MouseClickConsumer(viewer).

UnifiedDiffFooterCodeMining.draw() lines 621-692 are a copy of the header loop at 1093-1157. The only difference is that the header also appends ForegroundInfo entries to its foregrounds cache. Use Consumer as parameter.

Also the test testFooterMiningStyleRangesUseTheSameLogicAsTheHeader does not test the change, it only checks for is non-empty;

@vogella

vogella commented Sep 18, 2026

Copy link
Copy Markdown
Contributor

Please squash your commits into one.

@vogella

vogella commented Sep 18, 2026

Copy link
Copy Markdown
Contributor

I think you added an unrelated change: catch (BadLocationException | NullPointerException e)

The NPE does not come from this file: the test builds new ProjectionViewer(shell, null, null, false, SWT.V_SCROLL) and never calls configure(...), so fPresentationReconciler is null, and SourceViewer.computeStyleRanges dereferences it unguarded at reconciler.getRepairer(partitioningRegion.getType()).

I think the real defaultg is a missing null guard in SourceViewer.computeStyleRanges in eclipse.platform.ui. Catching bare NPE here also silents NPEs thrown by real presentation repairers.

I fixed it there, please have a look eclipse-platform/eclipse.platform.ui#4394

@tobiasmelcher
tobiasmelcher force-pushed the d031119/unified-diff-footer-styling branch from da60a32 to 7429bc8 Compare September 18, 2026 15:32
@tobiasmelcher

Copy link
Copy Markdown
Contributor Author

Thanks a lot for the careful review, @vogella — much appreciated!

I've amended the review-feedback commit with the following changes:

  • Footer font-handle leak: UnifiedDiffFooterCodeMining now mirrors the header's font-change handling. It tracks the base font and disposes the derived styled fonts when the editor font changes, instead of only at dispose(), so the native font handles are no longer leaked on a font change.
  • Narrowed the NullPointerException catch in computeStyleRanges: the null document case is now handled with an explicit guard, and the remaining NPE catch is scoped to just the SourceViewer.computeStyleRanges call (whose presentation reconciler cannot be checked from the outside). Any genuine NPE elsewhere in that method now propagates instead of being silently swallowed.
  • Clarified the footer test: renamed and reworded it to describe what it actually verifies — that draw() runs to completion and degrades gracefully when the viewer offers no syntax coloring.

The compare bundle builds cleanly and all tests pass locally. Please let me know if anything else should be adjusted.

@vogella

vogella commented Sep 18, 2026

Copy link
Copy Markdown
Contributor

Yes, see #2949 (comment)

Line-header minings already applied syntax coloring via StyleRange
computation. Footer minings (used when the diff sits at the end of a
document without a trailing newline) were missing this: they fell back to
a plain super.draw() call for the text. They now use the same
computeStyleRanges path, transformFontStyleToFont for bold/italic, and
the same rendering loop as the header. A shared MouseClickConsumer
(via the new IUnifiedDiffCodeMining interface) also gives footer minings
the same double-click overlay behaviour the header already had.
@tobiasmelcher
tobiasmelcher force-pushed the d031119/unified-diff-footer-styling branch from 7429bc8 to d2569a9 Compare September 18, 2026 15:41
@tobiasmelcher

Copy link
Copy Markdown
Contributor Author

Thanks again, @vogella — you're absolutely right on both points.

On the NullPointerException: I've removed the bare catch (... | NullPointerException). As you diagnosed, the NPE originates in SourceViewer.computeStyleRanges dereferencing a null fPresentationReconciler, not in this file, and catching it here would also have swallowed genuine NPEs from real presentation repairers. computeStyleRanges now catches only BadLocationException again, plus an explicit if (originalDocument == null) return ...; guard for the document-null case. Thank you for fixing the real cause upstream in eclipse-platform/eclipse.platform.ui#4394 — that's clearly the right place for it.

The footer test previously relied on that unguarded NPE path (it used a bare ProjectionViewer with no configure(...)). I've now given the test viewer a minimal presentation reconciler, so it exercises the real syntax-coloring path instead of depending on the missing null guard.

On squashing: done — the branch is now a single commit.

All tests pass locally. Thanks for the thorough review!

@vogella

vogella commented Sep 18, 2026

Copy link
Copy Markdown
Contributor

Stepping away from my laptop now, please feel free to merge eclipse-platform/eclipse.platform.ui#4394 once it is green. I think this change should wait until eclipse-platform/eclipse.platform.ui#4394 is in master.

Comment on lines +641 to +658
static final class ForegroundInfo {

final int x;
final int y;
final String str;
final Font font;
final Color background;
final Color foreground;

ForegroundInfo(int x, int y, String str, Font font, Color background, Color foreground) {
this.x = x;
this.y = y;
this.str = str;
this.font = font;
this.background = background;
this.foreground = foreground;
}
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Would it make sense to convert this class to a record? Could be more compact.

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.

3 participants