Enable syntax coloring for footer minings in unified diff - #2949
tobiasmelcher merged 1 commit into
Conversation
|
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; |
|
Please squash your commits into one. |
|
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 |
da60a32 to
7429bc8
Compare
|
Thanks a lot for the careful review, @vogella — much appreciated! I've amended the review-feedback commit with the following changes:
The compare bundle builds cleanly and all tests pass locally. Please let me know if anything else should be adjusted. |
|
Yes, see #2949 (comment) |
7429bc8 to
d2569a9
Compare
|
Thanks again, @vogella — you're absolutely right on both points. On the The footer test previously relied on that unguarded NPE path (it used a bare On squashing: done — the branch is now a single commit. All tests pass locally. Thanks for the thorough review! |
|
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. |
d2569a9 to
aa256c3
Compare
|
Do you have further feedback? Or are there any objections? I plan to merge this change tomorrow. |
testFooterMiningStyleRangesUseTheSameLogicAsTheHeader asserts that lastRectangle is set after drawing. But draw() sets lastRectangle (diff line 151) before it decides whether to color. The test would pass even if the plain fallback ran. Also he test reconciler uses new TextAttribute(null), so there is no color at all. A token with a real foreground color, plus a check on the ranges or the drawn pixels, would actually test the change.
|
aa256c3 to
1c42f53
Compare
|
Thanks again, @vogella — both points are now addressed:
The compare bundle builds cleanly and all tests pass locally. Assisted by Claude. |
1c42f53 to
9b02f40
Compare
|
A few more change request:
|
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. The word-level detailed-diff highlight rectangles are now measured using the styled font of each run rather than the base font, so the highlight stays correctly aligned when bold or italic text precedes the changed word on the same line.
9b02f40 to
88fefb2
Compare
1. 2. I could not reuse As a result the header is untouched by this change — the earlier attempt to make 3. The test did not check what I do have some doubts whether these pixel-based tests are stable across all platforms. We will 4. Minor. Test imports sorted; the overlay calls |
|
@tobiasmelcher I see you pushed a very similar branch to the upstream repo: If it can be deleted, please just do so. |
@HannesWell sorry, my fault. I just deleted the branch. |


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
DocumentFooterCodeMiningis 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:
computeStyleRangespath.transformFontStyleToFont.drawStyleRangeshelper used by the header.detailedDiffColorrectangles are filled behind the syntax-colored text (the same "fill background, then draw transparent text" order the header uses), so the darker word-level highlight shows in the footer band itself, not only in the double-click overlay.MouseClickConsumer(introduced via the newIUnifiedDiffCodeMininginterface) gives footer minings the same double-click overlay behaviour the header already had.The footer reaches this parity by reusing the existing
createDetailedDiffBackgroundRangeshelper to locate the word-level ranges rather than duplicating the header's geometric background-painting code. The footer label is now trailing-newline-stripped like the header's, so the overlay no longer needs a compensatingstripTrailing(), and the syntax-coloring ranges are cached so repaints skip recomputation.Assisted by Claude (Anthropic).