fix(lsp): resolve JDTLS root to topmost pom.xml in Java Maven multi-module projects#28761
Open
areyouok wants to merge 1 commit into
Open
fix(lsp): resolve JDTLS root to topmost pom.xml in Java Maven multi-module projects#28761areyouok wants to merge 1 commit into
areyouok wants to merge 1 commit into
Conversation
Previously JDTLS.root() found the nearest pom.xml, causing each Maven module to spawn its own jdtls instance. Now uses Filesystem.findUp with rootFirst to find the topmost pom.xml, so all modules share one instance. - Add StrictNearestRoot helper (returns undefined instead of ctx.directory) - Preserve Gradle and Eclipse project detection behavior - Add 12 unit tests for JDTLS root resolution
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Issue for this PR
Fixes #28760
Type of change
What does this PR do?
The existing JDTLS root detection (introduced in #14192) correctly handles Gradle monorepos by walking up to
settings.gradle, but for Maven projects it still returns the nearestpom.xmldirectory. This means each Maven submodule spawns its own JDTLS process.This PR adds Maven multi-module awareness: the root function now walks up the
pom.xmlchain and checks whether each parent pom declares the child directory as a<module>. If the parent-child relationship is confirmed, it keeps going up until reaching the true topmost parent pom.Key changes in
packages/opencode/src/lsp/server.ts:StrictNearestRoothelper: likeNearestRootbut returnsundefinedwhen no marker is found (instead of defaulting to the instance directory). Used for Gradle/Eclipse paths to avoid false positives.isModuleOf(pomContent, modulePath): parses<modules>blocks from pom.xml content, strips XML comments, normalizes paths (handles./prefix, trailing/), and checks if a directory is declared as a module.Filesystem.findUp("pom.xml", ...)to collect all ancestor poms, then walks from innermost to outermost verifying<module>links. Stops when the chain breaks (parent does not declare child as module).How did you verify your code works?
Added 16 unit tests in
packages/opencode/test/lsp/jdtls-root.test.tscovering:<module>chain<module>chain → stops at the independent module<module>with./prefix and trailing/normalization<module>paths (e.g.tools/sample)<module>declarations are ignored<module>declarations handled correctlyAll tests pass, typecheck clean.
Screenshots / recordings
N/A (LSP behavior change, no UI impact)
Checklist