aboutsummaryrefslogtreecommitdiff
path: root/packages/bun-vscode/src/features/debug.ts
diff options
context:
space:
mode:
authorGravatar Ashcon Partovi <ashcon@partovi.net> 2023-09-01 18:56:25 -0700
committerGravatar Ashcon Partovi <ashcon@partovi.net> 2023-09-01 18:56:25 -0700
commit94a4cda713195bbaf70b4d888d0d1722e8b39537 (patch)
tree5126ca9154fbfdb2d9bd9d14ea8dd3cab50e6132 /packages/bun-vscode/src/features/debug.ts
parenteeb683d977cb8f40910c32b719ccc9223d869280 (diff)
downloadbun-94a4cda713195bbaf70b4d888d0d1722e8b39537.tar.gz
bun-94a4cda713195bbaf70b4d888d0d1722e8b39537.tar.zst
bun-94a4cda713195bbaf70b4d888d0d1722e8b39537.zip
Add configuration options to extension
Diffstat (limited to 'packages/bun-vscode/src/features/debug.ts')
-rw-r--r--packages/bun-vscode/src/features/debug.ts34
1 files changed, 33 insertions, 1 deletions
diff --git a/packages/bun-vscode/src/features/debug.ts b/packages/bun-vscode/src/features/debug.ts
index 8d2b3327a..184863aa0 100644
--- a/packages/bun-vscode/src/features/debug.ts
+++ b/packages/bun-vscode/src/features/debug.ts
@@ -29,6 +29,7 @@ const attachConfiguration: vscode.DebugConfiguration = {
request: "attach",
name: "Attach Bun",
url: "ws://localhost:6499/",
+ stopOnEntry: false,
};
const adapters = new Map<string, FileDebugSession>();
@@ -59,6 +60,7 @@ function RunFileCommand(resource?: vscode.Uri): void {
...runConfiguration,
noDebug: true,
program: path,
+ runtime: getRuntime(resource),
});
}
}
@@ -69,11 +71,17 @@ function DebugFileCommand(resource?: vscode.Uri): void {
vscode.debug.startDebugging(undefined, {
...debugConfiguration,
program: path,
+ runtime: getRuntime(resource),
});
}
}
function InjectDebugTerminal(terminal: vscode.Terminal): void {
+ const enabled = getConfig("debugTerminal.enabled");
+ if (enabled === false) {
+ return;
+ }
+
const { name, creationOptions } = terminal;
if (name !== "JavaScript Debug Terminal") {
return;
@@ -84,13 +92,16 @@ function InjectDebugTerminal(terminal: vscode.Terminal): void {
return;
}
+ const stopOnEntry = getConfig("debugTerminal.stopOnEntry") === true;
+ const query = stopOnEntry ? "break=1" : "wait=1";
+
const { adapter, signal } = new TerminalDebugSession();
const debug = vscode.window.createTerminal({
...creationOptions,
name: "JavaScript Debug Terminal",
env: {
...env,
- "BUN_INSPECT": `${adapter.url}?wait=1`,
+ "BUN_INSPECT": `${adapter.url}?${query}`,
"BUN_INSPECT_NOTIFY": `${signal.url}`,
},
});
@@ -130,12 +141,18 @@ class DebugConfigurationProvider implements vscode.DebugConfigurationProvider {
target = debugConfiguration;
}
+ // If the configuration is missing a default property, copy it from the template.
for (const [key, value] of Object.entries(target)) {
if (config[key] === undefined) {
config[key] = value;
}
}
+ // If no runtime is specified, get the path from the configuration.
+ if (request === "launch" && !config["runtime"]) {
+ config["runtime"] = getRuntime(folder);
+ }
+
return config;
}
}
@@ -169,6 +186,9 @@ class FileDebugSession extends DebugSession {
this.adapter = new DebugAdapter(url);
this.adapter.on("Adapter.response", response => this.sendResponse(response));
this.adapter.on("Adapter.event", event => this.sendEvent(event));
+ this.adapter.on("Adapter.reverseRequest", ({ command, arguments: args }) =>
+ this.sendRequest(command, args, 5000, () => {}),
+ );
adapters.set(url, this);
}
@@ -234,3 +254,15 @@ function isJavaScript(languageId?: string): boolean {
languageId === "typescriptreact"
);
}
+
+function getRuntime(scope?: vscode.ConfigurationScope): string {
+ const value = getConfig("runtime", scope);
+ if (typeof value === "string" && value.trim().length > 0) {
+ return value;
+ }
+ return "bun";
+}
+
+function getConfig<T>(path: string, scope?: vscode.ConfigurationScope): unknown {
+ return vscode.workspace.getConfiguration("bun", scope).get(path);
+}