Skip to content

CodeMinings: Add support for rendering placeholder while resolving #3723 - #4508

Open
flori-schwa wants to merge 1 commit into
eclipse-platform:masterfrom
vi-eclipse:fschwabe/codemining-placeholders
Open

flori-schwa wants to merge 1 commit into
eclipse-platform:masterfrom
vi-eclipse:fschwabe/codemining-placeholders

Conversation

@flori-schwa

@flori-schwa flori-schwa commented Oct 16, 2026 •

Copy link
Copy Markdown

Codemining implementations can now opt-in to rendering placeholder text
to prevent editor jumping. The IPlaceholderCodeMining interface must be
implemented and getPlaceholderLabel() should return a non-empty string.

If no label is set and there is no last resolved mining, the placeholder
text will be shown while the resolve() Future is still running.

Fixes #3723

Example Usage:

In JavaImplementationCodeMining (JDT):

  • implement the new IPlaceholderCodeMining interface:
-public class JavaImplementationCodeMining extends AbstractJavaElementLineHeaderCodeMining {
+public class JavaImplementationCodeMining extends AbstractJavaElementLineHeaderCodeMining implements IPlaceholderCodeMining {
  • Implement the getPlaceholderLabel() Method:
@Override
public String getPlaceholderLabel() {
  if (!showImplementationsAtLeastOne) {
    return "?? implementations"; //$NON-NLS-1$
  }
  return null;
}

Here is a screen recording where I added a placeholder to the "Java References" and "Java Implementations" Code minings. I also added a random delay in the resolve method to simulate work.

Placeholders.mp4

@flori-schwa
flori-schwa force-pushed the fschwabe/codemining-placeholders branch 2 times, most recently from 0113326 to 05782b5 Compare October 16, 2026 17:36
@flori-schwa flori-schwa changed the title CodeMinings: Add support for rendering placeholders while resolving() CodeMinings: Add support for rendering placeholder while resolving #3723 Oct 17, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Test Results

   867 files  ± 0     867 suites  ±0   49m 27s ⏱️ - 10m 41s
 8 470 tests + 5   8 228 ✅ + 5  242 💤 ±0  0 ❌ ±0 
21 288 runs  +15  20 605 ✅ +15  683 💤 ±0  0 ❌ ±0 

Results for commit 05782b5. ± Comparison against base commit 3faf11c.

This pull request removes 2 and adds 7 tests. Note that renamed tests count towards both.
org.eclipse.jface.text.tests.codemining.CodeMiningLineHeaderAnnotationTest ‑ testGetHeightDoesNotReturnZero
org.eclipse.jface.text.tests.codemining.CodeMiningLineHeaderAnnotationTest ‑ testTwoLineCodeMiningHeightMatchesTextWidgetLineHeight
org.eclipse.jface.text.tests.codemining.CodeMiningLineHeaderAnnotationTest ‑ testGetHeightDoesNotReturnZero(boolean)[1] placeHolder: false
org.eclipse.jface.text.tests.codemining.CodeMiningLineHeaderAnnotationTest ‑ testGetHeightDoesNotReturnZero(boolean)[2] placeHolder: true
org.eclipse.jface.text.tests.codemining.CodeMiningLineHeaderAnnotationTest ‑ testResolvedPlaceholderDoesNotRequestRedraw
org.eclipse.jface.text.tests.codemining.CodeMiningLineHeaderAnnotationTest ‑ testTwoLineCodeMiningHeightMatchesTextWidgetLineHeight(boolean)[1] placeHolder: false
org.eclipse.jface.text.tests.codemining.CodeMiningLineHeaderAnnotationTest ‑ testTwoLineCodeMiningHeightMatchesTextWidgetLineHeight(boolean)[2] placeHolder: true
org.eclipse.jface.text.tests.codemining.CodeMiningLineHeaderAnnotationTest ‑ testUnresolvedPlaceholderRequestsRedraw
org.eclipse.jface.text.tests.codemining.CodeMiningTest ‑ testLineHeaderCodeMiningPlaceholder

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.

🟡 Changes recommended

Incorrect click-target mapping, a null-label painting race, and a nondeterministic test remain unresolved.

3 open issues
What changed in this PR

Adds opt-in code-mining placeholders to reduce editor content shifting while labels resolve asynchronously, addressing #3723.

Changes:

  • Introduces IPlaceholderCodeMining to distinguish placeholder labels from resolved labels.
  • Updates header, inline, and footer rendering to support placeholders without caching them as resolved results.
  • Adds placeholder rendering, height, and redraw tests.
File Description
tests/​org.eclipse.jface.text.tests/​src/​org/​eclipse/​jface/​text/​tests/​codemining/​PlaceholderLineHeaderCodeMining.java Adds a reusable placeholder-enabled test mining.
tests/​org.eclipse.jface.text.tests/​src/​org/​eclipse/​jface/​text/​tests/​codemining/​CodeMiningTest.java Tests placeholder-to-resolved label rendering.
tests/​org.eclipse.jface.text.tests/​src/​org/​eclipse/​jface/​text/​tests/​codemining/​CodeMiningLineHeaderAnnotationTest.java Tests placeholder height and resolution-triggered redraws.
bundles/​org.eclipse.jface.text/​src/​org/​eclipse/​jface/​text/​codemining/​IPlaceholderCodeMining.java Defines the public placeholder contract.
bundles/​org.eclipse.jface.text/​src/​org/​eclipse/​jface/​internal/​text/​codemining/​CodeMiningManager.java Adds a helper to identify unresolved placeholders.
bundles/​org.eclipse.jface.text/​src/​org/​eclipse/​jface/​internal/​text/​codemining/​CodeMiningLineHeaderAnnotation.java Supports placeholder drawing and separates resolved-cache handling.
bundles/​org.eclipse.jface.text/​src/​org/​eclipse/​jface/​internal/​text/​codemining/​CodeMiningLineContentAnnotation.java Supports inline placeholders and resolution-triggered redraws.
bundles/​org.eclipse.jface.text/​src/​org/​eclipse/​jface/​internal/​text/​codemining/​CodeMiningDocumentFooterAnnotation.java Updates footer height checks and resolved-cache handling.

Review effort: Balanced

@flori-schwa
flori-schwa force-pushed the fschwabe/codemining-placeholders branch 4 times, most recently from 26f3acd to e80a3e9 Compare November 6, 2026 14:12
@fedejeanne

Copy link
Copy Markdown
Member

Thanks for the update, the separate getPlaceholderLabel() method works well: getLabel() keeps its meaning, the click mapping and the "last resolved vs. placeholder" decision are now correct, and all my earlier points are addressed except the two below.

1. Test helper cleanup (the open thread on PlaceholderLineHeaderCodeMining)

PlaceholderLineHeaderCodeMining still has three constructors but only one is used. UnresolvedPlaceholderMining and ResolvablePlaceholderMining in CodeMiningLineHeaderAnnotationTest duplicate it. The patch below makes PlaceholderLineHeaderCodeMining concrete with a single constructor that takes the placeholder label, and reuses it everywhere.

2. Javadoc caveats for implementors of IPlaceholderCodeMining: the placeholder only prevents jumping if it has the same number of lines as the resolved label, and a null/empty resolved label makes the lines disappear again. Also included in the patch.

I applied the patch on top of e80a3e927c and ran CodeMiningLineHeaderAnnotationTest (11 tests) and CodeMiningTest (20 tests) with Tycho. It compiles and all tests pass.

Patch (apply with git apply)
diff --git a/bundles/org.eclipse.jface.text/src/org/eclipse/jface/text/codemining/IPlaceholderCodeMining.java b/bundles/org.eclipse.jface.text/src/org/eclipse/jface/text/codemining/IPlaceholderCodeMining.java
index 3ac92cfd2f..64664cb4c0 100644
--- a/bundles/org.eclipse.jface.text/src/org/eclipse/jface/text/codemining/IPlaceholderCodeMining.java
+++ b/bundles/org.eclipse.jface.text/src/org/eclipse/jface/text/codemining/IPlaceholderCodeMining.java
@@ -36,6 +36,10 @@ import org.eclipse.jface.text.ITextViewer;
  * <li>If resolution fails or is cancelled, the label should remain {@code null}. The mining is then
  * treated as resolved with an error, see {@link ICodeMining#getLabel()}.</li>
  * </ul>
+ * <p>
+ * To actually prevent editor jumping, the placeholder should have the same number of lines as the
+ * resolved label. If the mining resolves to a {@code null} or empty label, the placeholder
+ * disappears and the lines it occupied are removed again.
  *
  * @see ICodeMining
  * @since 3.32
diff --git a/tests/org.eclipse.jface.text.tests/src/org/eclipse/jface/text/tests/codemining/CodeMiningLineHeaderAnnotationTest.java b/tests/org.eclipse.jface.text.tests/src/org/eclipse/jface/text/tests/codemining/CodeMiningLineHeaderAnnotationTest.java
index bb846d0cb1..23c8306ae1 100644
--- a/tests/org.eclipse.jface.text.tests/src/org/eclipse/jface/text/tests/codemining/CodeMiningLineHeaderAnnotationTest.java
+++ b/tests/org.eclipse.jface.text.tests/src/org/eclipse/jface/text/tests/codemining/CodeMiningLineHeaderAnnotationTest.java
@@ -47,12 +47,9 @@ import org.eclipse.jface.internal.text.codemining.CodeMiningLineHeaderAnnotation
 
 import org.eclipse.jface.text.BadLocationException;
 import org.eclipse.jface.text.Document;
-import org.eclipse.jface.text.IDocument;
 import org.eclipse.jface.text.ITextViewer;
 import org.eclipse.jface.text.Position;
 import org.eclipse.jface.text.codemining.ICodeMining;
-import org.eclipse.jface.text.codemining.ICodeMiningProvider;
-import org.eclipse.jface.text.codemining.IPlaceholderCodeMining;
 import org.eclipse.jface.text.codemining.LineHeaderCodeMining;
 import org.eclipse.jface.text.source.AnnotationModel;
 import org.eclipse.jface.text.source.AnnotationPainter;
@@ -297,7 +294,7 @@ public class CodeMiningLineHeaderAnnotationTest {
 
 		String placeholder= "Placeholder";
 
-		ICodeMining mining= new ResolvablePlaceholderMining(0, document, null, placeholder) {
+		ICodeMining mining= new PlaceholderLineHeaderCodeMining(0, document, null, placeholder) {
 
 			@Override
 			public Point draw(GC gc, StyledText textWidget, Color color, int x, int y) {
@@ -343,7 +340,7 @@ public class CodeMiningLineHeaderAnnotationTest {
 
 		String placeholder= "Placeholder";
 
-		ICodeMining mining= new ResolvablePlaceholderMining(0, document, null, placeholder) {
+		ICodeMining mining= new PlaceholderLineHeaderCodeMining(0, document, null, placeholder) {
 			@Override
 			protected CompletableFuture<Void> doResolve(ITextViewer viewer, IProgressMonitor monitor) {
 				resolveRequested.set(true);
@@ -387,7 +384,7 @@ public class CodeMiningLineHeaderAnnotationTest {
 			}
 		};
 
-		ICodeMining unresolvedPlaceholder= new ResolvablePlaceholderMining(0, document, null, "Placeholder") {
+		ICodeMining unresolvedPlaceholder= new PlaceholderLineHeaderCodeMining(0, document, null, "Placeholder") {
 			@Override
 			public Point draw(GC gc, StyledText textWidget, Color color, int x, int y) {
 				drawnMining.compareAndSet(null, this);
@@ -412,7 +409,12 @@ public class CodeMiningLineHeaderAnnotationTest {
 	}
 
 	private LineHeaderCodeMining unresolvedPlaceholder(String label) throws BadLocationException {
-		return new UnresolvedPlaceholderMining(0, document, null, label);
+		return new PlaceholderLineHeaderCodeMining(0, document, null, label) {
+			@Override
+			public boolean isResolved() {
+				return false;
+			}
+		};
 	}
 
 	private LineHeaderCodeMining codeMining(String label) throws BadLocationException {
@@ -432,41 +434,4 @@ public class CodeMiningLineHeaderAnnotationTest {
 		return new Font(textWidget.getDisplay(), "Consolas", height, SWT.NORMAL); //$NON-NLS-1$
 	}
 
-	private static class UnresolvedPlaceholderMining extends LineHeaderCodeMining implements IPlaceholderCodeMining {
-
-		private final String placeholderLabel;
-
-		public UnresolvedPlaceholderMining(int beforeLineNumber, IDocument document, ICodeMiningProvider provider, String label) throws BadLocationException {
-			super(beforeLineNumber, document, provider);
-			this.placeholderLabel= label;
-		}
-
-		@Override
-		public boolean isResolved() {
-			return false;
-		}
-
-		@Override
-		public String getPlaceholderLabel() {
-			return placeholderLabel;
-		}
-
-	}
-
-	private static class ResolvablePlaceholderMining extends LineHeaderCodeMining implements IPlaceholderCodeMining {
-
-		private final String placeholderLabel;
-
-		public ResolvablePlaceholderMining(int beforeLineNumber, IDocument document, ICodeMiningProvider provider, String placeholder) throws BadLocationException {
-			super(beforeLineNumber, document, provider);
-			this.placeholderLabel= placeholder;
-		}
-
-		@Override
-		public String getPlaceholderLabel() {
-			return placeholderLabel;
-		}
-
-	}
-
 }
diff --git a/tests/org.eclipse.jface.text.tests/src/org/eclipse/jface/text/tests/codemining/CodeMiningTest.java b/tests/org.eclipse.jface.text.tests/src/org/eclipse/jface/text/tests/codemining/CodeMiningTest.java
index 93d47efdf3..2dfe7730fe 100644
--- a/tests/org.eclipse.jface.text.tests/src/org/eclipse/jface/text/tests/codemining/CodeMiningTest.java
+++ b/tests/org.eclipse.jface.text.tests/src/org/eclipse/jface/text/tests/codemining/CodeMiningTest.java
@@ -891,12 +891,7 @@ public class CodeMiningTest {
 					@Override
 					public CompletableFuture<List<? extends ICodeMining>> provideCodeMinings(ITextViewer viewer, IProgressMonitor monitor) {
 						try {
-							ICodeMining mining= new PlaceholderLineHeaderCodeMining(0, viewer.getDocument(), this) {
-
-								@Override
-								public String getPlaceholderLabel() {
-									return placeholderText;
-								}
+							ICodeMining mining= new PlaceholderLineHeaderCodeMining(0, viewer.getDocument(), this, placeholderText) {
 
 								@Override
 								protected CompletableFuture<Void> doResolve(ITextViewer theViewer, IProgressMonitor theMonitor) {
diff --git a/tests/org.eclipse.jface.text.tests/src/org/eclipse/jface/text/tests/codemining/PlaceholderLineHeaderCodeMining.java b/tests/org.eclipse.jface.text.tests/src/org/eclipse/jface/text/tests/codemining/PlaceholderLineHeaderCodeMining.java
index 7f7e3024fa..28673ca5db 100644
--- a/tests/org.eclipse.jface.text.tests/src/org/eclipse/jface/text/tests/codemining/PlaceholderLineHeaderCodeMining.java
+++ b/tests/org.eclipse.jface.text.tests/src/org/eclipse/jface/text/tests/codemining/PlaceholderLineHeaderCodeMining.java
@@ -10,29 +10,27 @@
  *******************************************************************************/
 package org.eclipse.jface.text.tests.codemining;
 
-import java.util.function.Consumer;
-
-import org.eclipse.swt.events.MouseEvent;
-
 import org.eclipse.jface.text.BadLocationException;
 import org.eclipse.jface.text.IDocument;
-import org.eclipse.jface.text.Position;
 import org.eclipse.jface.text.codemining.ICodeMiningProvider;
 import org.eclipse.jface.text.codemining.IPlaceholderCodeMining;
 import org.eclipse.jface.text.codemining.LineHeaderCodeMining;
 
-public abstract class PlaceholderLineHeaderCodeMining extends LineHeaderCodeMining implements IPlaceholderCodeMining {
+/**
+ * {@link LineHeaderCodeMining} with a fixed placeholder label for tests.
+ */
+public class PlaceholderLineHeaderCodeMining extends LineHeaderCodeMining implements IPlaceholderCodeMining {
 
-	public PlaceholderLineHeaderCodeMining(int beforeLineNumber, IDocument document, ICodeMiningProvider provider, Consumer<MouseEvent> action) throws BadLocationException {
-		super(beforeLineNumber, document, provider, action);
-	}
+	private final String placeholderLabel;
 
-	public PlaceholderLineHeaderCodeMining(int beforeLineNumber, IDocument document, ICodeMiningProvider provider) throws BadLocationException {
+	public PlaceholderLineHeaderCodeMining(int beforeLineNumber, IDocument document, ICodeMiningProvider provider, String placeholderLabel) throws BadLocationException {
 		super(beforeLineNumber, document, provider);
+		this.placeholderLabel= placeholderLabel;
 	}
 
-	public PlaceholderLineHeaderCodeMining(Position position, ICodeMiningProvider provider, Consumer<MouseEvent> action) throws BadLocationException {
-		super(position, provider, action);
+	@Override
+	public String getPlaceholderLabel() {
+		return placeholderLabel;
 	}
 
 }

…lipse-platform#3723

Codemining implementations can now opt-in to rendering placeholder text
to prevent editor jumping. The IPlaceholderCodeMining interface must be
implemented and getPlaceholderLabel() should return a non-empty string.

If no label is set and there is no last resolved mining, the placeholder
text will be shown while the resolve() Future is still running.

Fixes eclipse-platform#3723
@flori-schwa
flori-schwa force-pushed the fschwabe/codemining-placeholders branch from e80a3e9 to 05bffd8 Compare November 16, 2026 12:39
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.

Prevent editor "jumping" by using placeholders for Code Minings

3 participants