дзеркало
https://github.com/l0ng-ai/openidea.git
синхронізовано 2026-11-09 03:05:40 +02:00
fix(debugger): name the Java project in debug requests (#1866)
java-debug resolves the Java project for Evaluate from `mainClass` only when the class belongs to a project jdtls knows, and a JDWP attach cannot even see the main class, so every expression failed with "Cannot evaluate, please specify projectName in launch.json". Both builders now send `projectName`: the launch one for the project root jdtls resolved, the attach one for the module directory. The name is read from Eclipse's `.project` descriptor, else the Maven `artifactId` (jdtls names a module after its artifact, not its folder), else the folder name. Co-authored-by: chao <[email protected]>
Цей коміт міститься в:
1 джерело
fa36733f80
коміт
ab9bb7c266
2 files changed
+82
-4
No files matched your search
@@ -4,6 +4,7 @@ import type { RunConfig } from "@/platform/ipc";
|
||||
const invoked: Array<[string, unknown[]]> = [];
|
||||
let shortenCommandLine: string | null = null;
|
||||
let kotlinFiles = false;
|
||||
const files: Record<string, string> = {};
|
||||
vi.mock("@/platform/ipc", async (orig) => {
|
||||
const real = await orig<typeof import("@/platform/ipc")>();
|
||||
const ok = (data: unknown) => Promise.resolve({ status: "ok", data });
|
||||
@@ -17,7 +18,7 @@ vi.mock("@/platform/ipc", async (orig) => {
|
||||
? [{ path: "/p/api/src/main/java/a/Main.java", relPath: "api/src/main/java/a/Main.java" }]
|
||||
: [],
|
||||
),
|
||||
fsReadText: () => ok("package a;\npublic class Main {}"),
|
||||
fsReadText: (path: string) => ok(files[path] ?? "package a;\npublic class Main {}"),
|
||||
runConfigs: () => ok([]),
|
||||
fsReadDir: (path: string) =>
|
||||
ok(
|
||||
@@ -49,7 +50,7 @@ vi.mock("@/platform/ipc", async (orig) => {
|
||||
};
|
||||
});
|
||||
|
||||
const { isJavaDebuggable, javaAttachConfig, javaLaunchConfig } = await import("../java");
|
||||
const { isJavaDebuggable, javaAttachConfig, javaLaunchConfig, javaProjectName } = await import("../java");
|
||||
|
||||
const app: RunConfig = {
|
||||
id: "application:a.Main",
|
||||
@@ -90,6 +91,7 @@ describe("Java debugging (java-debug through jdtls)", () => {
|
||||
args: '--port "8081 x"',
|
||||
console: "internalConsole",
|
||||
shortenCommandLine: "none",
|
||||
projectName: "p",
|
||||
});
|
||||
});
|
||||
|
||||
@@ -162,7 +164,12 @@ describe("Java debugging (java-debug through jdtls)", () => {
|
||||
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 });
|
||||
expect(JSON.parse(l.extraJson!)).toMatchObject({
|
||||
debugServer: 41234,
|
||||
hostName: "127.0.0.1",
|
||||
port: 5005,
|
||||
projectName: "p",
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -176,3 +183,28 @@ it.each(["sibling", "/outside/modules"])("debugs from %s with the main class mod
|
||||
expect(launch.cwd).toBe(cwd.startsWith("/") ? cwd : `/p/${cwd}`);
|
||||
}
|
||||
});
|
||||
|
||||
describe("naming the Java project jdtls imported", () => {
|
||||
beforeEach(() => {
|
||||
invoked.length = 0;
|
||||
for (const key of Object.keys(files)) delete files[key];
|
||||
});
|
||||
|
||||
it("uses the Maven artifactId, not the folder name, and skips the parent's", async () => {
|
||||
files["/p/pom.xml"] =
|
||||
"<project><parent><artifactId>orders-parent</artifactId></parent><artifactId>openidea-fixture-orders</artifactId></project>";
|
||||
expect(await javaProjectName("/p")).toBe("openidea-fixture-orders");
|
||||
});
|
||||
|
||||
it("prefers the Eclipse project descriptor", async () => {
|
||||
files["/p/.project"] = "<projectDescription><name>taihe</name></projectDescription>";
|
||||
files["/p/pom.xml"] = "<project><artifactId>orders</artifactId></project>";
|
||||
expect(await javaProjectName("/p")).toBe("taihe");
|
||||
});
|
||||
|
||||
it("falls back to the folder name when the project says nothing, including unresolved properties", async () => {
|
||||
expect(await javaProjectName("/p/api")).toBe("api");
|
||||
files["/p/pom.xml"] = "<project><artifactId>${revision}</artifactId></project>";
|
||||
expect(await javaProjectName("/p")).toBe("p");
|
||||
});
|
||||
});
|
||||
Reference in new issue
Заблокувати користувача