Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix for windows debug support #14048

Merged
merged 19 commits into from
Sep 21, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions packages/bun-debug-adapter-protocol/src/debugger/adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2207,7 +2207,7 @@ function titleize(name: string): string {
}

function sourcePresentationHint(url?: string): DAP.Source["presentationHint"] {
if (!url || path.isAbsolute(url)) {
if (!url || !path.isAbsolute(url)) {
return "deemphasize";
}
if (url.includes("/node_modules/") || url.includes("\\node_modules\\")) {
Expand All @@ -2222,7 +2222,7 @@ function sourceName(url?: string): string {
}
if (isJavaScript(url)) {
if (process.platform === "win32") {
return url.split("\\").pop() || url;
url = url.replaceAll("\\", "/");
}
return url.split("/").pop() || url;
}
Expand Down Expand Up @@ -2633,6 +2633,10 @@ export function getRandomId() {
return Math.random().toString(36).slice(2);
}

export function normalizeWindowsPath(path: string): string {
return (path.charAt(0).toUpperCase() + path.slice(1)).replaceAll("\\\\", "\\");
export function normalizeWindowsPath(winPath: string): string {
winPath = path.normalize(winPath);
if (winPath[1] === ":" && (winPath[2] === "\\" || winPath[2] === "/")) {
return (winPath.charAt(0).toUpperCase() + winPath.slice(1)).replaceAll("\\\\", "\\");
}
return winPath;
}
52 changes: 28 additions & 24 deletions packages/bun-vscode/src/features/debug.ts
Original file line number Diff line number Diff line change
Expand Up @@ -176,19 +176,23 @@ class FileDebugSession extends DebugSession {
constructor(sessionId?: string) {
super();
const uniqueId = sessionId ?? Math.random().toString(36).slice(2);
// the signal is only first used well after this resolves
getAvailablePort().then(port => {
const url = process.platform === "win32" ? `ws://127.0.0.1:${port}/${getRandomId()}` : `ws+unix://${tmpdir()}/${uniqueId}.sock`;

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);
});
let url;
if (process.platform === "win32") {
getAvailablePort().then(port => {
// the signal is only first used well after this resolves
url = `ws://127.0.0.1:${port}/${getRandomId()}`;
});
} else {
url = `ws+unix://${tmpdir()}/${uniqueId}.sock`;
}
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);
}

handleMessage(message: DAP.Event | DAP.Request | DAP.Response): void {
Expand All @@ -211,18 +215,18 @@ class TerminalDebugSession extends FileDebugSession {

constructor() {
super();
// the signal is only first used well after this resolves
getAvailablePort().then(port => {
if (process.platform === "win32") {
if (process.platform === "win32") {
getAvailablePort().then(port => {
// the signal is only first used well after this resolves
this.signal = new TCPSocketSignal(port);
} else {
this.signal = new UnixSignal();
}
this.signal.on("Signal.received", () => {
vscode.debug.startDebugging(undefined, {
...ATTACH_CONFIGURATION,
url: this.adapter.url,
});
});
} else {
this.signal = new UnixSignal();
}
this.signal.on("Signal.received", () => {
vscode.debug.startDebugging(undefined, {
...ATTACH_CONFIGURATION,
url: this.adapter.url,
});
});
}
Expand Down
Loading