Skip to content

Add a syntax-highlighted source preview pane to the Open Type dialog - #3259

Open
deepika-u wants to merge 1 commit into
eclipse-jdt:masterfrom
deepika-u:preview_update_open_type
Open

deepika-u wants to merge 1 commit into
eclipse-jdt:masterfrom
deepika-u:preview_update_open_type

Conversation

@deepika-u

@deepika-u deepika-u commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor

Summary
Adds a source preview pane to the Open Type dialog (Ctrl+Shift+T), similar to Quick Search (Ctrl+Alt+Shift+L). It shows the selected type's source with line numbers and Java syntax highlighting, scrolled to the type declaration.

Problem
To inspect a type, or to tell apart types with the same simple name in different packages or modules, you have to open each one in an editor.

Solution

  • A read-only JavaSourceViewer below the results list, using the Java editor font and given an accessible name. It stays hidden until a single type is selected.
  • The source is read and partitioned in a background job (50 ms debounce), so the UI thread is not blocked by loading it. Stale results are dropped, and the job is cancelled when the dialog closes.
  • The type name is shown in bold, and the pane scrolls to the declaration.
  • With an empty filter, the preview follows the history list, with the mouse and with Up and Down.
  • The preview is cleared on no selection, multi-selection or an error status. "Source not available." is shown if no source can be found.
  • Scope: OpenTypeSelectionDialog is shared, so the preview also appears in Open Type in Hierarchy (Ctrl+Shift+H) and in the Add Super Interface dialog.

Tests (FilteredTypesSelectionDialogTests)

  • Preview shows the selected type's source, and is cleared when the selection is removed.
  • Multi-selection clears the preview, and the preview works again afterwards.
  • History entries (empty filter) each get their own preview. The history is filled by opening the types with the dialog, as a user would.

Verification

  • Preview appears and updates when switching between types.
  • "Source not available." for a binary type without attached source.
  • Empty filter: preview follows Up and Down through the history list.

After the pr ->
image

@iloveeclipse

Copy link
Copy Markdown
Member

Cool feature, works fast.

Few immediately observed issues:

I see that the preview isn't properly cleared once one typed something and removed text again. Previously shown class content remains visible:

image

Also I don't like the initial empty list with scrollbars shown at the beginning:

image

Could it be simply hidden & appear only if something is selected?

Also if multiple selection is used, the preview still shows some code and it is not clear which one is actually shown. On multiple selection the preview should be cleared.

That was after 5 minutes playing with the code, so there could be more.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

Source loading can block the UI thread, and preview layout, error fallback, and RTL rendering need correction.

4 open findings
What changed in this PR

Adds a source-code preview pane to the Open Type dialog.

Changes:

  • Adds syntax-highlighted source preview with line numbers and declaration highlighting.
  • Supports workspace and binary source with a fallback message.
  • Adds a UI test for workspace source rendering.
File Description
JavaUIMessages.properties Adds the unavailable-source message.
JavaUIMessages.java Exposes the message field.
OpenTypeSelectionDialog.java Implements preview creation and updates.
FilteredTypesSelectionDialogTests.java Tests basic preview rendering.

🧠 Review effort: Balanced


💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@deepika-u

Copy link
Copy Markdown
Contributor Author

Cool feature, works fast.

Thanks alot.

That was after 5 minutes playing with the code, so there could be more.

I'll check on the clear/refresh/scroll bar parts - thanks for the feedback.

@deepika-u
deepika-u force-pushed the preview_update_open_type branch 2 times, most recently from 39c9823 to 3070fc1 Compare October 14, 2026 07:10
@SougandhS
SougandhS requested a balanced review from Copilot October 15, 2026 00:51
@SougandhS SougandhS added the enhancement New feature or request label Oct 15, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@deepika-u
deepika-u force-pushed the preview_update_open_type branch 2 times, most recently from de9d779 to 3b60f6b Compare October 15, 2026 13:29
@iloveeclipse

Copy link
Copy Markdown
Member

@deepika-u : if you fix some review comments by pushing new commits to the PR, please also resolve the review comments which were addressed by latest push, so it is easier to understand what is fixed and what not.

@deepika-u

deepika-u commented Oct 15, 2026 •

Copy link
Copy Markdown
Contributor Author

That was after 5 minutes playing with the code, so there could be more.

All the issues listed above are addressed, can you check now please? and share opinion on the query please.
@iloveeclipse

