Skip to content

Add searchParticipant extension point for javaDerivedSource indexing#4938

Open
arcivanov wants to merge 1 commit intoeclipse-jdt:masterfrom
arcivanov:search-participant-extension-point
Open

Add searchParticipant extension point for javaDerivedSource indexing#4938
arcivanov wants to merge 1 commit intoeclipse-jdt:masterfrom
arcivanov:search-participant-extension-point

Conversation

@arcivanov
Copy link
Copy Markdown

@arcivanov arcivanov commented Mar 16, 2026

Summary

  • New org.eclipse.jdt.core.searchParticipant extension point allowing external OSGi bundles to register SearchParticipant implementations for non-Java source files (e.g. .kt, .scala, .groovy) that are registered under the javaDerivedSource content type
  • SearchParticipantRegistry eagerly loads contributed participants by file extension from the extension registry, and listens for dynamic bundle load/unload via IRegistryEventListener to reload automatically
  • IndexManager.addDerivedSource() routes derived files to their registered participant instead of the default JavaSearchParticipant
  • IndexAllProject and AddFolderToIndex discover javaDerivedSource files alongside Java files in source folders and index them via addDerivedSource()
  • DeltaProcessor handles add/change/remove deltas for derived source files, mirroring the compilation unit indexing pattern
  • SearchEngine.getSearchParticipants() new API returning the default participant plus all contributed participants
  • SearchParticipant.locateCallees() new default method enabling contributed participants to report outgoing call sites for non-Java members, used by the call hierarchy engine (in org.eclipse.jdt.core.manipulation) when Java AST-based callee analysis is not available
  • OrPattern.getPatterns() new public accessor so contributed SearchParticipant implementations can decompose OrPattern (e.g. REFERENCES + DECLARATIONS combined by ReferencesHandler when includeDeclaration=true) for correct pattern-type dispatch in locateMatches()
  • SearchParticipantRegistry.getLanguageId() new API returning the LSP language identifier for a given file extension, from the optional languageId attribute on the extension point registration; enables language server handlers to tag hover content with the correct language (e.g. "kotlin" instead of "java")
  • Fully backwards-compatible: when no participants are registered, behavior is identical to before

Companion PRs

Test plan

  • 12 new tests in DerivedSourceSearchParticipantTests covering:
    • Registry loading, singleton caching, reset/reload, unknown extension handling
    • Indexing triggered for derived source files (single, multiple, sub-package)
    • Java files not routed to participant
    • Deletion of derived source files removes index entries
    • SearchEngine.getSearchParticipants() returns default + contributed participants

@arcivanov arcivanov force-pushed the search-participant-extension-point branch 2 times, most recently from 1692a79 to f0228b3 Compare March 16, 2026 18:09
@iloveeclipse iloveeclipse requested a review from Copilot March 16, 2026 18:35
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

This PR adds a new org.eclipse.jdt.core.searchParticipant extension point so external bundles can contribute SearchParticipant implementations for indexing/searching non-Java files registered under the javaDerivedSource content type (e.g., Kotlin/Scala/Groovy), and wires derived-source indexing into JDT Core’s indexing and delta processing pipelines.

Changes:

  • Introduces SearchParticipantRegistry to load/search participants by file extension and react to registry changes.
  • Routes javaDerivedSource files through contributed participants during initial indexing, folder indexing, and resource delta processing.
  • Adds new public API SearchEngine.getSearchParticipants() (default + contributed) and adds tests validating registry behavior and derived-source indexing.

Reviewed changes

