fix(java): resolve application classpaths independently of working directory (#493)

Run and Debug passed the configuration working directory to java_resolve_launch as the module, so changing the working directory also changed which jdtls project supplied the classpath and failed with "references non-existing project". Java application configurations now store their module at detection and creation, keep it when the working directory changes, and clear it when the main class changes. Older saved configurations resolve it from the main class source file. The Kotlin debugger check also uses the module directory.

Fixes #435
This commit is contained in:
l0ng-ai authored and GitHub committed 2026-10-31 00:59:22 +08:00
1 parent 2754cf327f
commit 0660f3c020
17 files changed
+265 -30

No files matched your search

+5 -3
View File
@@ -20,6 +20,7 @@ import {
joinJavaArgs,
parseJavaArgs,
resolveJavaCommand,
resolveJavaModule,
} from "@/platform/javaLaunch";
import { notifications } from "@/workbench/contributions";
@@ -85,11 +86,12 @@ export async function javaLaunchConfig(
root: string,
preparation?: { request: RequestId; signal: AbortSignal },
): Promise<LaunchConfig> {
const module = rc.cwd ?? "";
const cwd = rc.cwd ? join(root, rc.cwd) : root;
const parsed = parseJavaArgs(rc.args);
if (!parsed.mainClass) throw new Error(`No main class in '${rc.name}'`);
preparation?.signal.throwIfAborted();
const module = await resolveJavaModule(rc);
preparation?.signal.throwIfAborted();
const info = await call(
commands.javaResolveLaunch(module, parsed.classpath === "test", true, preparation?.request ?? nextRequestId()),
);
@@ -103,7 +105,7 @@ export async function javaLaunchConfig(
body: formatCompileErrors(info).trimEnd(),
});
const resolved = resolveJavaCommand(rc, info);
const kotlin = rc.debugAdapter === KOTLIN_ADAPTER || (await moduleHasKotlinSources(cwd));
const kotlin = rc.debugAdapter === KOTLIN_ADAPTER || (await moduleHasKotlinSources(join(root, module)));
preparation?.signal.throwIfAborted();
const classPaths = parsed.explicitClasspath ? parsed.explicitClasspath.split(/[:;]/) : info.classPaths;
if (kotlin) {
@@ -116,7 +118,7 @@ export async function javaLaunchConfig(
cwd,
env: { ...rc.env },
extraJson: JSON.stringify({
projectRoot: cwd,
projectRoot: join(root, module),
mainClass: parsed.mainClass,
classPaths,
modulePaths: info.modulePaths,