diff options
author | 2022-03-24 21:10:53 -0700 | |
---|---|---|
committer | 2022-03-24 21:10:53 -0700 | |
commit | 120b2670da71f65e37b57b0137e38e06f1b55ada (patch) | |
tree | 6e1e4c9a78c18ceab3e212eed85037e85312303a /src/open.zig | |
parent | a5027d46aea8577efb6aab839b4fdf04779f1c09 (diff) | |
download | bun-120b2670da71f65e37b57b0137e38e06f1b55ada.tar.gz bun-120b2670da71f65e37b57b0137e38e06f1b55ada.tar.zst bun-120b2670da71f65e37b57b0137e38e06f1b55ada.zip |
Bun.openInEditor
Diffstat (limited to '')
-rw-r--r-- | src/open.zig | 31 |
1 files changed, 18 insertions, 13 deletions
diff --git a/src/open.zig b/src/open.zig index f129dfc54..26b980a66 100644 --- a/src/open.zig +++ b/src/open.zig @@ -219,12 +219,14 @@ pub const Editor = enum(u8) { file: []const u8, line: ?string, column: ?string, - allocator: std.mem.Allocator, + _: std.mem.Allocator, ) !void { - var file_path_buf: [bun.MAX_PATH_BYTES + 1024]u8 = undefined; - var file_path_buf_stream = std.io.fixedBufferStream(&file_path_buf); + var spawned = try default_allocator.create(SpawnedEditorContext); + spawned.* = .{}; + var file_path_buf_stream = std.io.fixedBufferStream(&spawned.file_path_buf); var file_path_buf_writer = file_path_buf_stream.writer(); - var args_buf: [10]string = undefined; + var args_buf = &spawned.buf; + errdefer default_allocator.destroy(spawned); var i: usize = 0; @@ -309,19 +311,22 @@ pub const Editor = enum(u8) { }, } - var child_process = try std.ChildProcess.init(args_buf[0..i], allocator); - child_process.stderr_behavior = .Pipe; - child_process.stdin_behavior = .Ignore; - child_process.stdout_behavior = .Pipe; - try child_process.spawn(); - var thread = try std.Thread.spawn(.{}, autoClose, .{child_process}); + spawned.child_process = try std.ChildProcess.init(args_buf[0..i], default_allocator); + var thread = try std.Thread.spawn(.{}, autoClose, .{spawned}); thread.detach(); } + const SpawnedEditorContext = struct { + file_path_buf: [1024 + bun.MAX_PATH_BYTES]u8 = undefined, + buf: [10]string = undefined, + child_process: *std.ChildProcess = undefined, + }; + + fn autoClose(spawned: *SpawnedEditorContext) void { + defer bun.default_allocator.destroy(spawned); - fn autoClose(child_process: *std.ChildProcess) void { Global.setThreadName("Open Editor"); - _ = child_process.wait() catch {}; - child_process.deinit(); + spawned.child_process.spawn() catch return; + _ = spawned.child_process.wait() catch {}; } }; |