Copilot reviewed 17 out of 17 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
org.eclipse.jdt.core/search/org/eclipse/jdt/internal/core/search/indexing/SearchParticipantRegistry.java New registry for discovering/caching participants and mapping them by extension.
org.eclipse.jdt.core/search/org/eclipse/jdt/internal/core/search/indexing/IndexManager.java Adds addDerivedSource() to schedule derived-source indexing via a contributed participant.
org.eclipse.jdt.core/search/org/eclipse/jdt/internal/core/search/indexing/IndexAllProject.java Extends full-project indexing to discover/index derived-source files in source folders.
org.eclipse.jdt.core/search/org/eclipse/jdt/internal/core/search/indexing/AddFolderToIndex.java Extends folder indexing to include derived-source files with registered participants.
org.eclipse.jdt.core/search/org/eclipse/jdt/internal/core/search/BasicSearchEngine.java Adds internal helper returning default + contributed participants.
org.eclipse.jdt.core/search/org/eclipse/jdt/core/search/SearchEngine.java New public API getSearchParticipants() exposing default + contributed participants.
org.eclipse.jdt.core/schema/searchParticipant.exsd Defines the new searchParticipant extension point schema.
org.eclipse.jdt.core/pom.xml Bumps bundle Maven version to 3.46.0-SNAPSHOT.
org.eclipse.jdt.core/plugin.xml Registers the new searchParticipant extension point.
org.eclipse.jdt.core/plugin.properties Adds translatable name for the new extension point.
org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/DeltaProcessor.java Handles add/change/remove deltas for derived-source files (mirrors CU behavior).
org.eclipse.jdt.core/META-INF/MANIFEST.MF Bumps OSGi bundle version to 3.46.0.qualifier.
org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/TestDerivedSourceSearchParticipant.java Test participant implementation used by indexing tests.
org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/TestDerivedSearchDocument.java Test SearchDocument for derived-source files (reads workspace content).
org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/DerivedSourceSearchParticipantTests.java New tests covering registry behavior and derived-source indexing pipeline.
org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/AllJavaModelTests.java Registers the new derived-source participant test suite.
org.eclipse.jdt.core.tests.model/plugin.xml Contributes a test javaDerivedSource file association + searchParticipant extension.

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

You can also share your feedback on Copilot code review. Take the survey.

@arcivanov arcivanov force-pushed the search-participant-extension-point branch from f0228b3 to d90fdff Compare March 16, 2026 19:28
@arcivanov
Copy link
Copy Markdown
Author

