Files
openidea/src/features/run/zigDebug.ts
T
Akbar Husain 39f709def5 fix(run): debug Zig build steps via the executable config (#4002)
Debug on a detected 'zig build run' configuration said it had no debug adapter: build-step configs only run 'zig build <step>'. Steps that run an executable (addRunArtifact in build.zig) now link to that executable's config, and Debug delegates to it — running its before-launch build and keeping the clicked step as the session's origin.

Refs #3260

Co-authored-by: akbar1214 <43771058+akbar1214@users.noreply.github.com>
2026-11-17 21:17:05 +08:00

36 lines
1.3 KiB
TypeScript

/**
* A Zig build step (`zig build <step>`) builds but has no debug adapter of its own. The project's
* executable configs build the binary first and debug it under CodeLLDB, so debugging a step is
* delegated to the executable it runs.
*/
import type { RunConfig } from "@/platform/ipc";
const EXE_KIND = "zig-application";
/**
* A detected `zig build <step>` config that runs an executable, which has no debug adapter of its
* own. Test steps are excluded: their tests are not the project's app binary.
*/
export function isZigBuildStep(config: RunConfig): boolean {
return (
config.detected &&
!config.isTest &&
config.kind === "zig" &&
config.id.startsWith("zig:") &&
config.args[0] === "build" &&
config.args.length > 1
);
}
/**
* The debuggable executable config for a Zig build step, as linked by the backend. Detected
* configs are regenerated on load, so a step that runs an executable always carries the link;
* without one there is nothing to safely delegate to (a test step, an unparsed build script…).
*/
export function zigDebugTarget(step: RunConfig, configs: readonly RunConfig[]): RunConfig | null {
if (!isZigBuildStep(step)) return null;
const linked = step.params?.debugTarget;
if (!linked) return null;
return configs.find((c) => c.kind === EXE_KIND && !!c.debugAdapter && c.id === linked) ?? null;
}