Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 24 additions & 1 deletion packages/opencode/src/lsp/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1129,7 +1129,30 @@ export namespace LSPServer {

export const JDTLS: Info = {
id: "jdtls",
root: NearestRoot(["pom.xml", "build.gradle", "build.gradle.kts", ".project", ".classpath"]),
root: async (file) => {
// Without exclusions, NearestRoot defaults to instance directory so we can't
// distinguish between a) no project found and b) project found at instance dir.
// So we can't choose the root from (potential) monorepo markers first.
// Look for potential subproject markers first while excluding potential monorepo markers.
const settingsMarkers = ["settings.gradle", "settings.gradle.kts"]
const gradleMarkers = ["gradlew", "gradlew.bat"]
const exclusionsForMonorepos = gradleMarkers.concat(settingsMarkers)

const [projectRoot, wrapperRoot, settingsRoot] = await Promise.all([
NearestRoot(
["pom.xml", "build.gradle", "build.gradle.kts", ".project", ".classpath"],
exclusionsForMonorepos,
)(file),
NearestRoot(gradleMarkers, settingsMarkers)(file),
NearestRoot(settingsMarkers)(file),
])

// If projectRoot is undefined we know we are in a monorepo or no project at all.
// So can safely fall through to the other roots
if (projectRoot) return projectRoot
if (wrapperRoot) return wrapperRoot
if (settingsRoot) return settingsRoot
},
extensions: [".java"],
async spawn(root) {
const java = Bun.which("java")
Expand Down
Loading