Skip to content

Commit 30752c0

Browse files
waltossclaude
andcommitted
Add runtime aliases and validate --runtime flag
Consolidate duplicate RUNTIME_CONFIGS entries (debugpy, lldb-dap) into an alias map so canonical runtime names stay unique. Unknown --runtime values now fail fast with a list of available runtimes instead of silently spawning a broken DAP session. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 135e733 commit 30752c0

2 files changed

Lines changed: 36 additions & 5 deletions

File tree

src/dap/runtimes/index.ts

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,32 @@ export type { DapAttachArgs, DapLaunchArgs, DapRuntimeConfig, UserLaunchInput }
77

88
const RUNTIME_CONFIGS: Record<string, DapRuntimeConfig> = {
99
lldb: lldbConfig,
10-
"lldb-dap": lldbConfig,
1110
codelldb: codelldbConfig,
1211
python: debugpyConfig,
13-
debugpy: debugpyConfig,
1412
java: javaConfig,
1513
};
1614

15+
/** Maps alias names to their canonical runtime name. */
16+
const RUNTIME_ALIASES: Record<string, keyof typeof RUNTIME_CONFIGS> = {
17+
jdwp: "java",
18+
debugpy: "python",
19+
"lldb-dap": "lldb"
20+
};
21+
22+
/**
23+
* Resolves a runtime alias to its canonical name.
24+
* Returns the input unchanged if it is not an alias.
25+
*/
26+
export function resolveRuntime(runtime: string): string {
27+
return RUNTIME_ALIASES[runtime] ?? runtime;
28+
}
29+
30+
/** Set of all known DAP runtime names (canonical + aliases). */
31+
export const KNOWN_DAP_RUNTIMES = new Set([
32+
...Object.keys(RUNTIME_CONFIGS),
33+
...Object.keys(RUNTIME_ALIASES),
34+
]);
35+
1736
const DEFAULT_CONFIG: DapRuntimeConfig = {
1837
getAdapterCommand: () => {
1938
throw new Error("Unknown runtime");

src/session/factory.ts

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,39 @@
11
import { CdpSession } from "../cdp/session.ts";
2+
import { KNOWN_DAP_RUNTIMES, resolveRuntime } from "../dap/runtimes/index.ts";
23
import { DapSession } from "../dap/session.ts";
34
import type { Logger } from "../logger/index.ts";
45
import type { Session } from "./session.ts";
56

6-
const DAP_RUNTIMES = new Set(["lldb", "lldb-dap", "codelldb", "python", "debugpy", "java"]);
7+
const CDP_RUNTIMES = new Set(["node", "bun"]);
78

89
/**
910
* Returns true if the given runtime string should use a DAP session
1011
* (as opposed to the default CDP session for Node.js/Bun).
1112
*/
1213
export function isDapRuntime(runtime: string | undefined): runtime is string {
13-
if (runtime === undefined || runtime === "node" || runtime === "bun") return false;
14-
return DAP_RUNTIMES.has(runtime) || !["node", "bun"].includes(runtime);
14+
if (runtime === undefined || CDP_RUNTIMES.has(runtime)) return false;
15+
return KNOWN_DAP_RUNTIMES.has(runtime);
1516
}
1617

18+
/** All runtime names accepted by --runtime (CDP + DAP + aliases). */
19+
const ALL_RUNTIMES = new Set([...CDP_RUNTIMES, ...KNOWN_DAP_RUNTIMES]);
20+
1721
/**
1822
* Create the appropriate Session implementation for the given runtime.
23+
* Resolves aliases (e.g. "jdwp" → "java") and rejects unknown runtimes.
1924
*/
2025
export function createSession(
2126
sessionName: string,
2227
runtime: string | undefined,
2328
options?: { logger?: Logger<"daemon"> },
2429
): Session {
30+
if (runtime !== undefined) {
31+
if (!ALL_RUNTIMES.has(runtime)) {
32+
const available = [...ALL_RUNTIMES].sort().join(", ");
33+
throw new Error(`Unknown runtime "${runtime}". Available: ${available}`);
34+
}
35+
runtime = resolveRuntime(runtime);
36+
}
2537
if (isDapRuntime(runtime)) {
2638
return new DapSession(sessionName, runtime, options);
2739
}

0 commit comments

Comments
 (0)