mirror of
https://github.com/l0ng-ai/openidea.git
synced 2026-11-24 16:04:21 +00:00
* fix(java): Run jdtls with a Lombok agent and show build errors at launch jdtls compiles with ECJ, which only generates Lombok members when the server JVM runs -javaagent:lombok.jar. Nothing put it there, so @Data / @Setter classes lost their accessors and Run launched stale classes with "Unresolved compilation problem" stubs and no explanation. - Projects whose build files mention Lombok get the newest jar: the IDE-managed one (new "Lombok (jdtls agent)" tool, latest release from Maven Central), else ~/.m2 (incl. settings.xml localRepository) or the Gradle cache. Each agent gets its own jdtls workspace so everything is rebuilt with it. - Settings › Languages & Frameworks › Java › JVM options (java.jdt.ls.vmargs); a Lombok agent there wins. - Run (and Debug, as a notification) list the first compile errors when the build has errors, plus a hint when Lombok is missing or older than 1.18.34. Fixes #3 * fix(java): Base the Lombok hint on the agent jdtls actually runs A Lombok agent in Settings › Java › JVM options wins over the managed and cached jars, but the launch hint still looked only at those: with no cached jar it said Lombok was missing, and with an old cached one it blamed that version although jdtls ran the user's. The hint and the startup warning now use the user's agent (version from its file name).
80 lines
2.5 KiB
TypeScript
80 lines
2.5 KiB
TypeScript
import { beforeEach, describe, expect, it, vi } from "vitest";
|
|
import type { RunConfig } from "@/platform/ipc";
|
|
|
|
const invoked: Array<[string, unknown[]]> = [];
|
|
vi.mock("@/platform/ipc", async (orig) => {
|
|
const real = await orig<typeof import("@/platform/ipc")>();
|
|
const ok = (data: unknown) => Promise.resolve({ status: "ok", data });
|
|
return {
|
|
...real,
|
|
commands: {
|
|
...real.commands,
|
|
javaResolveLaunch: (...a: unknown[]) => {
|
|
invoked.push(["javaResolveLaunch", a]);
|
|
return ok({
|
|
build: "succeeded",
|
|
projectRoot: "/p",
|
|
classPaths: ["/p/target/classes", "/m2/a.jar"],
|
|
modulePaths: [],
|
|
javaHome: "/jdk21",
|
|
javaExec: "/jdk21/bin/java",
|
|
errors: [],
|
|
errorCount: 0,
|
|
hints: [],
|
|
});
|
|
},
|
|
javaDebugServer: (...a: unknown[]) => {
|
|
invoked.push(["javaDebugServer", a]);
|
|
return ok(41234);
|
|
},
|
|
},
|
|
};
|
|
});
|
|
|
|
const { isJavaDebuggable, javaAttachConfig, javaLaunchConfig } = await import("../java");
|
|
|
|
const app: RunConfig = {
|
|
id: "application:a.Main",
|
|
name: "Main",
|
|
kind: "spring-boot",
|
|
command: "java",
|
|
args: ["-Xmx1g", "-cp", "${classpath}", "a.Main", "--port", "8081 x"],
|
|
cwd: "api",
|
|
env: { A: "1" },
|
|
detected: true,
|
|
isTest: false,
|
|
debugAdapter: "java-debug",
|
|
};
|
|
|
|
describe("Java debugging (java-debug through jdtls)", () => {
|
|
beforeEach(() => {
|
|
invoked.length = 0;
|
|
});
|
|
|
|
it("launches Application configs with the resolved classpath on jdtls' debug server", async () => {
|
|
expect(isJavaDebuggable(app)).toBe(true);
|
|
expect(isJavaDebuggable({ ...app, kind: "maven" })).toBe(false);
|
|
const l = await javaLaunchConfig(app, "/p");
|
|
expect(invoked).toEqual([
|
|
["javaResolveLaunch", ["api", false, true]],
|
|
["javaDebugServer", ["api"]],
|
|
]);
|
|
expect(l).toMatchObject({ adapter: "java-debug", request: "launch", cwd: "/p/api", args: [], env: { A: "1" } });
|
|
expect(JSON.parse(l.extraJson!)).toMatchObject({
|
|
debugServer: 41234,
|
|
mainClass: "a.Main",
|
|
classPaths: ["/p/target/classes", "/m2/a.jar"],
|
|
javaExec: "/jdk21/bin/java",
|
|
vmArgs: "-Xmx1g",
|
|
args: '--port "8081 x"',
|
|
console: "internalConsole",
|
|
});
|
|
});
|
|
|
|
it("attaches to a JDWP agent", async () => {
|
|
const l = await javaAttachConfig({ name: "mvn test", module: "", hostName: "127.0.0.1", port: 5005 }, "/p");
|
|
expect(l).toMatchObject({ request: "attach", cwd: "/p" });
|
|
expect(JSON.parse(l.extraJson!)).toMatchObject({ debugServer: 41234, hostName: "127.0.0.1", port: 5005 });
|
|
});
|
|
});
|