More fixes

This commit is contained in:
Ashcon Partovi
2023-08-25 23:29:46 -07:00
parent d0e2679fb5
commit eb4ef364f2
9 changed files with 69 additions and 16 deletions

View File

@@ -20,6 +20,7 @@ type LaunchRequest = DAP.LaunchRequest & {
env?: Record<string, string>;
inheritEnv?: boolean;
watch?: boolean | "hot";
debug?: boolean;
};
type AttachRequest = DAP.AttachRequest & {
@@ -256,7 +257,8 @@ export class DebugAdapter implements IDebugAdapter, InspectorListener {
}
const finalArgs = [...args];
if (isTestJavaScript(program)) {
const isTest = isTestJavaScript(program);
if (isTest) {
finalArgs.unshift("test");
}
@@ -276,8 +278,12 @@ export class DebugAdapter implements IDebugAdapter, InspectorListener {
finalEnv["BUN_INSPECT"] = `1${this.#url}`;
finalEnv["BUN_INSPECT_NOTIFY"] = `unix://${this.#inspector.unix}`;
// https://github.com/microsoft/vscode/issues/571
finalEnv["NO_COLOR"] = "1";
if (isTest) {
finalEnv["FORCE_COLOR"] = "1";
} else {
// https://github.com/microsoft/vscode/issues/571
finalEnv["NO_COLOR"] = "1";
}
const subprocess = spawn(runtime, [...finalArgs, program], {
stdio: ["ignore", "pipe", "pipe"],
@@ -305,11 +311,31 @@ export class DebugAdapter implements IDebugAdapter, InspectorListener {
subprocess.stdout!.on("data", data => {
const text = data.toString();
this.#stdout?.(text);
if (isTest) {
this.#emit("output", {
category: "stdout",
output: text,
source: {
path: program,
},
});
}
});
subprocess.stderr!.on("data", data => {
const text = data.toString();
this.#stderr?.(text);
if (isTest) {
this.#emit("output", {
category: "stdout", // Not stderr, since VSCode will highlight it as red.
output: text,
source: {
path: program,
},
});
}
});
const start = new Promise<undefined>(resolve => {

View File

@@ -51,9 +51,14 @@ export class WebSocketInspector implements Inspector {
let webSocket: WebSocket;
try {
this.#log("connecting:", url);
// @ts-expect-error: Node.js
webSocket = new WebSocket(url, {
headers: {
"Ref-Event-Loop": "0",
"Ref-Event-Loop": "1",
},
finishRequest: (request: import("http").ClientRequest) => {
request.setHeader("Ref-Event-Loop", "1");
request.end();
},
});
} catch (error) {

View File

@@ -55,14 +55,16 @@
"commands": [
{
"command": "extension.bun.runFile",
"title": "Run File",
"title": "Run Bun",
"shortTitle": "Run",
"category": "Bun",
"enablement": "!inDebugMode",
"icon": "$(play)"
},
{
"command": "extension.bun.debugFile",
"title": "Debug File",
"title": "Debug Bun",
"shortTitle": "Debug",
"category": "Bun",
"enablement": "!inDebugMode",
"icon": "$(debug-alt)"

View File

@@ -59,7 +59,7 @@ function RunFileCommand(resource: vscode.Uri): void {
vscode.debug.startDebugging(undefined, {
...runConfiguration,
noDebug: true,
program: resource,
program: path,
});
}
}
@@ -69,7 +69,7 @@ function DebugFileCommand(resource: vscode.Uri): void {
if (path) {
vscode.debug.startDebugging(undefined, {
...debugConfiguration,
program: resource,
program: path,
});
}
}

View File

@@ -626,6 +626,14 @@ pub const PathLike = union(Tag) {
pub const Tag = enum { string, buffer, slice_with_underlying_string };
pub fn estimatedSize(this: *const PathLike) usize {
return switch (this.*) {
.string => this.string.estimatedSize(),
.buffer => this.buffer.slice().len,
.slice_with_underlying_string => 0,
};
}
pub fn deinit(this: *const PathLike) void {
if (this.* == .slice_with_underlying_string) {
this.slice_with_underlying_string.deinit();
@@ -1059,6 +1067,13 @@ pub const PathOrFileDescriptor = union(Tag) {
}
}
pub fn estimatedSize(this: *const PathOrFileDescriptor) usize {
return switch (this.*) {
.path => this.path.estimatedSize(),
.fd => 0,
};
}
pub fn toThreadSafe(this: *PathOrFileDescriptor) void {
if (this.* == .path) {
this.path.toThreadSafe();

View File

@@ -1253,8 +1253,8 @@ pub const Blob = struct {
if (this.store) |store| {
size += @sizeOf(Blob.Store);
size += switch (store.data) {
.bytes => store.data.bytes.stored_name.len,
.file => store.data.file.pathlike.path.slice().len,
.bytes => store.data.bytes.stored_name.estimatedSize(),
.file => store.data.file.pathlike.estimatedSize(),
};
}

View File

@@ -2,6 +2,7 @@ import type * as BunType from "bun";
// We want to avoid dealing with creating a prototype for the inspector class
let sendFn_, disconnectFn_;
const colors = Bun.enableANSIColors && process.env.NO_COLOR !== "1";
var debuggerCounter = 1;
class DebuggerWithMessageQueue {
@@ -31,7 +32,7 @@ function generatePath() {
}
function terminalLink(url) {
if (Bun.enableANSIColors) {
if (colors) {
// bold + hyperlink + reset
return "\x1b[1m\x1b]8;;" + url + "\x1b\\" + url + "\x1b]8;;\x1b\\" + "\x1b[22m";
}
@@ -40,7 +41,7 @@ function terminalLink(url) {
}
function dim(text) {
if (Bun.enableANSIColors) {
if (colors) {
return "\x1b[2m" + text + "\x1b[22m";
}
@@ -276,7 +277,7 @@ class WebSocketListener {
// yellow foreground
writeToConsole(dim(`------------------ Bun Inspector ------------------` + "\n"));
if (Bun.enableANSIColors) {
if (colors) {
// reset background
writeToConsole("\x1b[49m");
}

File diff suppressed because one or more lines are too long

View File

@@ -31,6 +31,10 @@ pub const PathString = packed struct {
return this.toValue().asObjectRef();
}
pub fn estimatedSize(this: *const PathString) usize {
return @as(usize, this.len);
}
pub fn toJS(this: PathString, ctx: JSC.C.JSContextRef, _: JSC.C.ExceptionRef) JSC.C.JSValueRef {
var zig_str = JSC.ZigString.init(this.slice());
zig_str.detectEncoding();