An integration demo (that is stubbed out but won't be for long is available here): https://github.com/karellen/karellen-jdtls-kotlin

@arcivanov arcivanov force-pushed the search-participant-extension-point branch from d90fdff to e08990e Compare March 18, 2026 17:55
arcivanov added a commit to arcivanov/eclipse.jdt.ui that referenced this pull request Mar 21, 2026
Incoming calls (CallerMethodWrapper):

Replace hardcoded `new SearchParticipant[] { getDefaultSearchParticipant() }`
with `SearchEngine.getSearchParticipants()` so that incoming call searches
include results from contributed search participants registered via the
`org.eclipse.jdt.core.searchParticipant` extension point.

Outgoing calls (CalleeMethodWrapper):

When the member has no Java AST (i.e. `getCompilationUnitNode()` returns
null), fall back to `SearchParticipant.locateCallees()` on all contributed
participants. Each participant can report call sites within the member's
body. Returned callees are resolved to full declarations via
`resolveCallee()`, which handles METHOD, FIELD, and TYPE element types.

Non-standard ICompilationUnit handling (CallHierarchyCore):

Catch `ClassCastException` in `getCompilationUnitNode()` for non-standard
`ICompilationUnit` implementations (e.g. from contributed search
participants) that do not implement the internal compiler interface
(`org.eclipse.jdt.internal.compiler.env.ICompilationUnit`) required by
`ASTParser.createAST()`. Returns null to fall through to the participant
path.

Dependency:

Bump `org.eclipse.jdt.core` dependency to `[3.46.0,4.0.0)` for the
`SearchEngine.getSearchParticipants()` and `SearchParticipant.locateCallees()`
APIs added in eclipse-jdt/eclipse.jdt.core#4938.

Depends on eclipse-jdt/eclipse.jdt.core#4938.
Companion to eclipse-jdtls/eclipse.jdt.ls#3732.
@arcivanov arcivanov force-pushed the search-participant-extension-point branch 6 times, most recently from 57b2ef4 to 33b60c0 Compare March 28, 2026 04:55
Extend JDT Core's indexing pipeline to discover and index files registered
under the javaDerivedSource content type (e.g. .kt, .scala, .groovy) via
contributed SearchParticipant implementations.

Changes:
- New org.eclipse.jdt.core.searchParticipant extension point with schema
- SearchParticipantRegistry: loads contributed participants by file extension
  from the extension registry, listens for dynamic bundle load/unload via
  IRegistryEventListener to invalidate cached state automatically
- IndexManager.addDerivedSource(): routes derived files to their registered
  participant instead of the default JavaSearchParticipant
- IndexAllProject: discovers javaDerivedSource files alongside Java files
  in source folders and indexes them via addDerivedSource()
- AddFolderToIndex: same derived file discovery for folder additions
- DeltaProcessor: handles add/change/remove deltas for derived source files
- SearchEngine.getSearchParticipants(): new API returning the default
  participant plus all contributed participants
- SearchParticipant.locateCallees(): new default method enabling contributed
  participants to report outgoing call sites for non-Java members, used by
  the call hierarchy engine when Java AST-based callee analysis is not
  available
- OrPattern.getPatterns(): new public accessor so contributed participants
  can decompose OrPattern (e.g. REFERENCES + DECLARATIONS) for correct
  pattern-type dispatch in locateMatches()
- SearchParticipantRegistry.getLanguageId(): new API returning the LSP
  language identifier for a given file extension, from the optional
  languageId attribute on the extension point registration
- Fully backwards-compatible: no registered participants = identical behavior
@arcivanov arcivanov force-pushed the search-participant-extension-point branch from 33b60c0 to 8b7f31e Compare March 29, 2026 06:33
arcivanov added a commit to arcivanov/eclipse.jdt.ui that referenced this pull request Mar 30, 2026
Incoming calls (CallerMethodWrapper):

Replace hardcoded `new SearchParticipant[] { getDefaultSearchParticipant() }`
with `SearchEngine.getSearchParticipants()` so that incoming call searches
include results from contributed search participants registered via the
`org.eclipse.jdt.core.searchParticipant` extension point. For contributed
(non-Java) elements, accept A_INACCURATE matches since JDT's MatchLocator
cannot resolve type bindings for types not compiled by ECJ.

Outgoing calls (CalleeMethodWrapper):

When the member has no Java AST (i.e. `getCompilationUnitNode()` returns
null), fall back to `SearchParticipant.locateCallees()` on all contributed
participants. Each participant can report call sites within the member's
body. Returned callees are resolved to full declarations via
`resolveCallee()`, which handles METHOD, FIELD, and TYPE element types.

Outgoing calls from Java to non-Java targets (CalleeAnalyzerVisitor):

When a Java method invocation has a null ECJ binding (receiver type is from
a contributed language, not compiled by ECJ), fall back to resolveViaSearch()
which uses SearchEngine.getSearchParticipants() to find METHOD DECLARATIONS
matching the method name across all contributed participants.

Non-standard ICompilationUnit handling (CallHierarchyCore):

Guard getCompilationUnitNode() with isJavaLikeFileName() check so non-Java
source files (e.g. .kt) are not parsed as Java AST, which would produce
broken results and false positives in outgoing call analysis.

Dependency:

Bump `org.eclipse.jdt.core` dependency to `[3.46.0,4.0.0)` for the
`SearchEngine.getSearchParticipants()` and `SearchParticipant.locateCallees()`
APIs added in eclipse-jdt/eclipse.jdt.core#4938.

Depends on eclipse-jdt/eclipse.jdt.core#4938.
Companion to eclipse-jdtls/eclipse.jdt.ls#3732.
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