Use SearchEngine.getSearchParticipants() for non-Java language search#3732
Use SearchEngine.getSearchParticipants() for non-Java language search#3732arcivanov wants to merge 1 commit into
Conversation
|
Can one of the admins verify this patch? |
1803d94 to
2af1816
Compare
|
add to whitelist |
|
Thanks for the contribution @arcivanov. I'm not too familiar with JDT's Index API and I have a bunch of questions:
|
|
@jjohnstn could you please take a look? |
Will do. |
|
@fbricon Regarding JDT extensions, there is an existing extension in JDT, but it is in JDT UI and not accessible to jdt.ls. |
|
So, @fbricon you're quite right, this only covered the read path, not the indexing one. This PR will be transformed (it's still needed even further trimmed down) but the extension point is moving to JDT Core proper. Additionally I'm finishing up a functional prototype of how this PR and JDT Core PR (incoming) will work together to facilitate hybrid language project LSPs for Java ecosystem. |
2af1816 to
45c547c
Compare
|
An integration demo (that is stubbed out but won't be for long is available here): https://github.com/karellen/karellen-jdtls-kotlin |
@fbricon you requested a use prototype |
|
@arcivanov your readme mentions using kt as an isJavaDerivedFileName match, beware, that will introduce JDT compilation errors in kt files, as JDT will consider they're valid java content. See #3666 (comment) |
|
@fbricon thank you noted I'll investigate it and get back to you. There is another patch that will be required into the "manipulation" to get call-hierarchy to support inter-language references as well. |
@fbricon I don't think so. As I see it right now (as far as I progressed in the prototype) the builder exclusively uses The areas where
None of these trigger ECJ compilation. Your concern is based on the Does it make sense or I'm missing something? |
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.
45c547c to
3a3a770
Compare
Fair enough. Now do we still need this PR if you're making changes in upstream JDT Core? It's still unclear to me how indexing is supposed to be triggerd |
|
Yes, this is a part of 3 PRs. Give me another few days please I'm literally testing the end-to-end the Kotlin plugin for JDTLS right now: https://github.com/karellen/karellen-jdtls-kotlin/ @fbricon also in case you missed it eclipse-jdt/eclipse.jdt.core#4938 and eclipse-jdt/eclipse.jdt.ui#2881 |
c6dfc6f to
0e2fa76
Compare
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.
7a1496b to
4827d80
Compare
474223d to
9ab78e6
Compare
9ab78e6 to
276a7f1
Compare
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.
276a7f1 to
ab95b2e
Compare
SearchEngine.search() already supports multiple SearchParticipant instances, but all call sites in jdtls hardcode a single-element array containing only the default Java participant. This prevents non-Java languages from contributing index entries for cross-language call hierarchy, find references, type hierarchy, workspace symbol, and implementation search. This change updates all four search call sites (ReferencesHandler, CodeLensHandler, ImplementationCollector, HoverInfoProvider) to use the new JDT Core API SearchEngine.getSearchParticipants(), which returns the default participant plus any participants contributed via the org.eclipse.jdt.core.searchParticipant extension point. WorkspaceSymbolHandler: supplement searchAllTypeNames() results with a search() call through contributed participants. searchAllTypeNames() only queries the default (Java) participant's indexes, making non-Java types invisible to workspace/symbol queries. The supplementary search creates a TYPE DECLARATIONS pattern with the same match rule (camelcase or wildcard) and runs it through contributed participants only, converting SearchMatch results to SymbolInformation with proper location, container, and kind. ReferencesHandler: accept A_INACCURATE matches for contributed (non-Java) elements, since JDT's MatchLocator cannot resolve type bindings for types not compiled by ECJ. TypeHierarchyHandler: supplement JDT's native type hierarchy with contributed search participants. For subtypes, run a supplementary IMPLEMENTORS search via contributed participants to discover non-Java types that extend or implement the target type. For supertypes of contributed types, resolve declared supertype names via type declaration search since JDT's newSupertypeHierarchy() does not work for non-Java IType implementations. Re-resolve contributed elements via codeSelect when JavaCore.create() cannot reconstitute them from handle identifiers. HoverInfoProvider: use SearchParticipantRegistry.getLanguageId() to tag hover MarkedString content with the correct LSP language identifier (e.g. "kotlin" instead of "java") for elements from contributed search participants. JDTUtils.resolveCompilationUnit(IFile) now falls back to querying contributed SearchParticipant.getCompilationUnit(IFile) for non-Java source files, enabling document symbols, hover, go-to-definition, call hierarchy, and code lenses for derived source languages (e.g., Kotlin .kt files). JDTUtils.findElementsAtSelection() now falls back to searching contributed participants when Java's codeSelect() returns empty. This enables go-to-definition and hover for types and methods provided by non-Java languages (e.g., Kotlin facade classes and property accessors) from Java source files. NavigateToDefinitionHandler.computeBreakContinue() now guarded with isJavaLikeFileName check to prevent ClassCastException when ASTParser attempts to cast a contributed ICompilationUnit (e.g. KotlinCompilationUnit) to ECJ's internal ICompilationUnit interface. BaseJDTLanguageServer.computeAsync() and JDTLanguageServer .computeAsyncWithClientProgress() now log unhandled exceptions via whenComplete() instead of silently swallowing them, making failures in LSP request handlers visible in the server log. When no extensions are registered, behavior is identical to before (only the default Java participant is used), ensuring zero regression risk.
ab95b2e to
de9d34b
Compare
## Summary - `matchesTypeName()`, `matchesTypeAliasName()`, and `locateFacadeTypeMatch()` now use `TypeDeclarationPattern.matchesName()` instead of `equalsIgnoreCase`, supporting all JDT match rules (exact, prefix, camelcase, wildcard) - Adds `WorkspaceSymbolSearchTest` (8 tests) validating workspace/symbol search for Kotlin types ## Motivation Workspace/symbol queries (`workspace/symbol` LSP method) use `R_CAMELCASE_MATCH` and `R_PATTERN_MATCH`. The index correctly selected documents containing matching Kotlin types, but `locateMatches()` rejected all declarations because the name comparison used `equalsIgnoreCase` — only exact matches passed. `TypeDeclarationPattern.matchesName()` is the same method JDT Core uses in `matchesDecodedKey()` during index queries. It respects the pattern's match rule, handling camelcase (e.g., "IPS" → `InventoryPopulationService`), wildcards (e.g., `*Population*`), prefix, and exact matching. Companion fix: [eclipse.jdt.ls#3732](eclipse-jdtls/eclipse.jdt.ls#3732) supplements `WorkspaceSymbolHandler.searchAllTypeNames()` with a `search()` call through contributed participants, since `searchAllTypeNames` only queries the default Java participant's indexes. ## Test plan - [x] `testSearchAllTypeNamesDoesNotFindKotlinTypes` — confirms `searchAllTypeNames` gap - [x] `testSearchAllTypeNamesCamelCaseDoesNotFindKotlinTypes` — confirms camelcase gap - [x] `testSearchWithParticipantsFindsKotlinTypeExact` — exact match via `search()` - [x] `testSearchWithParticipantsFindsKotlinTypeCamelCase` — "IPS" finds `InventoryPopulationService` - [x] `testSearchWithParticipantsFindsKotlinTypePatternMatch` — `*Population*` finds type - [x] `testSearchWithParticipantsFindsMultipleKotlinTypes` — `Inventory*Service` finds 2 types - [x] `testSearchWithParticipantsFindsKotlinInterface` — "IR" finds interface + implementation - [x] `testSearchWithParticipantsFindsKotlinTypeWithPackageQualifier` — sub-package types found - [x] Full suite: 362 tests, 0 failures - [x] E2E verified against real Kotlin project (workspace/symbol for `InventoryPopulationService` and camelcase `IPS`)
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.derivedSourceSearchParticipant` 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 `DerivedSourceSearchParticipant.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
`DerivedSourceSearchParticipant.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.
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.derivedSourceSearchParticipant` 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 `DerivedSourceSearchParticipant.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
`DerivedSourceSearchParticipant.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.
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.derivedSourceSearchParticipant` 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 `DerivedSourceSearchParticipant.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
`DerivedSourceSearchParticipant.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.
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.derivedSourceSearchParticipant` 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 `DerivedSourceSearchParticipant.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
`DerivedSourceSearchParticipant.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.
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.derivedSourceSearchParticipant` 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 `DerivedSourceSearchParticipant.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
`DerivedSourceSearchParticipant.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.
* Use contributed search participants in call hierarchy
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.derivedSourceSearchParticipant` 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 `DerivedSourceSearchParticipant.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
`DerivedSourceSearchParticipant.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.
Summary
ReferencesHandler,CodeLensHandler,ImplementationCollector,HoverInfoProvider,WorkspaceSymbolHandler) to useSearchEngine.getSearchParticipants()instead of hardcoding only the default Java participantWorkspaceSymbolHandler.searchAllTypeNames()andsearchAllMethodNames()withsearch()calls through contributed participants — both APIs only query the default Java participant's indexes, making non-Java types and methods invisible to workspace/symbol queriesJDTUtils.resolveCompilationUnit(IFile)to query contributedDerivedSourceSearchParticipant.getCompilationUnit(IFile)for non-Java source filesJDTUtils.findElementsAtSelection()to search contributed participants when Java'scodeSelect()returns empty — enables go-to-definition and hover for types/methods provided by non-Java languages (e.g., Kotlin facade classes and property accessors) from Java source filesReferencesHandlerwhen the search target itself is a non-Java element (contributed participants may not provide full accuracy information)DerivedSourceSearchParticipantRegistryinstead of hardcoding"java"NavigateToDefinitionHandler.computeBreakContinue()withisJavaLikeFileNameto preventClassCastExceptionwhen ECJ'sASTParserattempts to parse a contributedICompilationUnit(e.g., Kotlin)BaseJDTLanguageServer.computeAsync()andJDTLanguageServer.computeAsyncWithClientProgress()instead of silently swallowing themMotivation
SearchEngine.search()already supports multipleSearchParticipantinstances, but all call sites in jdtls hardcode a single-element array containing only the default Java participant. This prevents non-Java languages from contributing search results for cross-language features.With the new
org.eclipse.jdt.core.derivedSourceSearchParticipantextension point (eclipse-jdt/eclipse.jdt.core#4938), languages like Kotlin can register search participants that index.ktfiles and contribute to JDT's search infrastructure. This PR wires jdtls to use those contributed participants.Changes
1. Search call sites →
getSearchParticipants()ReferencesHandler,CodeLensHandler,ImplementationCollector, andHoverInfoProvider.isResolved()now callSearchEngine.getSearchParticipants()which returns[default, ...contributed].2.
WorkspaceSymbolHandler— contributed participant supplementationsearchAllTypeNames()andsearchAllMethodNames()only query indexes through the default Java search participant (seeBasicSearchEngineline 1987:getDefaultSearchParticipant(), // Java search only). Non-Java types and methods indexed by contributed participants are invisible to these APIs.After both the existing
searchAllTypeNamesandsearchAllMethodNamescalls, supplementarysearch()calls are now run through contributed participants only (excluding the default). They create TYPE/METHOD DECLARATIONS patterns with the same match rule (camelcase or wildcard) used by the workspace symbol query, and convertSearchMatchresults toSymbolInformationwith proper location, container name, and symbol kind.3.
ReferencesHandler— accept inaccurate matches for non-Java elementsWhen the search target is a non-Java element (resolved via a contributed participant),
ReferencesHandlernow accepts inaccurate search matches. Contributed participants may not provide full accuracy information, and filtering these out would silently drop valid cross-language references.4.
resolveCompilationUnit(IFile)fallbackWhen a non-Java file (e.g.,
.kt) is opened, the method now queries contributed participants viaDerivedSourceSearchParticipant.getCompilationUnit(IFile)as a fallback after the standard Java resolution path. This enables document symbols, hover, go-to-definition, call hierarchy, and code lenses for derived source languages.5.
findElementsAtSelection()search participant fallbackWhen Java's
codeSelect()returns empty (which happens for types and methods provided by non-Java languages), a newresolveViaSearchParticipants()helper extracts the identifier at the cursor and searches contributed participants for matching TYPE or METHOD declarations. This fixes Java→Kotlin navigation gaps (go-to-definition and hover on Kotlin facade classes and property accessors from Java files).6. Type hierarchy support for contributed participants
TypeHierarchyHandlercannot reconstitute aIJavaElementfrom its handle identifier (which happens for contributed elements), it falls back tocodeSelect()at the element's source position to re-resolve itresolveContributedSupertypes): For non-Java types, JDT'snewSupertypeHierarchy()does not work. Instead, the superclass and superinterface names are resolved viaSearchEnginesearch across all participants, building the hierarchy items from the resolvedITypeinstancessupplementWithContributedSubtypes): After JDT computes subtypes via its own hierarchy, a secondary IMPLEMENTORS search is run against contributed participants only (excluding the default Java participant) to discover additional subtypes from non-Java languages7. Correct language ID for hover MarkedStrings
HoverInfoProvider.getLanguageId()queriesDerivedSourceSearchParticipantRegistryfor the file extension and its associated LSP language ID, falling back to"java"for standard Java elements. This ensures hover popups render syntax highlighting for the correct language.8.
NavigateToDefinitionHandler— guard ECJ AST parsing for non-Java filescomputeBreakContinue()usesASTParser.createAST()to parse break/continue statements, which internally casts theICompilationUnitto ECJ'sorg.eclipse.jdt.internal.compiler.env.ICompilationUnit. Contributed compilation units (e.g.,KotlinCompilationUnit) do not implement this internal interface, causing aClassCastException. AddedJavaCore.isJavaLikeFileName()guard to skip break/continue resolution for non-Java files.9. Log unhandled exceptions in
computeAsync()BaseJDTLanguageServer.computeAsync()andJDTLanguageServer.computeAsyncWithClientProgress()now attach awhenComplete()handler that logs unhandled exceptions instead of silently swallowing them. This makes failures in LSP request handlers visible in the server log for diagnosis.Backward Compatibility
When no search participant extensions are registered,
getSearchParticipants()returns only the default Java participant, and the fallback paths only run when standard JDT resolution already returned empty. Behavior is identical to before.Test plan
DerivedSourceSearchParticipantsTest(14 tests) passesNumberExtensionsKt)getBIG_DECIMAL_HUNDRED)