Skip to content

Fix TargetPlatformPresentationReconciler: stop scanning past damage end#2284

Open
vogella wants to merge 2 commits intoeclipse-pde:masterfrom
vogella:full-qualified-access
Open

Fix TargetPlatformPresentationReconciler: stop scanning past damage end#2284
vogella wants to merge 2 commits intoeclipse-pde:masterfrom
vogella:full-qualified-access

Conversation

@vogella
Copy link
Copy Markdown
Contributor

@vogella vogella commented Apr 6, 2026

Summary

Fixes #2283 (also related to eclipse-platform/eclipse.platform.ui#2276).

TargetPlatformPresentationReconciler.createPresentation() overrides the default
PresentationReconciler behaviour to always scan from offset 0. This is
necessary to correctly handle multi-line XML comment rules (<!-- ... -->):
without the full context from the start of the document, a comment that opened
before the damaged region would not be recognised.

However, the scan was running all the way to document.getLength() even though
the TextPresentation returned is constructed with the damage region as its
extent — meaning any style ranges added for content after the damage end are
silently discarded. This results in O(document length) work on the UI thread
for every keystroke, causing noticeable freezes in large .target files.

Changes

  • TargetPlatformPresentationReconciler — change the upper bound of
    TextUtilities.computePartitioning() from document.getLength() to
    damage.getOffset() + damage.getLength(). Scanning still starts at offset 0
    (multi-line rule correctness is preserved); it just stops where it would have
    discarded results anyway.

  • MANIFEST.MF (genericeditor.extension) — declare
    org.eclipse.pde.genericeditor.extension.tests as a friend of the
    reconciler.presentation package so the new tests can subclass the reconciler.

  • TargetPlatformPresentationReconcilerTest — new test class covering:

    • simple document, full damage
    • damage covering only the end of the document
    • multi-line comment before the damage region
    • damage region inside a multi-line comment

Known limitation

For edits very close to the end of a large file the gain is small (the damage
end ≈ the document end). A more thorough fix — e.g. caching scanner state
between edits, using a real IDocumentPartitioner for comments, or moving
reconciliation off the UI thread — is left for a follow-up.

Test plan

  • Compiles cleanly (mvn clean compile on the two affected bundles)
  • TargetPlatformPresentationReconcilerTest passes in a running Eclipse test environment
  • All existing AllTargetEditorTests continue to pass

🤖 Generated with Claude Code

@eclipse-pde-bot
Copy link
Copy Markdown
Contributor

eclipse-pde-bot commented Apr 6, 2026

This pull request changes some projects for the first time in this development cycle.
Therefore the following files need a version increment:

ui/org.eclipse.pde.genericeditor.extension.tests/META-INF/MANIFEST.MF
ui/org.eclipse.pde.genericeditor.extension.tests/pom.xml

An additional commit containing all the necessary changes was pushed to the top of this PR's branch. To obtain these changes (for example if you want to push more changes) either fetch from your fork or apply the git patch.

Git patch
From 0fa2556683520335d6b82feebcfa16423c685d74 Mon Sep 17 00:00:00 2001
From: Eclipse PDE Bot <pde-bot@eclipse.org>
Date: Mon, 6 Apr 2026 10:58:02 +0000
Subject: [PATCH] Version bump(s) for 4.40 stream


diff --git a/ui/org.eclipse.pde.genericeditor.extension.tests/META-INF/MANIFEST.MF b/ui/org.eclipse.pde.genericeditor.extension.tests/META-INF/MANIFEST.MF
index 035112ee37..e40d9d7d57 100644
--- a/ui/org.eclipse.pde.genericeditor.extension.tests/META-INF/MANIFEST.MF
+++ b/ui/org.eclipse.pde.genericeditor.extension.tests/META-INF/MANIFEST.MF
@@ -2,7 +2,7 @@ Manifest-Version: 1.0
 Bundle-ManifestVersion: 2
 Bundle-Name: Tests for Generic Target Platform Editor
 Bundle-SymbolicName: org.eclipse.pde.genericeditor.extension.tests
-Bundle-Version: 1.3.200.qualifier
+Bundle-Version: 1.3.300.qualifier
 Bundle-Vendor: Eclipse.org
 Bundle-RequiredExecutionEnvironment: JavaSE-21
 Require-Bundle: org.eclipse.core.runtime;bundle-version="[3.29.0,4.0.0)",
diff --git a/ui/org.eclipse.pde.genericeditor.extension.tests/pom.xml b/ui/org.eclipse.pde.genericeditor.extension.tests/pom.xml
index 8b3cafceec..4f98690f41 100644
--- a/ui/org.eclipse.pde.genericeditor.extension.tests/pom.xml
+++ b/ui/org.eclipse.pde.genericeditor.extension.tests/pom.xml
@@ -18,7 +18,7 @@
     <relativePath>../../</relativePath>
   </parent>
   <artifactId>org.eclipse.pde.genericeditor.extension.tests</artifactId>
-  <version>1.3.200-SNAPSHOT</version>
+  <version>1.3.300-SNAPSHOT</version>
   <packaging>eclipse-test-plugin</packaging>
 
   <properties>
-- 
2.53.0

Further information are available in Common Build Issues - Missing version increments.

@vogella vogella force-pushed the full-qualified-access branch from ad4c2fd to e08d95d Compare April 6, 2026 10:55
@github-actions
Copy link
Copy Markdown

