aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Ashcon Partovi <ashcon@partovi.net> 2023-08-31 23:18:52 -0700
committerGravatar Ashcon Partovi <ashcon@partovi.net> 2023-08-31 23:19:04 -0700
commit40d749b480a00bbc63beaac16625c529709f1cd6 (patch)
treeb138e5ad64e449ec39bda767634126463f59a241
parent5288178c865cd9dcb500b00a65197bf2641d4e5c (diff)
downloadbun-40d749b480a00bbc63beaac16625c529709f1cd6.tar.gz
bun-40d749b480a00bbc63beaac16625c529709f1cd6.tar.zst
bun-40d749b480a00bbc63beaac16625c529709f1cd6.zip
JavaScript Debug Terminal == Bun Terminal
-rw-r--r--packages/bun-vscode/src/features/debug.ts32
1 files changed, 32 insertions, 0 deletions
diff --git a/packages/bun-vscode/src/features/debug.ts b/packages/bun-vscode/src/features/debug.ts
index 11415ee55..2f0c3cc22 100644
--- a/packages/bun-vscode/src/features/debug.ts
+++ b/packages/bun-vscode/src/features/debug.ts
@@ -47,6 +47,7 @@ export default function (context: vscode.ExtensionContext, factory?: vscode.Debu
),
vscode.debug.registerDebugAdapterDescriptorFactory("bun", factory ?? new InlineDebugAdapterFactory()),
vscode.window.registerTerminalProfileProvider("bun", new TerminalProfileProvider()),
+ vscode.window.onDidOpenTerminal(InjectDebugTerminal),
);
}
@@ -71,6 +72,37 @@ function DebugFileCommand(resource?: vscode.Uri): void {
}
}
+function InjectDebugTerminal(terminal: vscode.Terminal): void {
+ const { name, creationOptions } = terminal;
+ if (name !== "JavaScript Debug Terminal") {
+ return;
+ }
+
+ const { env } = creationOptions as vscode.TerminalOptions;
+ if (env["BUN_INSPECT"]) {
+ return;
+ }
+
+ 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_NOTIFY": `${signal.url}`,
+ },
+ });
+
+ debug.show();
+
+ // If the terminal is disposed too early, it will show a
+ // "Terminal has already been disposed" error prompt in the UI.
+ // Until a proper fix is found, we can just wait a bit before
+ // disposing the terminal.
+ setTimeout(() => terminal.dispose(), 100);
+}
+
class TerminalProfileProvider implements vscode.TerminalProfileProvider {
provideTerminalProfile(token: vscode.CancellationToken): vscode.ProviderResult<vscode.TerminalProfile> {
const { terminalProfile } = new TerminalDebugSession();