aboutsummaryrefslogtreecommitdiff
path: root/packages/bun-vscode/src/features/debug.ts
diff options
context:
space:
mode:
authorGravatar Ashcon Partovi <ashcon@partovi.net> 2023-08-29 23:44:39 -0700
committerGravatar GitHub <noreply@github.com> 2023-08-29 23:44:39 -0700
commitf2553d24543d72a777ba60213473332809866cb2 (patch)
tree61faac4292dbdf1b4d0543e33d3f5d2c792825c5 /packages/bun-vscode/src/features/debug.ts
parentc028b206bce3f9b5c3cba7899c6bf34856efe43f (diff)
downloadbun-f2553d24543d72a777ba60213473332809866cb2.tar.gz
bun-f2553d24543d72a777ba60213473332809866cb2.tar.zst
bun-f2553d24543d72a777ba60213473332809866cb2.zip
More support for DAP (#4380)
* Fix reconnect with --watch * Support setVariable * Support setExpression * Support watch variables * Conditional and hit breakpoints * Support exceptionInfo * Support goto and gotoTargets * Support completions * Support both a URL and UNIX inspector at the same time * Fix url * WIP, add timeouts to figure out issue * Fix messages being dropped from debugger.ts * Progress * Fix breakpoints and ref-event-loop * More fixes * Fix exit * Make hovers better * Fix --hot
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"
+ );
+}