aboutsummaryrefslogtreecommitdiff
path: root/packages/bun-vscode/src
diff options
context:
space:
mode:
authorGravatar Ashcon Partovi <ashcon@partovi.net> 2023-08-26 18:26:50 -0700
committerGravatar Ashcon Partovi <ashcon@partovi.net> 2023-08-26 18:26:50 -0700
commiteeeef5aaf05c832ccc4e6de6781f1924a5893808 (patch)
tree8b1283bd79d0e17a850717c9a88d668fb0c2c21d /packages/bun-vscode/src
parentf9b966c13f5ed3d870c54b69cb59a5adc12060b7 (diff)
downloadbun-dap3.tar.gz
bun-dap3.tar.zst
bun-dap3.zip
Terminal works, launch is being reworkeddap3
Diffstat (limited to 'packages/bun-vscode/src')
-rw-r--r--packages/bun-vscode/src/features/debug.ts58
1 files changed, 15 insertions, 43 deletions
diff --git a/packages/bun-vscode/src/features/debug.ts b/packages/bun-vscode/src/features/debug.ts
index eae2b1c33..91e175413 100644
--- a/packages/bun-vscode/src/features/debug.ts
+++ b/packages/bun-vscode/src/features/debug.ts
@@ -1,9 +1,8 @@
import * as vscode from "vscode";
import type { CancellationToken, DebugConfiguration, ProviderResult, WorkspaceFolder } from "vscode";
import type { DAP } from "../../../bun-debug-adapter-protocol";
-import { DebugAdapter } from "../../../bun-debug-adapter-protocol";
+import { DebugAdapter, UnixSignal } from "../../../bun-debug-adapter-protocol";
import { DebugSession } from "@vscode/debugadapter";
-import { inspect } from "node:util";
import { tmpdir } from "node:os";
const debugConfiguration: vscode.DebugConfiguration = {
@@ -110,7 +109,7 @@ class InlineDebugAdapterFactory implements vscode.DebugAdapterDescriptorFactory
const { configuration } = session;
const { request, url } = configuration;
- if (request === "attach" && url === terminal?.url) {
+ if (request === "attach" && url === terminal?.adapter.url) {
return new vscode.DebugAdapterInlineImplementation(terminal);
}
@@ -120,47 +119,27 @@ class InlineDebugAdapterFactory implements vscode.DebugAdapterDescriptorFactory
}
class FileDebugSession extends DebugSession {
- readonly url: string;
readonly adapter: DebugAdapter;
+ readonly signal: UnixSignal;
constructor(sessionId?: string) {
super();
const uniqueId = sessionId ?? Math.random().toString(36).slice(2);
- this.url = `ws+unix://${tmpdir()}/bun-vscode-${uniqueId}.sock`;
- this.adapter = new DebugAdapter({
- url: this.url,
- send: this.sendMessage.bind(this),
- logger(...messages) {
- log("jsc", ...messages);
- },
- stdout(message) {
- log("console", message);
- },
- stderr(message) {
- log("console", message);
- },
- });
+ this.adapter = new DebugAdapter(`ws+unix://${tmpdir()}/${uniqueId}.sock`);
+ this.adapter.on("Adapter.response", response => this.sendResponse(response));
+ this.adapter.on("Adapter.event", event => this.sendEvent(event));
+ this.signal = new UnixSignal();
}
- sendMessage(message: DAP.Request | DAP.Response | DAP.Event): void {
- log("dap", "-->", message);
-
+ handleMessage(message: DAP.Event | DAP.Request | DAP.Response): void {
const { type } = message;
- if (type === "response") {
- this.sendResponse(message);
- } else if (type === "event") {
- this.sendEvent(message);
+ if (type === "request") {
+ this.adapter.emit("Adapter.request", message);
} else {
throw new Error(`Not supported: ${type}`);
}
}
- handleMessage(message: DAP.Event | DAP.Request | DAP.Response): void {
- log("dap", "<--", message);
-
- this.adapter.accept(message);
- }
-
dispose() {
this.adapter.close();
}
@@ -174,26 +153,19 @@ class TerminalDebugSession extends FileDebugSession {
this.terminal = vscode.window.createTerminal({
name: "Bun Terminal",
env: {
- "BUN_INSPECT": `1${this.url}`,
- "BUN_INSPECT_NOTIFY": `unix://${this.adapter.inspector.unix}`,
+ "BUN_INSPECT": `1${this.adapter.url}`,
+ "BUN_INSPECT_NOTIFY": `${this.signal.url}`,
},
isTransient: true,
iconPath: new vscode.ThemeIcon("debug-console"),
});
this.terminal.show();
- this.adapter.inspector.startDebugging = () => {
+ this.signal.on("Signal.received", () => {
vscode.debug.startDebugging(undefined, {
...attachConfiguration,
- url: this.url,
+ url: this.adapter.url,
});
- };
- }
-}
-
-function log(channel: string, ...message: unknown[]): void {
- if (process.env.NODE_ENV === "development") {
- console.log(`[${channel}]`, ...message);
- channels[channel]?.appendLine(message.map(v => inspect(v)).join(" "));
+ });
}
}