@deepika-u

Copy link
Copy Markdown
Contributor Author

@deepika-u : if you fix some review comments by pushing new commits to the PR, please also resolve the review comments which were addressed by latest push, so it is easier to understand what is fixed and what not.

Yes done, Thanks for your time.

@iloveeclipse

Copy link
Copy Markdown
Member

@deepika-u

Copy link
Copy Markdown
Contributor Author

See test fails: https://ci.eclipse.org/jdt/job/eclipse.jdt.ui-github/job/PR-3259/6/testReport/

Let me check them, thanks.

@deepika-u
deepika-u force-pushed the preview_update_open_type branch 2 times, most recently from 96da788 to 05ae7bb Compare October 16, 2026 06:56
@deepika-u

Copy link
Copy Markdown
Contributor Author

See test fails: https://ci.eclipse.org/jdt/job/eclipse.jdt.ui-github/job/PR-3259/6/testReport/

Let me check them, thanks.

All the failures are fixed. Once you let me know your preference in 1 other comment - i can go ahead with that and we can merge this issue once done.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

Preview color handling and source-range validation need correction to prevent unreadable content and selection errors.

3 open findings
3 resolved since last review

🧠 Review effort: Balanced

@deepika-u
deepika-u force-pushed the preview_update_open_type branch from 05ae7bb to 0bf301d Compare October 16, 2026 12:17
@deepika-u

deepika-u commented Oct 16, 2026 •

Copy link
Copy Markdown
Contributor Author

@iloveeclipse : Thanks for your time, 2 new comments are fixed. Waiting for your reply to fix 1 last comment to be implemented.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

Syntax-style preservation needs correction, and the previously reported UI-thread source-loading concern remains unresolved.

2 open issues
2 resolved since last review

Review effort: Balanced

@deepika-u
deepika-u force-pushed the preview_update_open_type branch from 0bf301d to 55f8c4e Compare October 17, 2026 13:31
@deepika-u
deepika-u force-pushed the preview_update_open_type branch from 01d7624 to cdf814a Compare October 23, 2026 04:45

@SougandhS SougandhS left a comment

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.

LGTM, thanks @deepika-u.

Screen.Recording.2026-10-23.at.10.55.55.AM.mov

With ambiguous results, users can now find the exact type from the preview instead of opening several editors.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🔵 Needs a closer look

The shared-dialog layout and asynchronous SWT lifecycle changes warrant Eclipse UI test execution and final human review.

No open issues 🎉

Review effort: Balanced

@deepika-u

Copy link
Copy Markdown
Contributor Author

No functional issue raised. Layout and lifecycle re-checked, CI tests are passing.

@iloveeclipse : is it ready to be merged now?

@deepika-u
deepika-u force-pushed the preview_update_open_type branch from cdf814a to f57c08a Compare October 27, 2026 10:28

@iloveeclipse iloveeclipse left a comment

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.

Can you please fix comments, for example via this patch:

diff --git a/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/dialogs/FilteredTypesSelectionDialogTests.java b/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/dialogs/FilteredTypesSelectionDialogTests.java
index 868aeac..37b9659 100644
--- a/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/dialogs/FilteredTypesSelectionDialogTests.java
+++ b/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/dialogs/FilteredTypesSelectionDialogTests.java
@@ -44,2 +44,3 @@
 import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.jobs.Job;
 
@@ -220,3 +221,3 @@
 		// result is queued with asyncExec, but not yet delivered.
-		Thread.sleep(500);
+		joinPreviewJob();
 
@@ -250,3 +251,3 @@
 		// Block the UI thread without dispatching events, so the job's result is queued but not delivered.
-		Thread.sleep(500);
+		joinPreviewJob();
 		openTypeDialog.close();
@@ -280,3 +281,3 @@
 		// Block the UI thread without dispatching events, so the job's result is queued but not delivered.
-		Thread.sleep(500);
+		joinPreviewJob();
 
