fix(debug): resolve relative dap commands from cwd

This commit is contained in:
DanZAIO
2026-06-20 00:01:20 -03:00
parent 23922f3fe2
commit 2afa7d49c6
2 changed files with 39 additions and 1 deletions
+14 -1
View File
@@ -171,6 +171,19 @@ export function getAdapterConfigs(cwd?: string): Record<string, DapAdapterConfig
return cwd ? loadAdapterConfigs(cwd) : { ...DEFAULT_ADAPTERS };
}
function normalizeCommandForCwd(command: string, cwd: string): string {
if (path.isAbsolute(command)) return command;
if (
command.startsWith("./") ||
command.startsWith("../") ||
command.startsWith(".\\") ||
command.startsWith("..\\")
) {
return path.resolve(cwd, command);
}
return command;
}
function resolveAdapterFromConfig(
adapterName: string,
configs: Record<string, DapAdapterConfig>,
@@ -178,7 +191,7 @@ function resolveAdapterFromConfig(
): DapResolvedAdapter | null {
const config = configs[adapterName];
if (!config) return null;
const resolvedCommand = resolveCommand(config.command, cwd);
const resolvedCommand = resolveCommand(normalizeCommandForCwd(config.command, cwd), cwd);
if (!resolvedCommand) return null;
return {
name: adapterName,
@@ -121,6 +121,31 @@ describe("DAP adapter configuration", () => {
expect(selected?.launchDefaults).toEqual({ request: "launch", projectRoot: "." });
});
it("resolves relative adapter commands from the debug cwd", async () => {
const cwd = await makeTempDir("omp-dap-config-relative-command-");
const command = path.join(cwd, "tools", process.platform === "win32" ? "debug-adapter.cmd" : "debug-adapter");
await fs.mkdir(path.dirname(command), { recursive: true });
await fs.writeFile(command, "");
await fs.chmod(command, 0o755);
await fs.writeFile(
path.join(cwd, "dap.json"),
JSON.stringify({
adapters: {
relative: {
command: process.platform === "win32" ? ".\\tools\\debug-adapter.cmd" : "./tools/debug-adapter",
fileTypes: [".rel"],
},
},
}),
);
const adapter = resolveAdapter("relative", cwd);
expect(adapter?.command).toBe(
process.platform === "win32" ? ".\\tools\\debug-adapter.cmd" : "./tools/debug-adapter",
);
expect(adapter?.resolvedCommand).toBe(command);
});
it("loads plugin DAP adapters from plugin config files", async () => {
const cwd = await makeTempDir("omp-dap-config-plugin-");
const pluginRoot = path.join(cwd, "plugins", "acme-debug");