aboutsummaryrefslogtreecommitdiff
path: root/packages/bun-vscode/src/features/debug.ts
diff options
context:
space:
mode:
Diffstat (limited to 'packages/bun-vscode/src/features/debug.ts')
-rw-r--r--packages/bun-vscode/src/features/debug.ts57
1 files changed, 43 insertions, 14 deletions
diff --git a/packages/bun-vscode/src/features/debug.ts b/packages/bun-vscode/src/features/debug.ts
index e6322b73b..984031e87 100644
--- a/packages/bun-vscode/src/features/debug.ts
+++ b/packages/bun-vscode/src/features/debug.ts
@@ -9,7 +9,8 @@ const debugConfiguration: vscode.DebugConfiguration = {
request: "launch",
name: "Debug Bun",
program: "${file}",
- watch: false,
+ stopOnEntry: false,
+ watchMode: false,
};
const runConfiguration: vscode.DebugConfiguration = {
@@ -17,8 +18,8 @@ const runConfiguration: vscode.DebugConfiguration = {
request: "launch",
name: "Run Bun",
program: "${file}",
- debug: false,
- watch: false,
+ noDebug: true,
+ watchMode: false,
};
const attachConfiguration: vscode.DebugConfiguration = {
@@ -48,15 +49,25 @@ export default function (context: vscode.ExtensionContext, factory?: vscode.Debu
vscode.window.registerTerminalProfileProvider("bun", new TerminalProfileProvider()),
);
- const { terminalProfile } = new TerminalDebugSession();
- const { options } = terminalProfile;
- const terminal = vscode.window.createTerminal(options);
- terminal.show();
- context.subscriptions.push(terminal);
+ const document = getActiveDocument();
+ if (isJavaScript(document?.languageId)) {
+ vscode.workspace.findFiles("bun.lockb", "node_modules", 1).then(files => {
+ const { terminalProfile } = new TerminalDebugSession();
+ const { options } = terminalProfile;
+ const terminal = vscode.window.createTerminal(options);
+
+ const focus = files.length > 0;
+ if (focus) {
+ terminal.show();
+ }
+
+ context.subscriptions.push(terminal);
+ });
+ }
}
function RunFileCommand(resource?: vscode.Uri): void {
- const path = getCurrentPath(resource);
+ const path = getActivePath(resource);
if (path) {
vscode.debug.startDebugging(undefined, {
...runConfiguration,
@@ -67,7 +78,7 @@ function RunFileCommand(resource?: vscode.Uri): void {
}
function DebugFileCommand(resource?: vscode.Uri): void {
- const path = getCurrentPath(resource);
+ const path = getActivePath(resource);
if (path) {
vscode.debug.startDebugging(undefined, {
...debugConfiguration,
@@ -178,18 +189,36 @@ class TerminalDebugSession extends FileDebugSession {
return new vscode.TerminalProfile({
name: "Bun Terminal",
env: {
- "BUN_INSPECT": `1${this.adapter.url}`,
+ "BUN_INSPECT": `${this.adapter.url}?wait=1`,
"BUN_INSPECT_NOTIFY": `${this.signal.url}`,
},
isTransient: true,
iconPath: new vscode.ThemeIcon("debug-console"),
});
}
+
+ dispose(): void {
+ super.dispose();
+ this.signal.close();
+ }
+}
+
+function getActiveDocument(): vscode.TextDocument | undefined {
+ return vscode.window.activeTextEditor?.document;
}
-function getCurrentPath(target?: vscode.Uri): string | undefined {
- if (!target && vscode.window.activeTextEditor) {
- target = vscode.window.activeTextEditor.document.uri;
+function getActivePath(target?: vscode.Uri): string | undefined {
+ if (!target) {
+ target = getActiveDocument()?.uri;
}
return target?.fsPath;
}
+
+function isJavaScript(languageId?: string): boolean {
+ return (
+ languageId === "javascript" ||
+ languageId === "javascriptreact" ||
+ languageId === "typescript" ||
+ languageId === "typescriptreact"
+ );
+}