in src/debug-adapter/client.ts [216:270]
protected setBreakPointsRequest(
response: DebugProtocol.SetBreakpointsResponse,
args: DebugProtocol.SetBreakpointsArguments,
) {
// The path we need to pass to Bazel here depends on how the .bzl file has
// been loaded. Unfortunately this means we have to create two breakpoints,
// one for each possible path, because the way the .bzl file is loaded is
// chosen by the user:
//
// 1. If the file is loaded using an explicit repository reference (i.e.,
// `@foo//:bar.bzl`), then it will appear in the `external` subdirectory
// of Bazel's output_base.
// 2. If the file is loaded as a same-repository path (i.e., `//:bar.bzl`),
// then Bazel will treat it as if it were under `execroot`, which is a
// symlink to the actual filesystem location of the file.
//
// TODO(allevato): We may be able to simplify this once
// https://github.com/bazelbuild/bazel/issues/6848 is in a release.
const workspaceName = path.basename(this.bazelInfo.get("execution_root"));
const relativeSourcePath = path.relative(
this.bazelInfo.get("workspace"),
args.source.path,
);
const sourcePathInExternal = path.join(
this.bazelInfo.get("output_base"),
"external",
workspaceName,
relativeSourcePath,
);
this.sourceBreakpoints.set(args.source.path, args.breakpoints);
this.sourceBreakpoints.set(sourcePathInExternal, args.breakpoints);
// Convert to Bazel breakpoints.
const bazelBreakpoints = new Array<skylark_debugging.Breakpoint>();
for (const [sourcePath, breakpoints] of this.sourceBreakpoints) {
for (const breakpoint of breakpoints) {
bazelBreakpoints.push(
skylark_debugging.Breakpoint.create({
expression: breakpoint.condition,
location: skylark_debugging.Location.create({
lineNumber: breakpoint.line,
path: sourcePath,
}),
}),
);
}
}
this.bazelConnection.sendRequest({
setBreakpoints: skylark_debugging.SetBreakpointsRequest.create({
breakpoint: bazelBreakpoints,
}),
}).catch((err) => this.debugLog("Error setting breakpoint: " + err));
this.sendResponse(response);
}