github-actions bot commented Apr 6, 2026

Test Results

  150 files  + 3    150 suites  +3   36m 50s ⏱️ + 1m 29s
3 501 tests + 4  3 446 ✅ + 3   54 💤 ±0  1 ❌ +1 
9 324 runs  +12  9 193 ✅ +11  130 💤 ±0  1 ❌ +1 

For more details on these failures, see this check.

Results for commit 58c2c98. ± Comparison against base commit 50600c6.

♻️ This comment has been updated with latest results.

@vogella vogella force-pushed the full-qualified-access branch from 30a7061 to c91f39e Compare April 6, 2026 19:26
@vogella vogella marked this pull request as ready for review April 8, 2026 07:25
@vogella vogella force-pushed the full-qualified-access branch from c91f39e to a2b3bb3 Compare April 14, 2026 17:19
@vogella vogella requested a review from Copilot April 15, 2026 12:56
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Improves the Generic Target Platform Editor’s syntax highlighting reconciler performance by avoiding unnecessary full-document partition scanning while preserving correctness for multi-line XML comment rules.

Changes:

  • Limit TargetPlatformPresentationReconciler partition scan length to the end of the damage region (still starting at offset 0).
  • Export reconciler.presentation as a “friend” package to enable test subclassing.
  • Add a new JUnit test class and wire it into the existing test suite; bump test bundle versions accordingly.

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
.../TargetPlatformPresentationReconciler.java Stops partition scanning at damage end instead of document end to reduce UI-thread work.
.../org.eclipse.pde.genericeditor.extension/META-INF/MANIFEST.MF Marks reconciler.presentation as x-friends for the test bundle.
.../TargetPlatformPresentationReconcilerTest.java Adds new tests for reconciler behavior across damage/comment scenarios.
.../AllTargetEditorTests.java Includes the new reconciler test class in the suite.
.../org.eclipse.pde.genericeditor.extension.tests/pom.xml Bumps test bundle Maven version.
.../org.eclipse.pde.genericeditor.extension.tests/META-INF/MANIFEST.MF Bumps OSGi bundle version.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +124 to +126
int scanEnd = damage.getOffset() + damage.getLength();
ITypedRegion[] regions = TextUtilities.computePartitioning(document, getDocumentPartitioning(), 0,
document.getLength(), false);
scanEnd, false);
Copy link

Copilot AI Apr 15, 2026

Choose a reason for hiding this comment

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

scanEnd is derived from damage.getOffset() + damage.getLength() and is passed to TextUtilities.computePartitioning(...) as the length parameter. If the provided damage region ever extends past the current document.getLength() (e.g., due to a stale damage region during rapid edits), computePartitioning will throw BadLocationException and this method returns null, potentially breaking syntax highlighting. Consider clamping the computed scan length to document.getLength() (and generally ensuring it is within valid bounds) before calling computePartitioning.

Copilot uses AI. Check for mistakes.
Comment on lines +49 to +62
@Test
public void testCreatePresentationReturnsNonNullForSimpleDocument() {
TestableReconciler reconciler = new TestableReconciler();
String content = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" //$NON-NLS-1$
+ "<target name=\"test\">\n" //$NON-NLS-1$
+ " <locations/>\n" //$NON-NLS-1$
+ "</target>\n"; //$NON-NLS-1$
IDocument document = new Document(content);
IRegion damage = new Region(0, content.length());

TextPresentation presentation = reconciler.createPresentation(document, damage);

assertNotNull("Expected a non-null TextPresentation for a simple document", presentation); //$NON-NLS-1$
}
Copy link

Copilot AI Apr 15, 2026

Choose a reason for hiding this comment

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

These tests only assert that createPresentation(...) returns a non-null TextPresentation, which would still pass even if the reconciler kept scanning to the end of the document (the original regression) or produced incorrect styling. To make this a meaningful regression test for the performance fix, consider installing a custom IDocumentPartitioner (or similar hook) on the IDocument that records the offset/length requested by TextUtilities.computePartitioning, then assert that the computed length matches damage.getOffset() + damage.getLength() rather than document.getLength().

Copilot uses AI. Check for mistakes.
@vogella vogella force-pushed the full-qualified-access branch from a2b3bb3 to 31f0806 Compare April 15, 2026 13:27
vogella and others added 2 commits April 15, 2026 15:27
The reconciler always scanned the full document (offset 0 to
document.getLength()) on every keystroke to ensure multi-line XML
comment rules are honoured. While scanning from offset 0 is required
for correctness, scanning *past* the damage end is wasted work because
the returned TextPresentation is bounded by the damage region and
silently discards any style ranges beyond it.

Change the upper bound of TextUtilities.computePartitioning() from
document.getLength() to damage.getOffset() + damage.getLength(). This
avoids scanning content whose results would be thrown away, while
preserving the full-context scan from offset 0 that multi-line rules
require.

Add TargetPlatformPresentationReconcilerTest to verify correctness for
the common cases: simple documents, partial damage regions, multi-line
comments before the damage, and damage inside a multi-line comment.

Fixes: eclipse-pde#2283

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@vogella vogella force-pushed the full-qualified-access branch from 31f0806 to 58c2c98 Compare April 15, 2026 13:27
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.

PDE Reconciler slow and blocking the UI

3 participants