@@ -426,2 +427,17 @@
 	/**
+	 * Waits until the preview job has finished, deliberately <b>without</b> running the event
+	 * loop. The job posts its result with <code>asyncExec</code> before it finishes, so afterwards
+	 * the result is queued in the display but not yet delivered, which is the state these tests
+	 * need. Blocking the UI thread is safe because the job never waits for the UI thread. The wait
+	 * is bounded, so that a stuck job fails the test instead of hanging it.
+	 */
+	private static void joinPreviewJob() throws InterruptedException {
+		long deadline = System.currentTimeMillis() + 5000;
+		while (Job.getJobManager().find(OpenTypeSelectionDialog.PREVIEW_JOB_FAMILY).length > 0) {
+			assertTrue(System.currentTimeMillis() < deadline, "Preview job did not finish in time");
+			Thread.sleep(10);
+		}
+	}
+
+	/**
 	 * Runs the event loop until the condition holds or a timeout elapsed.
diff --git a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/dialogs/OpenTypeSelectionDialog.java b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/dialogs/OpenTypeSelectionDialog.java
index 7cd1254..e78d0e2 100644
--- a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/dialogs/OpenTypeSelectionDialog.java
+++ b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/dialogs/OpenTypeSelectionDialog.java
@@ -72,3 +72,2 @@
 import org.eclipse.jdt.ui.text.IJavaPartitions;
-import org.eclipse.jdt.ui.text.JavaSourceViewerConfiguration;
 import org.eclipse.jdt.ui.text.JavaTextTools;
@@ -82,2 +81,3 @@
 import org.eclipse.jdt.internal.ui.text.FastJavaPartitioner;
+import org.eclipse.jdt.internal.ui.text.SimpleJavaSourceViewerConfiguration;
 import org.eclipse.jdt.internal.ui.util.SWTUtil;
@@ -102,2 +102,7 @@
 
+	/**
+	 * Job family of the preview jobs, for example to join them in tests.
+	 */
+	public static final Object PREVIEW_JOB_FAMILY= new Object();
+
 	/** The partition types of the Java partitioner, the same as the ones used by the Java editor. */
@@ -278,3 +283,5 @@
 		if (tools != null) {
-			fPreviewViewer.configure(new JavaSourceViewerConfiguration(tools.getColorManager(), store, null, IJavaPartitions.JAVA_PARTITIONING));
+			// The simple configuration, as used by other read-only Java previews: no hovers, hyperlinks,
+			// or information presenters, which require an editor.
+			fPreviewViewer.configure(new SimpleJavaSourceViewerConfiguration(tools.getColorManager(), store, null, IJavaPartitions.JAVA_PARTITIONING, false));
 		}
@@ -367,2 +374,7 @@
 			}
+
+			@Override
+			public boolean belongsTo(Object family) {
+				return family == PREVIEW_JOB_FAMILY;
+			}
 		};

@deepika-u

Copy link
Copy Markdown
Contributor Author

Thanks for your time, let me check on them.

@deepika-u
deepika-u force-pushed the preview_update_open_type branch 2 times, most recently from 66a6d56 to 8b84809 Compare October 28, 2026 06:31
@deepika-u

Copy link
Copy Markdown
Contributor Author

All four comments are addressed in the updated commit, you may take a look when you get some time please? Will monitor for tests to complete meanwhile.

@deepika-u

Copy link
Copy Markdown
Contributor Author

@iloveeclipse : Tests have passed. When you get some time, you may check please.

@deepika-u

Copy link
Copy Markdown
Contributor Author

Can you please fix comments, for example via this patch:

This is also fixed.

@deepika-u
deepika-u force-pushed the preview_update_open_type branch from 8b84809 to 614a614 Compare November 3, 2026 05:58
@deepika-u

Copy link
Copy Markdown
Contributor Author

@iloveeclipse
Are we good to go on this pr now?

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

The null-project factory incorrectly uses editor state instead of workspace settings, which can disable text-block partitioning and access workbench state on the caller’s thread.

1 open issue

Review effort: Balanced

@deepika-u
deepika-u force-pushed the preview_update_open_type branch from 614a614 to 0a61d1d Compare November 10, 2026 05:20
@deepika-u

Copy link
Copy Markdown
Contributor Author

@iloveeclipse
Do you have any further comments on this? Can this be merged now?

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟢 Approval recommended

No active review issues remain for the Open Type source-preview change.

No open issues 🎉

1 resolved since last review

Review effort: Balanced

@deepika-u

Copy link
Copy Markdown
Contributor Author

@jjohnstn
If possible can you take a look at this work item if time permits for M3 please?

@deepika-u
deepika-u force-pushed the preview_update_open_type branch from 0a61d1d to 5735d13 Compare November 16, 2026 05:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants