diff --git a/src/LSP.zig b/src/LSP.zig index f8142be..c541a48 100644 --- a/src/LSP.zig +++ b/src/LSP.zig @@ -5,7 +5,7 @@ const root = @import("root"); const tracy = @import("tracy"); const log = @import("log"); -a: std.mem.Allocator, +allocator: std.mem.Allocator, pid: tp.pid, const Self = @This(); @@ -14,8 +14,8 @@ const sp_tag = "child"; const debug_lsp = true; const lsp_request_timeout = std.time.ns_per_s * 30; -pub fn open(a: std.mem.Allocator, project: []const u8, cmd: tp.message) !Self { - return .{ .a = a, .pid = try Process.create(a, project, cmd) }; +pub fn open(allocator: std.mem.Allocator, project: []const u8, cmd: tp.message) !Self { + return .{ .allocator = allocator, .pid = try Process.create(allocator, project, cmd) }; } pub fn deinit(self: *Self) void { @@ -28,17 +28,17 @@ pub fn term(self: *Self) void { self.pid.deinit(); } -pub fn send_request(self: Self, a: std.mem.Allocator, method: []const u8, m: anytype) !tp.message { +pub fn send_request(self: Self, allocator: std.mem.Allocator, method: []const u8, m: anytype) !tp.message { // const frame = tracy.initZone(@src(), .{ .name = module_name ++ ".send_request" }); // defer frame.deinit(); - var cb = std.ArrayList(u8).init(self.a); + var cb = std.ArrayList(u8).init(self.allocator); defer cb.deinit(); try cbor.writeValue(cb.writer(), m); - return self.pid.call(a, lsp_request_timeout, .{ "REQ", method, cb.items }); + return self.pid.call(allocator, lsp_request_timeout, .{ "REQ", method, cb.items }); } pub fn send_notification(self: Self, method: []const u8, m: anytype) !void { - var cb = std.ArrayList(u8).init(self.a); + var cb = std.ArrayList(u8).init(self.allocator); defer cb.deinit(); try cbor.writeValue(cb.writer(), m); return self.send_notification_raw(method, cb.items); @@ -53,7 +53,7 @@ pub fn close(self: *Self) void { } const Process = struct { - a: std.mem.Allocator, + allocator: std.mem.Allocator, cmd: tp.message, receiver: Receiver, sp: ?tp.subprocess = null, @@ -68,7 +68,7 @@ const Process = struct { const Receiver = tp.Receiver(*Process); - pub fn create(a: std.mem.Allocator, project: []const u8, cmd: tp.message) !tp.pid { + pub fn create(allocator: std.mem.Allocator, project: []const u8, cmd: tp.message) !tp.pid { var tag: []const u8 = undefined; if (try cmd.match(.{tp.extract(&tag)})) { // @@ -77,31 +77,31 @@ const Process = struct { } else { return tp.exit("no LSP command"); } - const self = try a.create(Process); - var sp_tag_ = std.ArrayList(u8).init(a); + const self = try allocator.create(Process); + var sp_tag_ = std.ArrayList(u8).init(allocator); defer sp_tag_.deinit(); try sp_tag_.appendSlice(tag); try sp_tag_.appendSlice("-" ++ sp_tag); self.* = .{ - .a = a, - .cmd = try cmd.clone(a), + .allocator = allocator, + .cmd = try cmd.clone(allocator), .receiver = Receiver.init(receive, self), - .recv_buf = std.ArrayList(u8).init(a), + .recv_buf = std.ArrayList(u8).init(allocator), .parent = tp.self_pid().clone(), - .tag = try a.dupeZ(u8, tag), - .project = try a.dupeZ(u8, project), - .requests = std.AutoHashMap(i32, tp.pid).init(a), + .tag = try allocator.dupeZ(u8, tag), + .project = try allocator.dupeZ(u8, project), + .requests = std.AutoHashMap(i32, tp.pid).init(allocator), .sp_tag = try sp_tag_.toOwnedSliceSentinel(0), }; - return tp.spawn_link(self.a, self, Process.start, self.tag); + return tp.spawn_link(self.allocator, self, Process.start, self.tag); } fn deinit(self: *Process) void { var i = self.requests.iterator(); while (i.next()) |req| req.value_ptr.deinit(); - self.a.free(self.sp_tag); + self.allocator.free(self.sp_tag); self.recv_buf.deinit(); - self.a.free(self.cmd.buf); + self.allocator.free(self.cmd.buf); self.close() catch {}; self.write_log("### terminated LSP process ###\n", .{}); if (self.log_file) |file| file.close(); @@ -127,10 +127,10 @@ const Process = struct { const frame = tracy.initZone(@src(), .{ .name = module_name ++ " start" }); defer frame.deinit(); _ = tp.set_trap(true); - self.sp = tp.subprocess.init(self.a, self.cmd, self.sp_tag, .Pipe) catch |e| return tp.exit_error(e, @errorReturnTrace()); + self.sp = tp.subprocess.init(self.allocator, self.cmd, self.sp_tag, .Pipe) catch |e| return tp.exit_error(e, @errorReturnTrace()); tp.receive(&self.receiver); - var log_file_path = std.ArrayList(u8).init(self.a); + var log_file_path = std.ArrayList(u8).init(self.allocator); defer log_file_path.deinit(); const state_dir = root.get_state_dir() catch |e| return tp.exit_error(e, @errorReturnTrace()); log_file_path.writer().print("{s}/lsp-{s}.log", .{ state_dir, self.tag }) catch |e| return tp.exit_error(e, @errorReturnTrace()); @@ -248,7 +248,7 @@ const Process = struct { const id = self.next_id; self.next_id += 1; - var msg = std.ArrayList(u8).init(self.a); + var msg = std.ArrayList(u8).init(self.allocator); defer msg.deinit(); const msg_writer = msg.writer(); try cbor.writeMapHeader(msg_writer, 4); @@ -261,9 +261,9 @@ const Process = struct { try cbor.writeValue(msg_writer, "params"); _ = try msg_writer.write(params_cb); - const json = try cbor.toJsonAlloc(self.a, msg.items); - defer self.a.free(json); - var output = std.ArrayList(u8).init(self.a); + const json = try cbor.toJsonAlloc(self.allocator, msg.items); + defer self.allocator.free(json); + var output = std.ArrayList(u8).init(self.allocator); defer output.deinit(); const writer = output.writer(); const terminator = "\r\n"; @@ -282,7 +282,7 @@ const Process = struct { const have_params = !(cbor.match(params_cb, cbor.null_) catch false); - var msg = std.ArrayList(u8).init(self.a); + var msg = std.ArrayList(u8).init(self.allocator); defer msg.deinit(); const msg_writer = msg.writer(); try cbor.writeMapHeader(msg_writer, 3); @@ -297,9 +297,9 @@ const Process = struct { try cbor.writeMapHeader(msg_writer, 0); } - const json = try cbor.toJsonAlloc(self.a, msg.items); - defer self.a.free(json); - var output = std.ArrayList(u8).init(self.a); + const json = try cbor.toJsonAlloc(self.allocator, msg.items); + defer self.allocator.free(json); + var output = std.ArrayList(u8).init(self.allocator); defer output.deinit(); const writer = output.writer(); const terminator = "\r\n"; @@ -321,20 +321,20 @@ const Process = struct { const buf = try self.recv_buf.toOwnedSlice(); const data = buf[headers_end + sep.len .. headers_end + sep.len + headers.content_length]; const rest = buf[headers_end + sep.len + headers.content_length ..]; - defer self.a.free(buf); + defer self.allocator.free(buf); if (rest.len > 0) try self.recv_buf.appendSlice(rest); const message = .{ .body = data[0..headers.content_length] }; - const cb = try cbor.fromJsonAlloc(self.a, message.body); - defer self.a.free(cb); + const cb = try cbor.fromJsonAlloc(self.allocator, message.body); + defer self.allocator.free(cb); try self.receive_lsp_message(cb); if (rest.len > 0) return self.frame_message_recv(); } fn receive_lsp_request(self: *Process, id: i32, method: []const u8, params: ?[]const u8) !void { - const json = if (params) |p| try cbor.toJsonPrettyAlloc(self.a, p) else null; - defer if (json) |p| self.a.free(p); + const json = if (params) |p| try cbor.toJsonPrettyAlloc(self.allocator, p) else null; + defer if (json) |p| self.allocator.free(p); self.write_log("### RECV req: {d}\nmethod: {s}\n{s}\n###\n", .{ id, method, json orelse "no params" }); - var msg = std.ArrayList(u8).init(self.a); + var msg = std.ArrayList(u8).init(self.allocator); defer msg.deinit(); const writer = msg.writer(); try cbor.writeArrayHeader(writer, 7); @@ -349,13 +349,13 @@ const Process = struct { } fn receive_lsp_response(self: *Process, id: i32, result: ?[]const u8, err: ?[]const u8) !void { - const json = if (result) |p| try cbor.toJsonPrettyAlloc(self.a, p) else null; - defer if (json) |p| self.a.free(p); - const json_err = if (err) |p| try cbor.toJsonPrettyAlloc(self.a, p) else null; - defer if (json_err) |p| self.a.free(p); + const json = if (result) |p| try cbor.toJsonPrettyAlloc(self.allocator, p) else null; + defer if (json) |p| self.allocator.free(p); + const json_err = if (err) |p| try cbor.toJsonPrettyAlloc(self.allocator, p) else null; + defer if (json_err) |p| self.allocator.free(p); self.write_log("### RECV rsp: {d} {s}\n{s}\n###\n", .{ id, if (json_err) |_| "error" else "response", json_err orelse json orelse "no result" }); const from = self.requests.get(id) orelse return; - var msg = std.ArrayList(u8).init(self.a); + var msg = std.ArrayList(u8).init(self.allocator); defer msg.deinit(); const writer = msg.writer(); try cbor.writeArrayHeader(writer, 4); @@ -372,10 +372,10 @@ const Process = struct { } fn receive_lsp_notification(self: *Process, method: []const u8, params: ?[]const u8) !void { - const json = if (params) |p| try cbor.toJsonPrettyAlloc(self.a, p) else null; - defer if (json) |p| self.a.free(p); + const json = if (params) |p| try cbor.toJsonPrettyAlloc(self.allocator, p) else null; + defer if (json) |p| self.allocator.free(p); self.write_log("### RECV notify:\nmethod: {s}\n{s}\n###\n", .{ method, json orelse "no params" }); - var msg = std.ArrayList(u8).init(self.a); + var msg = std.ArrayList(u8).init(self.allocator); defer msg.deinit(); const writer = msg.writer(); try cbor.writeArrayHeader(writer, 6); diff --git a/src/Project.zig b/src/Project.zig index b0519d7..1bfdc25 100644 --- a/src/Project.zig +++ b/src/Project.zig @@ -10,7 +10,7 @@ const builtin = @import("builtin"); const LSP = @import("LSP.zig"); -a: std.mem.Allocator, +allocator: std.mem.Allocator, name: []const u8, files: std.ArrayList(File), pending: std.ArrayList(File), @@ -29,31 +29,31 @@ const File = struct { visited: bool = false, }; -pub fn init(a: std.mem.Allocator, name: []const u8) error{OutOfMemory}!Self { +pub fn init(allocator: std.mem.Allocator, name: []const u8) error{OutOfMemory}!Self { return .{ - .a = a, - .name = try a.dupe(u8, name), - .files = std.ArrayList(File).init(a), - .pending = std.ArrayList(File).init(a), + .allocator = allocator, + .name = try allocator.dupe(u8, name), + .files = std.ArrayList(File).init(allocator), + .pending = std.ArrayList(File).init(allocator), .open_time = std.time.milliTimestamp(), - .language_servers = std.StringHashMap(LSP).init(a), - .file_language_server = std.StringHashMap(LSP).init(a), + .language_servers = std.StringHashMap(LSP).init(allocator), + .file_language_server = std.StringHashMap(LSP).init(allocator), }; } pub fn deinit(self: *Self) void { var i_ = self.file_language_server.iterator(); while (i_.next()) |p| { - self.a.free(p.key_ptr.*); + self.allocator.free(p.key_ptr.*); } var i = self.language_servers.iterator(); while (i.next()) |p| { - self.a.free(p.key_ptr.*); + self.allocator.free(p.key_ptr.*); p.value_ptr.*.term(); } - for (self.files.items) |file| self.a.free(file.path); + for (self.files.items) |file| self.allocator.free(file.path); self.files.deinit(); - self.a.free(self.name); + self.allocator.free(self.name); } pub fn write_state(self: *Self, writer: anytype) !void { @@ -100,14 +100,14 @@ fn get_lsp(self: *Self, language_server: []const u8) !LSP { if (self.language_servers.get(language_server)) |lsp| return lsp; const logger = log.logger("lsp"); errdefer |e| logger.print_err("get_lsp", "failed to initialize LSP: {s} -> {any}", .{ fmt_lsp_name_func(language_server), e }); - const lsp = try LSP.open(self.a, self.name, .{ .buf = language_server }); - try self.language_servers.put(try self.a.dupe(u8, language_server), lsp); + const lsp = try LSP.open(self.allocator, self.name, .{ .buf = language_server }); + try self.language_servers.put(try self.allocator.dupe(u8, language_server), lsp); const uri = try self.make_URI(null); - defer self.a.free(uri); + defer self.allocator.free(uri); const basename_begin = std.mem.lastIndexOfScalar(u8, self.name, std.fs.path.sep); const basename = if (basename_begin) |begin| self.name[begin + 1 ..] else self.name; const response = try self.send_lsp_init_request(lsp, self.name, basename, uri); - defer self.a.free(response.buf); + defer self.allocator.free(response.buf); try lsp.send_notification("initialized", .{}); logger.print("initialized LSP: {s}", .{fmt_lsp_name_func(language_server)}); return lsp; @@ -125,7 +125,7 @@ fn get_file_lsp(self: *Self, file_path: []const u8) !LSP { } fn make_URI(self: *Self, file_path: ?[]const u8) ![]const u8 { - var buf = std.ArrayList(u8).init(self.a); + var buf = std.ArrayList(u8).init(self.allocator); if (file_path) |path| { if (std.fs.path.isAbsolute(path)) { try buf.writer().print("file://{s}", .{path}); @@ -164,8 +164,8 @@ fn simple_query_recent_files(self: *Self, from: tp.pid_ref, max: usize, query: [ for (self.files.items) |file| { if (file.path.len < query.len) continue; if (std.mem.indexOf(u8, file.path, query)) |idx| { - var matches = try self.a.alloc(usize, query.len); - defer self.a.free(matches); + var matches = try self.allocator.alloc(usize, query.len); + defer self.allocator.free(matches); var n: usize = 0; while (n < query.len) : (n += 1) matches[n] = idx + n; try from.send(.{ "PRJ", "recent", self.longest_file_path, file.path, matches }); @@ -182,7 +182,7 @@ pub fn query_recent_files(self: *Self, from: tp.pid_ref, max: usize, query: []co defer from.send(.{ "PRJ", "recent_done", self.longest_file_path, query }) catch {}; var searcher = try fuzzig.Ascii.init( - self.a, + self.allocator, 4096, // haystack max size 4096, // needle max size .{ .case_sensitive = false }, @@ -194,7 +194,7 @@ pub fn query_recent_files(self: *Self, from: tp.pid_ref, max: usize, query: []co score: i32, matches: []const usize, }; - var matches = std.ArrayList(Match).init(self.a); + var matches = std.ArrayList(Match).init(self.allocator); for (self.files.items) |file| { const match = searcher.scoreMatches(file.path, query); @@ -202,7 +202,7 @@ pub fn query_recent_files(self: *Self, from: tp.pid_ref, max: usize, query: []co (try matches.addOne()).* = .{ .path = file.path, .score = score, - .matches = try self.a.dupe(usize, match.matches), + .matches = try self.allocator.dupe(usize, match.matches), }; } } @@ -222,19 +222,19 @@ pub fn query_recent_files(self: *Self, from: tp.pid_ref, max: usize, query: []co pub fn add_pending_file(self: *Self, file_path: []const u8, mtime: i128) error{OutOfMemory}!void { self.longest_file_path = @max(self.longest_file_path, file_path.len); - (try self.pending.addOne()).* = .{ .path = try self.a.dupe(u8, file_path), .mtime = mtime }; + (try self.pending.addOne()).* = .{ .path = try self.allocator.dupe(u8, file_path), .mtime = mtime }; } pub fn merge_pending_files(self: *Self) error{OutOfMemory}!void { defer self.sort_files_by_mtime(); const existing = try self.files.toOwnedSlice(); self.files = self.pending; - self.pending = std.ArrayList(File).init(self.a); + self.pending = std.ArrayList(File).init(self.allocator); for (existing) |*file| { self.update_mru_internal(file.path, file.mtime, file.row, file.col) catch {}; - self.a.free(file.path); + self.allocator.free(file.path); } - self.a.free(existing); + self.allocator.free(existing); } pub fn update_mru(self: *Self, file_path: []const u8, row: usize, col: usize) !void { @@ -255,7 +255,7 @@ fn update_mru_internal(self: *Self, file_path: []const u8, mtime: i128, row: usi } if (row != 0) { (try self.files.addOne()).* = .{ - .path = try self.a.dupe(u8, file_path), + .path = try self.allocator.dupe(u8, file_path), .mtime = mtime, .row = row, .col = col, @@ -263,7 +263,7 @@ fn update_mru_internal(self: *Self, file_path: []const u8, mtime: i128, row: usi }; } else { (try self.files.addOne()).* = .{ - .path = try self.a.dupe(u8, file_path), + .path = try self.allocator.dupe(u8, file_path), .mtime = mtime, }; } @@ -282,11 +282,11 @@ pub fn did_open(self: *Self, file_path: []const u8, file_type: []const u8, langu self.update_mru(file_path, 0, 0) catch {}; const lsp = try self.get_lsp(language_server); if (!self.file_language_server.contains(file_path)) { - const key = try self.a.dupe(u8, file_path); + const key = try self.allocator.dupe(u8, file_path); try self.file_language_server.put(key, lsp); } const uri = try self.make_URI(file_path); - defer self.a.free(uri); + defer self.allocator.free(uri); try lsp.send_notification("textDocument/didOpen", .{ .textDocument = .{ .uri = uri, .languageId = file_type, .version = version, .text = text }, }); @@ -295,34 +295,34 @@ pub fn did_open(self: *Self, file_path: []const u8, file_type: []const u8, langu pub fn did_change(self: *Self, file_path: []const u8, version: usize, root_dst_addr: usize, root_src_addr: usize) !void { const lsp = try self.get_file_lsp(file_path); const uri = try self.make_URI(file_path); - defer self.a.free(uri); + defer self.allocator.free(uri); const root_dst: Buffer.Root = if (root_dst_addr == 0) return else @ptrFromInt(root_dst_addr); const root_src: Buffer.Root = if (root_src_addr == 0) return else @ptrFromInt(root_src_addr); var dizzy_edits = std.ArrayListUnmanaged(dizzy.Edit){}; - var dst = std.ArrayList(u8).init(self.a); - var src = std.ArrayList(u8).init(self.a); + var dst = std.ArrayList(u8).init(self.allocator); + var src = std.ArrayList(u8).init(self.allocator); var scratch = std.ArrayListUnmanaged(u32){}; - var edits_cb = std.ArrayList(u8).init(self.a); + var edits_cb = std.ArrayList(u8).init(self.allocator); const writer = edits_cb.writer(); defer { edits_cb.deinit(); dst.deinit(); src.deinit(); - scratch.deinit(self.a); - dizzy_edits.deinit(self.a); + scratch.deinit(self.allocator); + dizzy_edits.deinit(self.allocator); } try root_dst.store(dst.writer()); try root_src.store(src.writer()); const scratch_len = 4 * (dst.items.len + src.items.len) + 2; - try scratch.ensureTotalCapacity(self.a, scratch_len); + try scratch.ensureTotalCapacity(self.allocator, scratch_len); scratch.items.len = scratch_len; - try dizzy.PrimitiveSliceDiffer(u8).diff(self.a, &dizzy_edits, src.items, dst.items, scratch.items); + try dizzy.PrimitiveSliceDiffer(u8).diff(self.allocator, &dizzy_edits, src.items, dst.items, scratch.items); var lines_dst: usize = 0; var last_offset: usize = 0; @@ -361,7 +361,7 @@ pub fn did_change(self: *Self, file_path: []const u8, version: usize, root_dst_a } } - var msg = std.ArrayList(u8).init(self.a); + var msg = std.ArrayList(u8).init(self.allocator); defer msg.deinit(); const msg_writer = msg.writer(); try cbor.writeMapHeader(msg_writer, 2); @@ -389,7 +389,7 @@ fn scan_char(chars: []const u8, lines: *usize, char: u8, last_offset: ?*usize) v pub fn did_save(self: *Self, file_path: []const u8) !void { const lsp = try self.get_file_lsp(file_path); const uri = try self.make_URI(file_path); - defer self.a.free(uri); + defer self.allocator.free(uri); try lsp.send_notification("textDocument/didSave", .{ .textDocument = .{ .uri = uri }, }); @@ -398,7 +398,7 @@ pub fn did_save(self: *Self, file_path: []const u8) !void { pub fn did_close(self: *Self, file_path: []const u8) !void { const lsp = try self.get_file_lsp(file_path); const uri = try self.make_URI(file_path); - defer self.a.free(uri); + defer self.allocator.free(uri); try lsp.send_notification("textDocument/didClose", .{ .textDocument = .{ .uri = uri }, }); @@ -423,12 +423,12 @@ pub fn goto_type_definition(self: *Self, from: tp.pid_ref, file_path: []const u8 fn send_goto_request(self: *Self, from: tp.pid_ref, file_path: []const u8, row: usize, col: usize, method: []const u8) !void { const lsp = try self.get_file_lsp(file_path); const uri = try self.make_URI(file_path); - defer self.a.free(uri); - const response = try lsp.send_request(self.a, method, .{ + defer self.allocator.free(uri); + const response = try lsp.send_request(self.allocator, method, .{ .textDocument = .{ .uri = uri }, .position = .{ .line = row, .character = col }, }); - defer self.a.free(response.buf); + defer self.allocator.free(response.buf); var link: []const u8 = undefined; var locations: []const u8 = undefined; if (try response.match(.{ "child", tp.string, "result", tp.array })) { @@ -505,15 +505,15 @@ fn navigate_to_location_link(_: *Self, from: tp.pid_ref, location_link: []const pub fn references(self: *Self, from: tp.pid_ref, file_path: []const u8, row: usize, col: usize) !void { const lsp = try self.get_file_lsp(file_path); const uri = try self.make_URI(file_path); - defer self.a.free(uri); + defer self.allocator.free(uri); log.logger("lsp").print("finding references...", .{}); - const response = try lsp.send_request(self.a, "textDocument/references", .{ + const response = try lsp.send_request(self.allocator, "textDocument/references", .{ .textDocument = .{ .uri = uri }, .position = .{ .line = row, .character = col }, .context = .{ .includeDeclaration = true }, }); - defer self.a.free(response.buf); + defer self.allocator.free(response.buf); var locations: []const u8 = undefined; if (try response.match(.{ "child", tp.string, "result", tp.null_ })) { return; @@ -571,8 +571,8 @@ fn send_reference(self: *Self, to: tp.pid_ref, location: []const u8) !void { file_path[i] = '\\'; }; } - const line = try self.get_line_of_file(self.a, file_path, targetRange.?.start.line); - defer self.a.free(line); + const line = try self.get_line_of_file(self.allocator, file_path, targetRange.?.start.line); + defer self.allocator.free(line); const file_path_ = if (file_path.len > self.name.len and std.mem.eql(u8, self.name, file_path[0..self.name.len])) file_path[self.name.len + 1 ..] else @@ -591,12 +591,12 @@ fn send_reference(self: *Self, to: tp.pid_ref, location: []const u8) !void { pub fn completion(self: *Self, _: tp.pid_ref, file_path: []const u8, row: usize, col: usize) !void { const lsp = try self.get_file_lsp(file_path); const uri = try self.make_URI(file_path); - defer self.a.free(uri); - const response = try lsp.send_request(self.a, "textDocument/completion", .{ + defer self.allocator.free(uri); + const response = try lsp.send_request(self.allocator, "textDocument/completion", .{ .textDocument = .{ .uri = uri }, .position = .{ .line = row, .character = col }, }); - defer self.a.free(response.buf); + defer self.allocator.free(response.buf); } pub fn publish_diagnostics(self: *Self, to: tp.pid_ref, params_cb: []const u8) !void { @@ -750,7 +750,7 @@ pub fn show_message(_: *Self, _: tp.pid_ref, params_cb: []const u8) !void { } fn send_lsp_init_request(self: *Self, lsp: LSP, project_path: []const u8, project_basename: []const u8, project_uri: []const u8) !tp.message { - return lsp.send_request(self.a, "initialize", .{ + return lsp.send_request(self.allocator, "initialize", .{ .processId = if (builtin.os.tag == .linux) std.os.linux.getpid() else null, .rootPath = project_path, .rootUri = project_uri, @@ -1075,13 +1075,13 @@ fn format_lsp_name_func( const eol = '\n'; -fn get_line_of_file(self: *Self, a: std.mem.Allocator, file_path: []const u8, line_: usize) ![]const u8 { +fn get_line_of_file(self: *Self, allocator: std.mem.Allocator, file_path: []const u8, line_: usize) ![]const u8 { const line = line_ + 1; const file = try std.fs.cwd().openFile(file_path, .{ .mode = .read_only }); defer file.close(); const stat = try file.stat(); - var buf = try a.alloc(u8, @intCast(stat.size)); - defer a.free(buf); + var buf = try allocator.alloc(u8, @intCast(stat.size)); + defer allocator.free(buf); const read_size = try file.reader().readAll(buf); if (read_size != @as(@TypeOf(read_size), @intCast(stat.size))) @panic("get_line_of_file: buffer underrun"); @@ -1089,15 +1089,15 @@ fn get_line_of_file(self: *Self, a: std.mem.Allocator, file_path: []const u8, li var line_count: usize = 1; for (0..buf.len) |i| { if (line_count == line) - return self.get_line(a, buf[i..]); + return self.get_line(allocator, buf[i..]); if (buf[i] == eol) line_count += 1; } - return a.dupe(u8, ""); + return allocator.dupe(u8, ""); } -pub fn get_line(_: *Self, a: std.mem.Allocator, buf: []const u8) ![]const u8 { +pub fn get_line(_: *Self, allocator: std.mem.Allocator, buf: []const u8) ![]const u8 { for (0..buf.len) |i| { - if (buf[i] == eol) return a.dupe(u8, buf[0..i]); + if (buf[i] == eol) return allocator.dupe(u8, buf[0..i]); } - return a.dupe(u8, buf); + return allocator.dupe(u8, buf); } diff --git a/src/buffer/Buffer.zig b/src/buffer/Buffer.zig index 788c669..eec51ae 100644 --- a/src/buffer/Buffer.zig +++ b/src/buffer/Buffer.zig @@ -25,8 +25,8 @@ pub const Metrics = struct { }; arena: std.heap.ArenaAllocator, -a: Allocator, -external_a: Allocator, +allocator: Allocator, +external_allocator: Allocator, root: Root, leaves_buf: ?[]Node = null, file_buf: ?[]const u8 = null, @@ -111,7 +111,7 @@ pub const Branch = struct { return result; } - fn merge_results(self: *const Branch, a: Allocator, left: WalkerMut, right: WalkerMut) WalkerMut { + fn merge_results(self: *const Branch, allocator: Allocator, left: WalkerMut, right: WalkerMut) WalkerMut { var result = WalkerMut{}; result.err = if (left.err) |_| left.err else right.err; if (left.replace != null or right.replace != null) { @@ -122,7 +122,7 @@ pub const Branch = struct { else if (new_right.is_empty()) new_left else - Node.new(a, new_left, new_right) catch |e| return .{ .err = e }; + Node.new(allocator, new_left, new_right) catch |e| return .{ .err = e }; } result.keep_walking = left.keep_walking and right.keep_walking; result.found = left.found or right.found; @@ -135,10 +135,10 @@ pub const Leaf = struct { bol: bool = true, eol: bool = true, - fn new(a: Allocator, piece: []const u8, bol: bool, eol: bool) !*const Node { + fn new(allocator: Allocator, piece: []const u8, bol: bool, eol: bool) !*const Node { if (piece.len == 0) return if (!bol and !eol) &empty_leaf else if (bol and !eol) &empty_bol_leaf else if (!bol and eol) &empty_eol_leaf else &empty_line_leaf; - const node = try a.create(Node); + const node = try allocator.create(Node); node.* = .{ .leaf = .{ .buf = piece, .bol = bol, .eol = eol } }; return node; } @@ -242,8 +242,8 @@ const Node = union(enum) { const walker = *const fn (ctx: *anyopaque, node: *const Node) WalkerMut; - fn new(a: Allocator, l: *const Node, r: *const Node) !*const Node { - const node = try a.create(Node); + fn new(allocator: Allocator, l: *const Node, r: *const Node) !*const Node { + const node = try allocator.create(Node); const l_weights_sum = l.weights_sum(); var weights_sum_ = Weights{}; weights_sum_.add(l_weights_sum); @@ -279,24 +279,24 @@ const Node = union(enum) { }; } - pub fn rebalance(self: *const Node, a: Allocator, tmp_a: Allocator) !Root { + pub fn rebalance(self: *const Node, allocator: Allocator, tmp_allocator: Allocator) !Root { return if (self.is_balanced()) self else bal: { - const leaves = try self.collect_leaves(tmp_a); - defer tmp_a.free(leaves); - break :bal self.merge(leaves, a); + const leaves = try self.collect_leaves(tmp_allocator); + defer tmp_allocator.free(leaves); + break :bal self.merge(leaves, allocator); }; } - fn merge(self: *const Node, leaves: []*const Node, a: Allocator) !Root { + fn merge(self: *const Node, leaves: []*const Node, allocator: Allocator) !Root { const len = leaves.len; if (len == 1) { return leaves[0]; } if (len == 2) { - return Node.new(a, leaves[0], leaves[1]); + return Node.new(allocator, leaves[0], leaves[1]); } const mid = len / 2; - return Node.new(a, try self.merge(leaves[0..mid], a), try self.merge(leaves[mid..], a)); + return Node.new(allocator, try self.merge(leaves[0..mid], allocator), try self.merge(leaves[mid..], allocator)); } fn is_empty(self: *const Node) bool { @@ -316,8 +316,8 @@ const Node = union(enum) { } } - fn collect_leaves(self: *const Node, a: Allocator) ![]*const Node { - var leaves = ArrayList(*const Node).init(a); + fn collect_leaves(self: *const Node, allocator: Allocator) ![]*const Node { + var leaves = ArrayList(*const Node).init(allocator); try leaves.ensureTotalCapacity(self.lines()); try self.collect(&leaves); return leaves.toOwnedSlice(); @@ -340,21 +340,21 @@ const Node = union(enum) { } } - fn walk(self: *const Node, a: Allocator, f: WalkerMut.F, ctx: *anyopaque, metrics: Metrics) WalkerMut { + fn walk(self: *const Node, allocator: Allocator, f: WalkerMut.F, ctx: *anyopaque, metrics: Metrics) WalkerMut { switch (self.*) { .node => |*node| { - const left = node.left.walk(a, f, ctx, metrics); + const left = node.left.walk(allocator, f, ctx, metrics); if (!left.keep_walking) { var result = WalkerMut{}; result.err = left.err; result.found = left.found; if (left.replace) |p| { - result.replace = Node.new(a, p, node.right) catch |e| return .{ .err = e }; + result.replace = Node.new(allocator, p, node.right) catch |e| return .{ .err = e }; } return result; } - const right = node.right.walk(a, f, ctx, metrics); - return node.merge_results(a, left, right); + const right = node.right.walk(allocator, f, ctx, metrics); + return node.merge_results(allocator, left, right); }, .leaf => |*l| return f(ctx, l, metrics), } @@ -388,12 +388,12 @@ const Node = union(enum) { return result.found; } - fn walk_from_line_begin_internal(self: *const Node, a: Allocator, line: usize, f: WalkerMut.F, ctx: *anyopaque, metrics: Metrics) WalkerMut { + fn walk_from_line_begin_internal(self: *const Node, allocator: Allocator, line: usize, f: WalkerMut.F, ctx: *anyopaque, metrics: Metrics) WalkerMut { switch (self.*) { .node => |*node| { const left_bols = node.weights.bols; if (line >= left_bols) { - const right_result = node.right.walk_from_line_begin_internal(a, line - left_bols, f, ctx, metrics); + const right_result = node.right.walk_from_line_begin_internal(allocator, line - left_bols, f, ctx, metrics); if (right_result.replace) |p| { var result = WalkerMut{}; result.err = right_result.err; @@ -402,15 +402,15 @@ const Node = union(enum) { result.replace = if (p.is_empty()) node.left else - Node.new(a, node.left, p) catch |e| return .{ .err = e }; + Node.new(allocator, node.left, p) catch |e| return .{ .err = e }; return result; } else { return right_result; } } - const left_result = node.left.walk_from_line_begin_internal(a, line, f, ctx, metrics); - const right_result = if (left_result.found and left_result.keep_walking) node.right.walk(a, f, ctx, metrics) else WalkerMut{}; - return node.merge_results(a, left_result, right_result); + const left_result = node.left.walk_from_line_begin_internal(allocator, line, f, ctx, metrics); + const right_result = if (left_result.found and left_result.keep_walking) node.right.walk(allocator, f, ctx, metrics) else WalkerMut{}; + return node.merge_results(allocator, left_result, right_result); }, .leaf => |*l| { if (line == 0) { @@ -427,8 +427,8 @@ const Node = union(enum) { } } - pub fn walk_from_line_begin(self: *const Node, a: Allocator, line: usize, f: WalkerMut.F, ctx: *anyopaque, metrics: Metrics) !struct { bool, ?Root } { - const result = self.walk_from_line_begin_internal(a, line, f, ctx, metrics); + pub fn walk_from_line_begin(self: *const Node, allocator: Allocator, line: usize, f: WalkerMut.F, ctx: *anyopaque, metrics: Metrics) !struct { bool, ?Root } { + const result = self.walk_from_line_begin_internal(allocator, line, f, ctx, metrics); if (result.err) |e| return e; return .{ result.found, result.replace }; } @@ -608,15 +608,15 @@ const Node = union(enum) { return result orelse ""; } - pub fn delete_range(self: *const Node, sel: Selection, a: Allocator, size: ?*usize, metrics: Metrics) error{Stop}!Root { + pub fn delete_range(self: *const Node, sel: Selection, allocator: Allocator, size: ?*usize, metrics: Metrics) error{Stop}!Root { var wcwidth: usize = 0; _ = self.get_range(sel, null, size, &wcwidth, metrics) catch return error.Stop; - return self.del_chars(sel.begin.row, sel.begin.col, wcwidth, a, metrics) catch return error.Stop; + return self.del_chars(sel.begin.row, sel.begin.col, wcwidth, allocator, metrics) catch return error.Stop; } - pub fn del_chars(self: *const Node, line: usize, col: usize, count: usize, a: Allocator, metrics_: Metrics) !Root { + pub fn del_chars(self: *const Node, line: usize, col: usize, count: usize, allocator: Allocator, metrics_: Metrics) !Root { const Ctx = struct { - a: Allocator, + allocator: Allocator, col: usize, abs_col: usize = 0, count: usize, @@ -625,7 +625,7 @@ const Node = union(enum) { const ctx = @as(*@This(), @ptrCast(@alignCast(Ctx))); var result = WalkerMut.keep_walking; if (ctx.delete_next_bol and ctx.count == 0) { - result.replace = Leaf.new(ctx.a, leaf.buf, false, leaf.eol) catch |e| return .{ .err = e }; + result.replace = Leaf.new(ctx.allocator, leaf.buf, false, leaf.eol) catch |e| return .{ .err = e }; result.keep_walking = false; ctx.delete_next_bol = false; return result; @@ -645,23 +645,23 @@ const Node = union(enum) { if (ctx.col == 0) { if (ctx.count > leaf_wcwidth) { ctx.count -= leaf_wcwidth; - result.replace = Leaf.new(ctx.a, "", leaf_bol, false) catch |e| return .{ .err = e }; + result.replace = Leaf.new(ctx.allocator, "", leaf_bol, false) catch |e| return .{ .err = e }; if (leaf.eol) { ctx.count -= 1; ctx.delete_next_bol = true; } } else if (ctx.count == leaf_wcwidth) { - result.replace = Leaf.new(ctx.a, "", leaf_bol, leaf.eol) catch |e| return .{ .err = e }; + result.replace = Leaf.new(ctx.allocator, "", leaf_bol, leaf.eol) catch |e| return .{ .err = e }; ctx.count = 0; } else { const pos = leaf.width_to_pos(ctx.count, base_col, metrics) catch |e| return .{ .err = e }; - result.replace = Leaf.new(ctx.a, leaf.buf[pos..], leaf_bol, leaf.eol) catch |e| return .{ .err = e }; + result.replace = Leaf.new(ctx.allocator, leaf.buf[pos..], leaf_bol, leaf.eol) catch |e| return .{ .err = e }; ctx.count = 0; } } else if (ctx.col == leaf_wcwidth) { if (leaf.eol) { ctx.count -= 1; - result.replace = Leaf.new(ctx.a, leaf.buf, leaf_bol, false) catch |e| return .{ .err = e }; + result.replace = Leaf.new(ctx.allocator, leaf.buf, leaf_bol, false) catch |e| return .{ .err = e }; ctx.delete_next_bol = true; } ctx.col -= leaf_wcwidth; @@ -674,14 +674,14 @@ const Node = union(enum) { ctx.delete_next_bol = true; break :leaf_eol false; } else leaf.eol; - result.replace = Leaf.new(ctx.a, leaf.buf[0..pos], leaf_bol, leaf_eol) catch |e| return .{ .err = e }; + result.replace = Leaf.new(ctx.allocator, leaf.buf[0..pos], leaf_bol, leaf_eol) catch |e| return .{ .err = e }; ctx.col = 0; } else { const pos = leaf.width_to_pos(ctx.col, base_col, metrics) catch |e| return .{ .err = e }; const pos_end = leaf.width_to_pos(ctx.col + ctx.count, base_col, metrics) catch |e| return .{ .err = e }; - const left = Leaf.new(ctx.a, leaf.buf[0..pos], leaf_bol, false) catch |e| return .{ .err = e }; - const right = Leaf.new(ctx.a, leaf.buf[pos_end..], false, leaf.eol) catch |e| return .{ .err = e }; - result.replace = Node.new(ctx.a, left, right) catch |e| return .{ .err = e }; + const left = Leaf.new(ctx.allocator, leaf.buf[0..pos], leaf_bol, false) catch |e| return .{ .err = e }; + const right = Leaf.new(ctx.allocator, leaf.buf[pos_end..], false, leaf.eol) catch |e| return .{ .err = e }; + result.replace = Node.new(ctx.allocator, left, right) catch |e| return .{ .err = e }; ctx.count = 0; } } @@ -691,21 +691,21 @@ const Node = union(enum) { return result; } }; - var ctx: Ctx = .{ .a = a, .col = col, .count = count }; - const found, const root = try self.walk_from_line_begin(a, line, Ctx.walker, &ctx, metrics_); + var ctx: Ctx = .{ .allocator = allocator, .col = col, .count = count }; + const found, const root = try self.walk_from_line_begin(allocator, line, Ctx.walker, &ctx, metrics_); return if (found) (root orelse error.Stop) else error.NotFound; } - fn merge_in_place(leaves: []const Node, a: Allocator) !Root { + fn merge_in_place(leaves: []const Node, allocator: Allocator) !Root { const len = leaves.len; if (len == 1) { return &leaves[0]; } if (len == 2) { - return Node.new(a, &leaves[0], &leaves[1]); + return Node.new(allocator, &leaves[0], &leaves[1]); } const mid = len / 2; - return Node.new(a, try merge_in_place(leaves[0..mid], a), try merge_in_place(leaves[mid..], a)); + return Node.new(allocator, try merge_in_place(leaves[0..mid], allocator), try merge_in_place(leaves[mid..], allocator)); } pub fn get_line(self: *const Node, line: usize, result: *ArrayList(u8), metrics: Metrics) !void { @@ -756,12 +756,12 @@ const Node = union(enum) { line_: usize, col_: usize, s: []const u8, - a: Allocator, + allocator: Allocator, metrics_: Metrics, ) !struct { usize, usize, Root } { var self = self_; const Ctx = struct { - a: Allocator, + allocator: Allocator, col: usize, abs_col: usize = 0, s: []const u8, @@ -774,46 +774,46 @@ const Node = union(enum) { Ctx.abs_col += leaf_wcwidth; if (Ctx.col == 0) { - const left = Leaf.new(Ctx.a, Ctx.s, leaf.bol, Ctx.eol) catch |e| return .{ .err = e }; - const right = Leaf.new(Ctx.a, leaf.buf, Ctx.eol, leaf.eol) catch |e| return .{ .err = e }; - return .{ .replace = Node.new(Ctx.a, left, right) catch |e| return .{ .err = e } }; + const left = Leaf.new(Ctx.allocator, Ctx.s, leaf.bol, Ctx.eol) catch |e| return .{ .err = e }; + const right = Leaf.new(Ctx.allocator, leaf.buf, Ctx.eol, leaf.eol) catch |e| return .{ .err = e }; + return .{ .replace = Node.new(Ctx.allocator, left, right) catch |e| return .{ .err = e } }; } if (leaf_wcwidth == Ctx.col) { if (leaf.eol and Ctx.eol and Ctx.s.len == 0) { - const left = Leaf.new(Ctx.a, leaf.buf, leaf.bol, true) catch |e| return .{ .err = e }; - const right = Leaf.new(Ctx.a, Ctx.s, true, true) catch |e| return .{ .err = e }; - return .{ .replace = Node.new(Ctx.a, left, right) catch |e| return .{ .err = e } }; + const left = Leaf.new(Ctx.allocator, leaf.buf, leaf.bol, true) catch |e| return .{ .err = e }; + const right = Leaf.new(Ctx.allocator, Ctx.s, true, true) catch |e| return .{ .err = e }; + return .{ .replace = Node.new(Ctx.allocator, left, right) catch |e| return .{ .err = e } }; } - const left = Leaf.new(Ctx.a, leaf.buf, leaf.bol, false) catch |e| return .{ .err = e }; + const left = Leaf.new(Ctx.allocator, leaf.buf, leaf.bol, false) catch |e| return .{ .err = e }; if (Ctx.eol) { - const middle = Leaf.new(Ctx.a, Ctx.s, false, Ctx.eol) catch |e| return .{ .err = e }; - const right = Leaf.new(Ctx.a, "", Ctx.eol, leaf.eol) catch |e| return .{ .err = e }; + const middle = Leaf.new(Ctx.allocator, Ctx.s, false, Ctx.eol) catch |e| return .{ .err = e }; + const right = Leaf.new(Ctx.allocator, "", Ctx.eol, leaf.eol) catch |e| return .{ .err = e }; return .{ .replace = Node.new( - Ctx.a, + Ctx.allocator, left, - Node.new(Ctx.a, middle, right) catch |e| return .{ .err = e }, + Node.new(Ctx.allocator, middle, right) catch |e| return .{ .err = e }, ) catch |e| return .{ .err = e } }; } else { - const right = Leaf.new(Ctx.a, Ctx.s, false, leaf.eol) catch |e| return .{ .err = e }; - return .{ .replace = Node.new(Ctx.a, left, right) catch |e| return .{ .err = e } }; + const right = Leaf.new(Ctx.allocator, Ctx.s, false, leaf.eol) catch |e| return .{ .err = e }; + return .{ .replace = Node.new(Ctx.allocator, left, right) catch |e| return .{ .err = e } }; } } if (leaf_wcwidth > Ctx.col) { const pos = leaf.width_to_pos(Ctx.col, base_col, metrics) catch |e| return .{ .err = e }; if (Ctx.eol and Ctx.s.len == 0) { - const left = Leaf.new(Ctx.a, leaf.buf[0..pos], leaf.bol, Ctx.eol) catch |e| return .{ .err = e }; - const right = Leaf.new(Ctx.a, leaf.buf[pos..], Ctx.eol, leaf.eol) catch |e| return .{ .err = e }; - return .{ .replace = Node.new(Ctx.a, left, right) catch |e| return .{ .err = e } }; + const left = Leaf.new(Ctx.allocator, leaf.buf[0..pos], leaf.bol, Ctx.eol) catch |e| return .{ .err = e }; + const right = Leaf.new(Ctx.allocator, leaf.buf[pos..], Ctx.eol, leaf.eol) catch |e| return .{ .err = e }; + return .{ .replace = Node.new(Ctx.allocator, left, right) catch |e| return .{ .err = e } }; } - const left = Leaf.new(Ctx.a, leaf.buf[0..pos], leaf.bol, false) catch |e| return .{ .err = e }; - const middle = Leaf.new(Ctx.a, Ctx.s, false, Ctx.eol) catch |e| return .{ .err = e }; - const right = Leaf.new(Ctx.a, leaf.buf[pos..], Ctx.eol, leaf.eol) catch |e| return .{ .err = e }; + const left = Leaf.new(Ctx.allocator, leaf.buf[0..pos], leaf.bol, false) catch |e| return .{ .err = e }; + const middle = Leaf.new(Ctx.allocator, Ctx.s, false, Ctx.eol) catch |e| return .{ .err = e }; + const right = Leaf.new(Ctx.allocator, leaf.buf[pos..], Ctx.eol, leaf.eol) catch |e| return .{ .err = e }; return .{ .replace = Node.new( - Ctx.a, + Ctx.allocator, left, - Node.new(Ctx.a, middle, right) catch |e| return .{ .err = e }, + Node.new(Ctx.allocator, middle, right) catch |e| return .{ .err = e }, ) catch |e| return .{ .err = e } }; } @@ -822,7 +822,7 @@ const Node = union(enum) { } }; if (s.len == 0) return error.Stop; - var rest = try a.dupe(u8, s); + var rest = try allocator.dupe(u8, s); var chunk = rest; var line = line_; var col = col_; @@ -837,8 +837,8 @@ const Node = union(enum) { rest = &[_]u8{}; need_eol = false; } - var ctx: Ctx = .{ .a = a, .col = col, .s = chunk, .eol = need_eol }; - const found, const replace = try self.walk_from_line_begin(a, line, Ctx.walker, &ctx, metrics_); + var ctx: Ctx = .{ .allocator = allocator, .col = col, .s = chunk, .eol = need_eol }; + const found, const replace = try self.walk_from_line_begin(allocator, line, Ctx.walker, &ctx, metrics_); if (!found) return error.NotFound; if (replace) |root| self = root; if (need_eol) { @@ -866,7 +866,7 @@ const Node = union(enum) { } pub const FindAllCallback = fn (data: *anyopaque, begin_row: usize, begin_col: usize, end_row: usize, end_col: usize) error{Stop}!void; - pub fn find_all_ranges(self: *const Node, pattern: []const u8, data: *anyopaque, callback: *const FindAllCallback, a: Allocator) !void { + pub fn find_all_ranges(self: *const Node, pattern: []const u8, data: *anyopaque, callback: *const FindAllCallback, allocator: Allocator) !void { const Ctx = struct { pattern: []const u8, data: *anyopaque, @@ -932,9 +932,9 @@ const Node = union(enum) { .pattern = pattern, .data = data, .callback = callback, - .buf = try a.alloc(u8, pattern.len * 2), + .buf = try allocator.alloc(u8, pattern.len * 2), }; - defer a.free(ctx.buf); + defer allocator.free(ctx.buf); return self.store(ctx.writer()); } @@ -1012,33 +1012,33 @@ const Node = union(enum) { } }; -pub fn create(a: Allocator) !*Self { - const self = try a.create(Self); - const arena_a = if (builtin.is_test) a else std.heap.page_allocator; +pub fn create(allocator: Allocator) !*Self { + const self = try allocator.create(Self); + const arena_a = if (builtin.is_test) allocator else std.heap.page_allocator; self.* = .{ .arena = std.heap.ArenaAllocator.init(arena_a), - .a = self.arena.allocator(), - .external_a = a, - .root = try Node.new(self.a, &empty_leaf, &empty_leaf), + .allocator = self.arena.allocator(), + .external_allocator = allocator, + .root = try Node.new(self.allocator, &empty_leaf, &empty_leaf), }; return self; } pub fn deinit(self: *Self) void { - if (self.file_buf) |buf| self.external_a.free(buf); - if (self.leaves_buf) |buf| self.external_a.free(buf); + if (self.file_buf) |buf| self.external_allocator.free(buf); + if (self.leaves_buf) |buf| self.external_allocator.free(buf); self.arena.deinit(); - self.external_a.destroy(self); + self.external_allocator.destroy(self); } fn new_file(self: *const Self, file_exists: *bool) !Root { file_exists.* = false; - return Leaf.new(self.a, "", true, false); + return Leaf.new(self.allocator, "", true, false); } pub fn load(self: *const Self, reader: anytype, size: usize) !Root { const eol = '\n'; - var buf = try self.external_a.alloc(u8, size); + var buf = try self.external_allocator.alloc(u8, size); const self_ = @constCast(self); self_.file_buf = buf; const read_size = try reader.readAll(buf); @@ -1053,7 +1053,7 @@ pub fn load(self: *const Self, reader: anytype, size: usize) !Root { if (buf[i] == eol) leaf_count += 1; } - var leaves = try self.external_a.alloc(Node, leaf_count); + var leaves = try self.external_allocator.alloc(Node, leaf_count); self_.leaves_buf = leaves; var cur_leaf: usize = 0; var b: usize = 0; @@ -1069,7 +1069,7 @@ pub fn load(self: *const Self, reader: anytype, size: usize) !Root { leaves[cur_leaf] = .{ .leaf = .{ .buf = line, .bol = true, .eol = false } }; if (leaves.len != cur_leaf + 1) return error.Unexpected; - return Node.merge_in_place(leaves, self.a); + return Node.merge_in_place(leaves, self.allocator); } pub fn load_from_string(self: *const Self, s: []const u8) !Root { @@ -1079,7 +1079,7 @@ pub fn load_from_string(self: *const Self, s: []const u8) !Root { pub fn load_from_string_and_update(self: *Self, file_path: []const u8, s: []const u8) !void { self.root = try self.load_from_string(s); - self.file_path = try self.a.dupe(u8, file_path); + self.file_path = try self.allocator.dupe(u8, file_path); self.last_save = self.root; self.file_exists = false; } @@ -1099,13 +1099,13 @@ pub fn load_from_file(self: *const Self, file_path: []const u8, file_exists: *bo pub fn load_from_file_and_update(self: *Self, file_path: []const u8) !void { var file_exists: bool = false; self.root = try self.load_from_file(file_path, &file_exists); - self.file_path = try self.a.dupe(u8, file_path); + self.file_path = try self.allocator.dupe(u8, file_path); self.last_save = self.root; self.file_exists = file_exists; } -pub fn store_to_string(self: *const Self, a: Allocator) ![]u8 { - var s = try ArrayList(u8).initCapacity(a, self.root.weights_sum().len); +pub fn store_to_string(self: *const Self, allocator: Allocator) ![]u8 { + var s = try ArrayList(u8).initCapacity(allocator, self.root.weights_sum().len); try self.root.store(s.writer()); return s.toOwnedSlice(); } @@ -1169,8 +1169,8 @@ pub fn store_undo(self: *Self, meta: []const u8) !void { } fn create_undo(self: *const Self, root: Root, meta_: []const u8) !*UndoNode { - const h = try self.a.create(UndoNode); - const meta = try self.a.dupe(u8, meta_); + const h = try self.allocator.create(UndoNode); + const meta = try self.allocator.dupe(u8, meta_); h.* = UndoNode{ .root = root, .meta = meta, @@ -1194,7 +1194,7 @@ fn push_redo_branch(self: *Self) !void { const r = self.redo_history orelse return; const u = self.undo_history orelse return; const next = u.branches; - const b = try self.a.create(UndoBranch); + const b = try self.allocator.create(UndoBranch); b.* = .{ .redo = r, .next = next, diff --git a/src/diff.zig b/src/diff.zig index 8e4d61d..d1ff6dd 100644 --- a/src/diff.zig +++ b/src/diff.zig @@ -32,7 +32,7 @@ pub fn deinit(self: *Self) void { const Process = struct { arena: std.heap.ArenaAllocator, - a: std.mem.Allocator, + allocator: std.mem.Allocator, receiver: Receiver, const Receiver = tp.Receiver(*Process); @@ -42,10 +42,10 @@ const Process = struct { const self = try outer_a.create(Process); self.* = .{ .arena = std.heap.ArenaAllocator.init(outer_a), - .a = self.arena.allocator(), + .allocator = self.arena.allocator(), .receiver = Receiver.init(Process.receive, self), }; - return tp.spawn_link(self.a, self, Process.start, module_name); + return tp.spawn_link(self.allocator, self, Process.start, module_name); } fn start(self: *Process) tp.result { @@ -79,26 +79,26 @@ const Process = struct { const root_src: Buffer.Root = if (root_old_addr == 0) return else @ptrFromInt(root_old_addr); var dizzy_edits = std.ArrayListUnmanaged(dizzy.Edit){}; - var dst = std.ArrayList(u8).init(self.a); - var src = std.ArrayList(u8).init(self.a); + var dst = std.ArrayList(u8).init(self.allocator); + var src = std.ArrayList(u8).init(self.allocator); var scratch = std.ArrayListUnmanaged(u32){}; - var edits = std.ArrayList(Edit).init(self.a); + var edits = std.ArrayList(Edit).init(self.allocator); defer { dst.deinit(); src.deinit(); - scratch.deinit(self.a); - dizzy_edits.deinit(self.a); + scratch.deinit(self.allocator); + dizzy_edits.deinit(self.allocator); } try root_dst.store(dst.writer()); try root_src.store(src.writer()); const scratch_len = 4 * (dst.items.len + src.items.len) + 2; - try scratch.ensureTotalCapacity(self.a, scratch_len); + try scratch.ensureTotalCapacity(self.allocator, scratch_len); scratch.items.len = scratch_len; - try dizzy.PrimitiveSliceDiffer(u8).diff(self.a, &dizzy_edits, src.items, dst.items, scratch.items); + try dizzy.PrimitiveSliceDiffer(u8).diff(self.allocator, &dizzy_edits, src.items, dst.items, scratch.items); if (dizzy_edits.items.len > 2) try edits.ensureTotalCapacity((dizzy_edits.items.len - 1) / 2); diff --git a/src/location_history.zig b/src/location_history.zig index 951ba01..c64c43f 100644 --- a/src/location_history.zig +++ b/src/location_history.zig @@ -30,7 +30,7 @@ pub fn deinit(self: *Self) void { const Process = struct { arena: std.heap.ArenaAllocator, - a: std.mem.Allocator, + allocator: std.mem.Allocator, backwards: std.ArrayList(Entry), current: ?Entry = null, forwards: std.ArrayList(Entry), @@ -49,12 +49,12 @@ const Process = struct { const self = try outer_a.create(Process); self.* = .{ .arena = std.heap.ArenaAllocator.init(outer_a), - .a = self.arena.allocator(), - .backwards = std.ArrayList(Entry).init(self.a), - .forwards = std.ArrayList(Entry).init(self.a), + .allocator = self.arena.allocator(), + .backwards = std.ArrayList(Entry).init(self.allocator), + .forwards = std.ArrayList(Entry).init(self.allocator), .receiver = Receiver.init(Process.receive, self), }; - return tp.spawn_link(self.a, self, Process.start, module_name); + return tp.spawn_link(self.allocator, self, Process.start, module_name); } fn start(self: *Process) tp.result { @@ -67,7 +67,7 @@ const Process = struct { self.clear_forwards(); self.backwards.deinit(); self.forwards.deinit(); - if (self.current) |entry| self.a.free(entry.file_path); + if (self.current) |entry| self.allocator.free(entry.file_path); self.arena.deinit(); outer_a.destroy(self); } @@ -81,7 +81,7 @@ const Process = struct { } fn clear_table(self: *Process, table: *std.ArrayList(Entry)) void { - for (table.items) |entry| self.a.free(entry.file_path); + for (table.items) |entry| self.allocator.free(entry.file_path); table.clearAndFree(); } @@ -111,25 +111,25 @@ const Process = struct { fn update(self: *Process, entry_: Entry) !void { const entry: Entry = .{ - .file_path = try self.a.dupe(u8, entry_.file_path), + .file_path = try self.allocator.dupe(u8, entry_.file_path), .cursor = entry_.cursor, .selection = entry_.selection, }; - errdefer self.a.free(entry.file_path); + errdefer self.allocator.free(entry.file_path); defer self.current = entry; if (isdupe(self.current, entry)) - return self.a.free(self.current.?.file_path); + return self.allocator.free(self.current.?.file_path); if (isdupe(self.backwards.getLastOrNull(), entry)) { if (self.current) |current| self.forwards.append(current) catch {}; const top = self.backwards.pop(); - self.a.free(top.file_path); + self.allocator.free(top.file_path); tp.trace(tp.channel.all, tp.message.fmt(.{ "location", "back", entry.file_path, entry.cursor.row, entry.cursor.col, self.backwards.items.len, self.forwards.items.len })); } else if (isdupe(self.forwards.getLastOrNull(), entry)) { if (self.current) |current| self.backwards.append(current) catch {}; const top = self.forwards.pop(); - self.a.free(top.file_path); + self.allocator.free(top.file_path); tp.trace(tp.channel.all, tp.message.fmt(.{ "location", "forward", entry.file_path, entry.cursor.row, entry.cursor.col, self.backwards.items.len, self.forwards.items.len })); } else if (self.current) |current| { try self.backwards.append(current); diff --git a/src/log.zig b/src/log.zig index 5f502dc..e551466 100644 --- a/src/log.zig +++ b/src/log.zig @@ -8,7 +8,7 @@ const Self = @This(); pub const max_log_message = tp.max_message_size - 128; -a: std.mem.Allocator, +allocator: std.mem.Allocator, receiver: Receiver, subscriber: ?tp.pid, heap: [32 + 1024]u8, @@ -19,11 +19,11 @@ const MsgStoreT = std.DoublyLinkedList([]u8); const Receiver = tp.Receiver(*Self); const StartArgs = struct { - a: std.mem.Allocator, + allocator: std.mem.Allocator, }; -pub fn spawn(ctx: *tp.context, a: std.mem.Allocator, env: ?*const tp.env) !tp.pid { - return try ctx.spawn_link(StartArgs{ .a = a }, Self.start, "log", null, env); +pub fn spawn(ctx: *tp.context, allocator: std.mem.Allocator, env: ?*const tp.env) !tp.pid { + return try ctx.spawn_link(StartArgs{ .allocator = allocator }, Self.start, "log", null, env); } fn start(args: StartArgs) tp.result { @@ -34,9 +34,9 @@ fn start(args: StartArgs) tp.result { } fn init(args: StartArgs) !*Self { - var p = try args.a.create(Self); + var p = try args.allocator.create(Self); p.* = .{ - .a = args.a, + .allocator = args.allocator, .receiver = Receiver.init(Self.receive, p), .subscriber = null, .heap = undefined, @@ -48,7 +48,7 @@ fn init(args: StartArgs) !*Self { fn deinit(self: *const Self) void { if (self.subscriber) |*s| s.deinit(); - self.a.destroy(self); + self.allocator.destroy(self); } fn log(msg: []const u8) void { @@ -56,9 +56,9 @@ fn log(msg: []const u8) void { } fn store(self: *Self, m: tp.message) void { - const a: std.mem.Allocator = self.fba.allocator(); - const buf: []u8 = a.alloc(u8, m.len()) catch return; - var node: *MsgStoreT.Node = a.create(MsgStoreT.Node) catch return; + const allocator: std.mem.Allocator = self.fba.allocator(); + const buf: []u8 = allocator.alloc(u8, m.len()) catch return; + var node: *MsgStoreT.Node = allocator.create(MsgStoreT.Node) catch return; node.data = buf; @memcpy(buf, m.buf); self.msg_store.append(node); diff --git a/src/main.zig b/src/main.zig index ebbcf97..87247d5 100644 --- a/src/main.zig +++ b/src/main.zig @@ -349,21 +349,21 @@ pub fn exit(status: u8) noreturn { const config = @import("config"); -pub fn read_config(a: std.mem.Allocator, buf: *?[]const u8) config { +pub fn read_config(allocator: std.mem.Allocator, buf: *?[]const u8) config { const file_name = get_app_config_file_name(application_name) catch return .{}; - return read_json_config_file(a, file_name, buf) catch .{}; + return read_json_config_file(allocator, file_name, buf) catch .{}; } -fn read_json_config_file(a: std.mem.Allocator, file_name: []const u8, buf: *?[]const u8) !config { +fn read_json_config_file(allocator: std.mem.Allocator, file_name: []const u8, buf: *?[]const u8) !config { const cbor = @import("cbor"); var file = std.fs.openFileAbsolute(file_name, .{ .mode = .read_only }) catch |e| switch (e) { error.FileNotFound => return .{}, else => return e, }; defer file.close(); - const json = try file.readToEndAlloc(a, 64 * 1024); - defer a.free(json); - const cbor_buf: []u8 = try a.alloc(u8, json.len); + const json = try file.readToEndAlloc(allocator, 64 * 1024); + defer allocator.free(json); + const cbor_buf: []u8 = try allocator.alloc(u8, json.len); buf.* = cbor_buf; const cb = try cbor.fromJson(json, cbor_buf); var iter = cb; @@ -383,16 +383,16 @@ fn read_json_config_file(a: std.mem.Allocator, file_name: []const u8, buf: *?[]c return data; } -pub fn write_config(conf: config, a: std.mem.Allocator) !void { - return write_json_file(config, conf, a, try get_app_config_file_name(application_name)); +pub fn write_config(conf: config, allocator: std.mem.Allocator) !void { + return write_json_file(config, conf, allocator, try get_app_config_file_name(application_name)); } -fn write_json_file(comptime T: type, data: T, a: std.mem.Allocator, file_name: []const u8) !void { +fn write_json_file(comptime T: type, data: T, allocator: std.mem.Allocator, file_name: []const u8) !void { const cbor = @import("cbor"); var file = try std.fs.createFileAbsolute(file_name, .{ .truncate = true }); defer file.close(); - var cb = std.ArrayList(u8).init(a); + var cb = std.ArrayList(u8).init(allocator); defer cb.deinit(); try cbor.writeValue(cb.writer(), data); diff --git a/src/project_manager.zig b/src/project_manager.zig index 157e322..eb34ffc 100644 --- a/src/project_manager.zig +++ b/src/project_manager.zig @@ -45,14 +45,14 @@ pub fn open(rel_project_directory: []const u8) !void { return (try get()).pid.send(.{ "open", project_directory }); } -pub fn request_most_recent_file(a: std.mem.Allocator) !?[]const u8 { +pub fn request_most_recent_file(allocator: std.mem.Allocator) !?[]const u8 { const project = tp.env.get().str("project"); if (project.len == 0) return tp.exit("No project"); - const rsp = try (try get()).pid.call(a, request_timeout, .{ "request_most_recent_file", project }); - defer a.free(rsp.buf); + const rsp = try (try get()).pid.call(allocator, request_timeout, .{ "request_most_recent_file", project }); + defer allocator.free(rsp.buf); var file_path: []const u8 = undefined; - return if (try rsp.match(.{tp.extract(&file_path)})) try a.dupe(u8, file_path) else null; + return if (try rsp.match(.{tp.extract(&file_path)})) try allocator.dupe(u8, file_path) else null; } pub fn request_recent_files(max: usize) !void { @@ -62,9 +62,9 @@ pub fn request_recent_files(max: usize) !void { return (try get()).pid.send(.{ "request_recent_files", project, max }); } -pub fn request_recent_projects(a: std.mem.Allocator) !tp.message { +pub fn request_recent_projects(allocator: std.mem.Allocator) !tp.message { const project = tp.env.get().str("project"); - return (try get()).pid.call(a, request_timeout, .{ "request_recent_projects", project }); + return (try get()).pid.call(allocator, request_timeout, .{ "request_recent_projects", project }); } pub fn query_recent_files(max: usize, query: []const u8) !void { @@ -167,7 +167,7 @@ pub fn get_mru_position(file_path: []const u8) !void { } const Process = struct { - a: std.mem.Allocator, + allocator: std.mem.Allocator, parent: tp.pid, logger: log.Logger, receiver: Receiver, @@ -182,29 +182,29 @@ const Process = struct { }; fn create() !tp.pid { - const a = std.heap.c_allocator; - const self = try a.create(Process); + const allocator = std.heap.c_allocator; + const self = try allocator.create(Process); self.* = .{ - .a = a, + .allocator = allocator, .parent = tp.self_pid().clone(), .logger = log.logger(module_name), .receiver = Receiver.init(Process.receive, self), - .projects = ProjectsMap.init(a), + .projects = ProjectsMap.init(allocator), }; - return tp.spawn_link(self.a, self, Process.start, module_name); + return tp.spawn_link(self.allocator, self, Process.start, module_name); } fn deinit(self: *Process) void { var i = self.projects.iterator(); while (i.next()) |p| { - self.a.free(p.key_ptr.*); + self.allocator.free(p.key_ptr.*); p.value_ptr.*.deinit(); - self.a.destroy(p.value_ptr.*); + self.allocator.destroy(p.value_ptr.*); } self.projects.deinit(); self.parent.deinit(); self.logger.deinit(); - self.a.destroy(self); + self.allocator.destroy(self); } fn start(self: *Process) tp.result { @@ -313,10 +313,10 @@ const Process = struct { fn open(self: *Process, project_directory: []const u8) !void { if (self.projects.get(project_directory) == null) { self.logger.print("opening: {s}", .{project_directory}); - const project = try self.a.create(Project); - project.* = try Project.init(self.a, project_directory); - try self.projects.put(try self.a.dupe(u8, project_directory), project); - self.walker = try walk_tree_async(self.a, project_directory); + const project = try self.allocator.create(Project); + project.* = try Project.init(self.allocator, project_directory); + try self.projects.put(try self.allocator.dupe(u8, project_directory), project); + self.walker = try walk_tree_async(self.allocator, project_directory); self.restore_project(project) catch |e| self.logger.err("restore_project", e); project.sort_files_by_mtime(); } else { @@ -347,11 +347,11 @@ const Process = struct { } fn request_recent_projects(self: *Process, from: tp.pid_ref, project_directory: []const u8) error{ OutOfMemory, Exit }!void { - var recent_projects = std.ArrayList(RecentProject).init(self.a); + var recent_projects = std.ArrayList(RecentProject).init(self.allocator); defer recent_projects.deinit(); self.load_recent_projects(&recent_projects, project_directory) catch {}; self.sort_projects_by_last_used(&recent_projects); - var message = std.ArrayList(u8).init(self.a); + var message = std.ArrayList(u8).init(self.allocator); const writer = message.writer(); try cbor.writeArrayHeader(writer, recent_projects.items.len); for (recent_projects.items) |project| @@ -370,7 +370,7 @@ const Process = struct { fn request_path_files(self: *Process, from: tp.pid_ref, project_directory: []const u8, max: usize, path: []const u8) error{ OutOfMemory, Exit }!void { const project = self.projects.get(project_directory) orelse return tp.exit("No project"); - request_path_files_async(self.a, from, project, max, path) catch |e| return tp.exit_error(e, @errorReturnTrace()); + request_path_files_async(self.allocator, from, project, max, path) catch |e| return tp.exit_error(e, @errorReturnTrace()); } fn did_open(self: *Process, project_directory: []const u8, file_path: []const u8, file_type: []const u8, language_server: []const u8, version: usize, text: []const u8) !void { @@ -484,8 +484,8 @@ const Process = struct { fn persist_project(self: *Process, project: *Project) !void { self.logger.print("saving: {s}", .{project.name}); - const file_name = try get_project_state_file_path(self.a, project); - defer self.a.free(file_name); + const file_name = try get_project_state_file_path(self.allocator, project); + defer self.allocator.free(file_name); var file = try std.fs.createFileAbsolute(file_name, .{ .truncate = true }); defer file.close(); var buffer = std.io.bufferedWriter(file.writer()); @@ -494,23 +494,23 @@ const Process = struct { } fn restore_project(self: *Process, project: *Project) !void { - const file_name = try get_project_state_file_path(self.a, project); - defer self.a.free(file_name); + const file_name = try get_project_state_file_path(self.allocator, project); + defer self.allocator.free(file_name); var file = std.fs.openFileAbsolute(file_name, .{ .mode = .read_only }) catch |e| switch (e) { error.FileNotFound => return, else => return e, }; defer file.close(); const stat = try file.stat(); - var buffer = try self.a.alloc(u8, @intCast(stat.size)); - defer self.a.free(buffer); + var buffer = try self.allocator.alloc(u8, @intCast(stat.size)); + defer self.allocator.free(buffer); const size = try file.readAll(buffer); try project.restore_state(buffer[0..size]); } - fn get_project_state_file_path(a: std.mem.Allocator, project: *Project) ![]const u8 { + fn get_project_state_file_path(allocator: std.mem.Allocator, project: *Project) ![]const u8 { const path = project.name; - var stream = std.ArrayList(u8).init(a); + var stream = std.ArrayList(u8).init(allocator); const writer = stream.writer(); _ = try writer.write(try root.get_state_dir()); _ = try writer.writeByte(std.fs.path.sep); @@ -532,7 +532,7 @@ const Process = struct { } fn load_recent_projects(self: *Process, recent_projects: *std.ArrayList(RecentProject), project_directory: []const u8) !void { - var path = std.ArrayList(u8).init(self.a); + var path = std.ArrayList(u8).init(self.allocator); defer path.deinit(); const writer = path.writer(); _ = try writer.write(try root.get_state_dir()); @@ -555,7 +555,7 @@ const Process = struct { recent_projects: *std.ArrayList(RecentProject), project_directory: []const u8, ) !void { - var path = std.ArrayList(u8).init(self.a); + var path = std.ArrayList(u8).init(self.allocator); defer path.deinit(); const writer = path.writer(); _ = try writer.write(state_dir); @@ -565,15 +565,15 @@ const Process = struct { var file = try std.fs.openFileAbsolute(path.items, .{ .mode = .read_only }); defer file.close(); const stat = try file.stat(); - const buffer = try self.a.alloc(u8, @intCast(stat.size)); - defer self.a.free(buffer); + const buffer = try self.allocator.alloc(u8, @intCast(stat.size)); + defer self.allocator.free(buffer); _ = try file.readAll(buffer); var iter: []const u8 = buffer; var name: []const u8 = undefined; if (cbor.matchValue(&iter, tp.extract(&name)) catch return) { const last_used = if (std.mem.eql(u8, project_directory, name)) std.math.maxInt(@TypeOf(stat.mtime)) else stat.mtime; - (try recent_projects.addOne()).* = .{ .name = try self.a.dupe(u8, name), .last_used = last_used }; + (try recent_projects.addOne()).* = .{ .name = try self.allocator.dupe(u8, name), .last_used = last_used }; } } @@ -589,7 +589,7 @@ const Process = struct { fn request_path_files_async(a_: std.mem.Allocator, parent_: tp.pid_ref, project_: *Project, max_: usize, path_: []const u8) !void { return struct { - a: std.mem.Allocator, + allocator: std.mem.Allocator, project_name: []const u8, path: []const u8, parent: tp.pid, @@ -599,20 +599,20 @@ fn request_path_files_async(a_: std.mem.Allocator, parent_: tp.pid_ref, project_ const path_files = @This(); const Receiver = tp.Receiver(*path_files); - fn spawn_link(a: std.mem.Allocator, parent: tp.pid_ref, project: *Project, max: usize, path: []const u8) !void { - const self = try a.create(path_files); + fn spawn_link(allocator: std.mem.Allocator, parent: tp.pid_ref, project: *Project, max: usize, path: []const u8) !void { + const self = try allocator.create(path_files); self.* = .{ - .a = a, - .project_name = try a.dupe(u8, project.name), + .allocator = allocator, + .project_name = try allocator.dupe(u8, project.name), .path = try if (std.fs.path.isAbsolute(path)) - a.dupe(u8, path) + allocator.dupe(u8, path) else - std.fs.path.join(a, &[_][]const u8{ project.name, path }), + std.fs.path.join(allocator, &[_][]const u8{ project.name, path }), .parent = parent.clone(), .max = max, .dir = try std.fs.cwd().openDir(self.path, .{ .iterate = true }), }; - const pid = try tp.spawn_link(a, self, path_files.start, module_name ++ ".path_files"); + const pid = try tp.spawn_link(allocator, self, path_files.start, module_name ++ ".path_files"); pid.deinit(); } @@ -627,8 +627,8 @@ fn request_path_files_async(a_: std.mem.Allocator, parent_: tp.pid_ref, project_ fn deinit(self: *path_files) void { self.dir.close(); - self.a.free(self.path); - self.a.free(self.project_name); + self.allocator.free(self.path); + self.allocator.free(self.project_name); self.parent.deinit(); } @@ -653,7 +653,7 @@ fn request_path_files_async(a_: std.mem.Allocator, parent_: tp.pid_ref, project_ fn walk_tree_async(a_: std.mem.Allocator, root_path_: []const u8) !tp.pid { return struct { - a: std.mem.Allocator, + allocator: std.mem.Allocator, root_path: []const u8, parent: tp.pid, receiver: Receiver, @@ -663,17 +663,17 @@ fn walk_tree_async(a_: std.mem.Allocator, root_path_: []const u8) !tp.pid { const tree_walker = @This(); const Receiver = tp.Receiver(*tree_walker); - fn spawn_link(a: std.mem.Allocator, root_path: []const u8) !tp.pid { - const self = try a.create(tree_walker); + fn spawn_link(allocator: std.mem.Allocator, root_path: []const u8) !tp.pid { + const self = try allocator.create(tree_walker); self.* = .{ - .a = a, - .root_path = try a.dupe(u8, root_path), + .allocator = allocator, + .root_path = try allocator.dupe(u8, root_path), .parent = tp.self_pid().clone(), .receiver = Receiver.init(tree_walker.receive, self), .dir = try std.fs.cwd().openDir(self.root_path, .{ .iterate = true }), - .walker = try walk_filtered(self.dir, self.a), + .walker = try walk_filtered(self.dir, self.allocator), }; - return tp.spawn_link(a, self, tree_walker.start, module_name ++ ".tree_walker"); + return tp.spawn_link(allocator, self, tree_walker.start, module_name ++ ".tree_walker"); } fn start(self: *tree_walker) tp.result { @@ -687,7 +687,7 @@ fn walk_tree_async(a_: std.mem.Allocator, root_path_: []const u8) !tp.pid { fn deinit(self: *tree_walker) void { self.walker.deinit(); self.dir.close(); - self.a.free(self.root_path); + self.allocator.free(self.root_path); self.parent.deinit(); } diff --git a/src/renderer/vaxis/renderer.zig b/src/renderer/vaxis/renderer.zig index c750b2c..0167899 100644 --- a/src/renderer/vaxis/renderer.zig +++ b/src/renderer/vaxis/renderer.zig @@ -20,7 +20,7 @@ const event_type = input.event_type; const Self = @This(); pub const log_name = "vaxis"; -a: std.mem.Allocator, +allocator: std.mem.Allocator, tty: vaxis.Tty, vx: vaxis.Vaxis, @@ -49,7 +49,7 @@ const Event = union(enum) { focus_in, }; -pub fn init(a: std.mem.Allocator, handler_ctx: *anyopaque, no_alternate: bool) !Self { +pub fn init(allocator: std.mem.Allocator, handler_ctx: *anyopaque, no_alternate: bool) !Self { const opts: vaxis.Vaxis.Options = .{ .kitty_keyboard_flags = .{ .disambiguate = true, @@ -58,16 +58,16 @@ pub fn init(a: std.mem.Allocator, handler_ctx: *anyopaque, no_alternate: bool) ! .report_all_as_ctl_seqs = true, .report_text = true, }, - .system_clipboard_allocator = a, + .system_clipboard_allocator = allocator, }; return .{ - .a = a, + .allocator = allocator, .tty = try vaxis.Tty.init(), - .vx = try vaxis.init(a, opts), + .vx = try vaxis.init(allocator, opts), .no_alternate = no_alternate, - .event_buffer = std.ArrayList(u8).init(a), - .input_buffer = std.ArrayList(u8).init(a), - .bracketed_paste_buffer = std.ArrayList(u8).init(a), + .event_buffer = std.ArrayList(u8).init(allocator), + .input_buffer = std.ArrayList(u8).init(allocator), + .bracketed_paste_buffer = std.ArrayList(u8).init(allocator), .handler_ctx = handler_ctx, .logger = log.logger(log_name), .loop = undefined, @@ -77,7 +77,7 @@ pub fn init(a: std.mem.Allocator, handler_ctx: *anyopaque, no_alternate: bool) ! pub fn deinit(self: *Self) void { panic_cleanup = null; self.loop.stop(); - self.vx.deinit(self.a, self.tty.anyWriter()); + self.vx.deinit(self.allocator, self.tty.anyWriter()); self.tty.deinit(); self.bracketed_paste_buffer.deinit(); self.input_buffer.deinit(); @@ -85,7 +85,7 @@ pub fn deinit(self: *Self) void { } var panic_cleanup: ?struct { - a: std.mem.Allocator, + allocator: std.mem.Allocator, tty: *vaxis.Tty, vx: *vaxis.Vaxis, } = null; @@ -93,7 +93,7 @@ pub fn panic(msg: []const u8, error_return_trace: ?*std.builtin.StackTrace, ret_ const cleanup = panic_cleanup; panic_cleanup = null; if (cleanup) |self| { - self.vx.deinit(self.a, self.tty.anyWriter()); + self.vx.deinit(self.allocator, self.tty.anyWriter()); self.tty.deinit(); } return std.builtin.default_panic(msg, error_return_trace, ret_addr); @@ -102,7 +102,7 @@ pub fn panic(msg: []const u8, error_return_trace: ?*std.builtin.StackTrace, ret_ pub fn run(self: *Self) !void { self.vx.sgr = .legacy; - panic_cleanup = .{ .a = self.a, .tty = &self.tty, .vx = &self.vx }; + panic_cleanup = .{ .allocator = self.allocator, .tty = &self.tty, .vx = &self.vx }; if (!self.no_alternate) try self.vx.enterAltScreen(self.tty.anyWriter()); if (builtin.os.tag == .windows) { try self.resize(.{ .rows = 25, .cols = 80, .x_pixel = 0, .y_pixel = 0 }); // dummy resize to fully init vaxis @@ -128,7 +128,7 @@ pub fn sigwinch(self: *Self) !void { } fn resize(self: *Self, ws: vaxis.Winsize) !void { - try self.vx.resize(self.a, self.tty.anyWriter(), ws); + try self.vx.resize(self.allocator, self.tty.anyWriter(), ws); self.vx.queueRefresh(); if (self.dispatch_event) |f| f(self.handler_ctx, try self.fmtmsg(.{"resize"})); } @@ -336,7 +336,7 @@ pub fn set_terminal_working_directory(self: *Self, absolute_path: []const u8) vo pub fn copy_to_system_clipboard(self: *Self, text: []const u8) void { var bufferedWriter = self.tty.bufferedWriter(); - self.vx.copyToSystemClipboard(bufferedWriter.writer().any(), text, self.a) catch |e| log.logger(log_name).err("copy_to_system_clipboard", e); + self.vx.copyToSystemClipboard(bufferedWriter.writer().any(), text, self.allocator) catch |e| log.logger(log_name).err("copy_to_system_clipboard", e); bufferedWriter.flush() catch @panic("flush failed"); } diff --git a/src/ripgrep.zig b/src/ripgrep.zig index 63c72cc..ede7879 100644 --- a/src/ripgrep.zig +++ b/src/ripgrep.zig @@ -15,18 +15,18 @@ pub const Writer = std.io.Writer(*Self, Error, write); pub const BufferedWriter = std.io.BufferedWriter(max_chunk_size, Writer); pub const Error = error{ OutOfMemory, Exit, ThespianSpawnFailed, Closed }; -pub const FindF = fn (a: std.mem.Allocator, query: []const u8, tag: [:0]const u8) Error!Self; +pub const FindF = fn (allocator: std.mem.Allocator, query: []const u8, tag: [:0]const u8) Error!Self; -pub fn find_in_stdin(a: std.mem.Allocator, query: []const u8, tag: [:0]const u8) Error!Self { - return create(a, query, tag, .Pipe); +pub fn find_in_stdin(allocator: std.mem.Allocator, query: []const u8, tag: [:0]const u8) Error!Self { + return create(allocator, query, tag, .Pipe); } -pub fn find_in_files(a: std.mem.Allocator, query: []const u8, tag: [:0]const u8) !Self { - return create(a, query, tag, .Close); +pub fn find_in_files(allocator: std.mem.Allocator, query: []const u8, tag: [:0]const u8) !Self { + return create(allocator, query, tag, .Close); } -fn create(a: std.mem.Allocator, query: []const u8, tag: [:0]const u8, stdin_behavior: std.process.Child.StdIo) !Self { - return .{ .pid = try Process.create(a, query, tag, stdin_behavior), .stdin_behavior = stdin_behavior }; +fn create(allocator: std.mem.Allocator, query: []const u8, tag: [:0]const u8, stdin_behavior: std.process.Child.StdIo) !Self { + return .{ .pid = try Process.create(allocator, query, tag, stdin_behavior), .stdin_behavior = stdin_behavior }; } pub fn deinit(self: *Self) void { @@ -71,7 +71,7 @@ pub fn bufferedWriter(self: *Self) BufferedWriter { } const Process = struct { - a: std.mem.Allocator, + allocator: std.mem.Allocator, query: []const u8, receiver: Receiver, sp: ?tp.subprocess = null, @@ -84,25 +84,25 @@ const Process = struct { const Receiver = tp.Receiver(*Process); - pub fn create(a: std.mem.Allocator, query: []const u8, tag: [:0]const u8, stdin_behavior: std.process.Child.StdIo) !tp.pid { - const self = try a.create(Process); + pub fn create(allocator: std.mem.Allocator, query: []const u8, tag: [:0]const u8, stdin_behavior: std.process.Child.StdIo) !tp.pid { + const self = try allocator.create(Process); self.* = .{ - .a = a, - .query = try a.dupe(u8, query), + .allocator = allocator, + .query = try allocator.dupe(u8, query), .receiver = Receiver.init(receive, self), - .output = std.ArrayList(u8).init(a), + .output = std.ArrayList(u8).init(allocator), .parent = tp.self_pid().clone(), - .tag = try a.dupeZ(u8, tag), + .tag = try allocator.dupeZ(u8, tag), .logger = log.logger(@typeName(Self)), .stdin_behavior = stdin_behavior, }; - return tp.spawn_link(self.a, self, Process.start, tag); + return tp.spawn_link(self.allocator, self, Process.start, tag); } fn deinit(self: *Process) void { self.output.deinit(); self.logger.deinit(); - self.a.free(self.query); + self.allocator.free(self.query); self.close() catch {}; } @@ -122,7 +122,7 @@ const Process = struct { "--json", self.query, }); - self.sp = tp.subprocess.init(self.a, args, module_name, self.stdin_behavior) catch |e| return tp.exit_error(e, @errorReturnTrace()); + self.sp = tp.subprocess.init(self.allocator, args, module_name, self.stdin_behavior) catch |e| return tp.exit_error(e, @errorReturnTrace()); tp.receive(&self.receiver); } @@ -167,7 +167,7 @@ const Process = struct { } fn dispatch(self: *Process, m: tp.message) !void { - var obj = std.json.ObjectMap.init(self.a); + var obj = std.json.ObjectMap.init(self.allocator); defer obj.deinit(); if (try m.match(tp.extract(&obj))) { if (obj.get("type")) |*val| { diff --git a/src/service_template.zig b/src/service_template.zig index 537ac75..ef28821 100644 --- a/src/service_template.zig +++ b/src/service_template.zig @@ -9,8 +9,8 @@ const Self = @This(); const module_name = @typeName(Self); pub const Error = error{ OutOfMemory, Exit }; -pub fn create(a: std.mem.Allocator) Error!Self { - return .{ .pid = try Process.create(a) }; +pub fn create(allocator: std.mem.Allocator) Error!Self { + return .{ .pid = try Process.create(allocator) }; } pub fn from_pid(pid: tp.pid_ref) Error!Self { @@ -37,17 +37,17 @@ pub fn shutdown(self: *Self) void { // } const Process = struct { - a: std.mem.Allocator, + allocator: std.mem.Allocator, parent: tp.pid, logger: log.Logger, receiver: Receiver, const Receiver = tp.Receiver(*Process); - pub fn create(a: std.mem.Allocator) Error!tp.pid { - const self = try a.create(Process); + pub fn create(allocator: std.mem.Allocator) Error!tp.pid { + const self = try allocator.create(Process); self.* = .{ - .a = a, + .allocator = allocator, .parent = tp.self_pid().clone(), .logger = log.logger(module_name), .receiver = Receiver.init(Process.receive, self), diff --git a/src/syntax/src/syntax.zig b/src/syntax/src/syntax.zig index 76b1be6..6737389 100644 --- a/src/syntax/src/syntax.zig +++ b/src/syntax/src/syntax.zig @@ -18,7 +18,7 @@ const Parser = treez.Parser; const Query = treez.Query; pub const Node = treez.Node; -a: std.mem.Allocator, +allocator: std.mem.Allocator, lang: *const Language, file_type: *const FileType, parser: *Parser, @@ -26,10 +26,10 @@ query: *Query, injections: *Query, tree: ?*treez.Tree = null, -pub fn create(file_type: *const FileType, a: std.mem.Allocator, content: []const u8) !*Self { - const self = try a.create(Self); +pub fn create(file_type: *const FileType, allocator: std.mem.Allocator, content: []const u8) !*Self { + const self = try allocator.create(Self); self.* = .{ - .a = a, + .allocator = allocator, .lang = file_type.lang_fn() orelse std.debug.panic("tree-sitter parser function failed for language: {s}", .{file_type.name}), .file_type = file_type, .parser = try Parser.create(), @@ -42,21 +42,21 @@ pub fn create(file_type: *const FileType, a: std.mem.Allocator, content: []const return self; } -pub fn create_file_type(a: std.mem.Allocator, content: []const u8, lang_name: []const u8) !*Self { +pub fn create_file_type(allocator: std.mem.Allocator, content: []const u8, lang_name: []const u8) !*Self { const file_type = FileType.get_by_name(lang_name) orelse return error.NotFound; - return create(file_type, a, content); + return create(file_type, allocator, content); } -pub fn create_guess_file_type(a: std.mem.Allocator, content: []const u8, file_path: ?[]const u8) !*Self { +pub fn create_guess_file_type(allocator: std.mem.Allocator, content: []const u8, file_path: ?[]const u8) !*Self { const file_type = FileType.guess(file_path, content) orelse return error.NotFound; - return create(file_type, a, content); + return create(file_type, allocator, content); } pub fn destroy(self: *Self) void { if (self.tree) |tree| tree.destroy(); self.query.destroy(); self.parser.destroy(); - self.a.destroy(self); + self.allocator.destroy(self); } pub fn refresh_full(self: *Self, content: []const u8) !void { diff --git a/src/text_manip.zig b/src/text_manip.zig index 9fc9f12..d140481 100644 --- a/src/text_manip.zig +++ b/src/text_manip.zig @@ -55,8 +55,8 @@ fn remove_prefix_in_line(prefix: []const u8, text: []const u8, writer: TextWrite } } -pub fn toggle_prefix_in_text(prefix: []const u8, text: []const u8, a: std.mem.Allocator) ![]const u8 { - var result = try std.ArrayList(u8).initCapacity(a, prefix.len + text.len); +pub fn toggle_prefix_in_text(prefix: []const u8, text: []const u8, allocator: std.mem.Allocator) ![]const u8 { + var result = try std.ArrayList(u8).initCapacity(allocator, prefix.len + text.len); const writer = result.writer(); var pos: usize = 0; var prefix_pos: usize = std.math.maxInt(usize); diff --git a/src/tui/Button.zig b/src/tui/Button.zig index 3d9efa3..1f6eb9e 100644 --- a/src/tui/Button.zig +++ b/src/tui/Button.zig @@ -46,28 +46,28 @@ pub fn Options(context: type) type { }; } -pub fn create(ctx_type: type, a: std.mem.Allocator, parent: Plane, opts: Options(ctx_type)) error{OutOfMemory}!*State(ctx_type) { +pub fn create(ctx_type: type, allocator: std.mem.Allocator, parent: Plane, opts: Options(ctx_type)) error{OutOfMemory}!*State(ctx_type) { const Self = State(ctx_type); - const self = try a.create(Self); + const self = try allocator.create(Self); var n = try Plane.init(&opts.pos.opts(@typeName(Self)), parent); errdefer n.deinit(); self.* = .{ - .a = a, + .allocator = allocator, .parent = parent, .plane = n, .opts = opts, }; - self.opts.label = try self.a.dupe(u8, opts.label); + self.opts.label = try self.allocator.dupe(u8, opts.label); return self; } -pub fn create_widget(ctx_type: type, a: std.mem.Allocator, parent: Plane, opts: Options(ctx_type)) error{OutOfMemory}!Widget { - return Widget.to(try create(ctx_type, a, parent, opts)); +pub fn create_widget(ctx_type: type, allocator: std.mem.Allocator, parent: Plane, opts: Options(ctx_type)) error{OutOfMemory}!Widget { + return Widget.to(try create(ctx_type, allocator, parent, opts)); } pub fn State(ctx_type: type) type { return struct { - a: std.mem.Allocator, + allocator: std.mem.Allocator, parent: Plane, plane: Plane, active: bool = false, @@ -77,10 +77,10 @@ pub fn State(ctx_type: type) type { const Self = @This(); pub const Context = ctx_type; - pub fn deinit(self: *Self, a: std.mem.Allocator) void { - self.a.free(self.opts.label); + pub fn deinit(self: *Self, allocator: std.mem.Allocator) void { + self.allocator.free(self.opts.label); self.plane.deinit(); - a.destroy(self); + allocator.destroy(self); } pub fn layout(self: *Self) Widget.Layout { diff --git a/src/tui/EventHandler.zig b/src/tui/EventHandler.zig index f4c1969..79c5ce5 100644 --- a/src/tui/EventHandler.zig +++ b/src/tui/EventHandler.zig @@ -96,9 +96,9 @@ pub fn send(self: Self, from_: tp.pid_ref, m: tp.message) tp.result { return self.vtable.send(self.ptr, from_, m); } -pub fn empty(a: Allocator) !Self { +pub fn empty(allocator: Allocator) !Self { const child: type = struct {}; - const widget = try a.create(child); + const widget = try allocator.create(child); widget.* = .{}; return .{ .ptr = widget, @@ -106,8 +106,8 @@ pub fn empty(a: Allocator) !Self { .vtable = comptime &.{ .type_name = @typeName(child), .deinit = struct { - pub fn deinit(ctx: *anyopaque, a_: Allocator) void { - return a_.destroy(@as(*child, @ptrCast(@alignCast(ctx)))); + pub fn deinit(ctx: *anyopaque, allocator_: Allocator) void { + return allocator_.destroy(@as(*child, @ptrCast(@alignCast(ctx)))); } }.deinit, .send = struct { @@ -120,14 +120,14 @@ pub fn empty(a: Allocator) !Self { } pub const List = struct { - a: Allocator, + allocator: Allocator, list: ArrayList(EventHandler), recursion_check: bool = false, - pub fn init(a: Allocator) List { + pub fn init(allocator: Allocator) List { return .{ - .a = a, - .list = ArrayList(EventHandler).init(a), + .allocator = allocator, + .list = ArrayList(EventHandler).init(allocator), }; } diff --git a/src/tui/InputBox.zig b/src/tui/InputBox.zig index 264a899..8b85aec 100644 --- a/src/tui/InputBox.zig +++ b/src/tui/InputBox.zig @@ -48,17 +48,17 @@ pub fn Options(context: type) type { }; } -pub fn create(ctx_type: type, a: std.mem.Allocator, parent: Plane, opts: Options(ctx_type)) !Widget { +pub fn create(ctx_type: type, allocator: std.mem.Allocator, parent: Plane, opts: Options(ctx_type)) !Widget { const Self = State(ctx_type); - const self = try a.create(Self); + const self = try allocator.create(Self); var n = try Plane.init(&opts.pos.opts(@typeName(Self)), parent); errdefer n.deinit(); self.* = .{ .parent = parent, .plane = n, .opts = opts, - .label = std.ArrayList(u8).init(a), - .text = std.ArrayList(u8).init(a), + .label = std.ArrayList(u8).init(allocator), + .text = std.ArrayList(u8).init(allocator), }; try self.label.appendSlice(self.opts.label); self.opts.label = self.label.items; @@ -79,11 +79,11 @@ pub fn State(ctx_type: type) type { const Self = @This(); pub const Context = ctx_type; - pub fn deinit(self: *Self, a: std.mem.Allocator) void { + pub fn deinit(self: *Self, allocator: std.mem.Allocator) void { self.text.deinit(); self.label.deinit(); self.plane.deinit(); - a.destroy(self); + allocator.destroy(self); } pub fn layout(self: *Self) Widget.Layout { diff --git a/src/tui/Menu.zig b/src/tui/Menu.zig index dd7a55e..57eec61 100644 --- a/src/tui/Menu.zig +++ b/src/tui/Menu.zig @@ -50,15 +50,15 @@ pub fn Options(context: type) type { }; } -pub fn create(ctx_type: type, a: std.mem.Allocator, parent: Widget, opts: Options(ctx_type)) !*State(ctx_type) { - const self = try a.create(State(ctx_type)); - const container = try WidgetList.createH(a, parent, @typeName(@This()), .dynamic); +pub fn create(ctx_type: type, allocator: std.mem.Allocator, parent: Widget, opts: Options(ctx_type)) !*State(ctx_type) { + const self = try allocator.create(State(ctx_type)); + const container = try WidgetList.createH(allocator, parent, @typeName(@This()), .dynamic); self.* = .{ - .a = a, - .menu = try WidgetList.createV(a, container.widget(), @typeName(@This()), .dynamic), + .allocator = allocator, + .menu = try WidgetList.createV(allocator, container.widget(), @typeName(@This()), .dynamic), .container = container, .container_widget = container.widget(), - .scrollbar = if (opts.on_scroll) |on_scroll| (try scrollbar_v.create(a, parent, null, on_scroll)).dynamic_cast(scrollbar_v).? else null, + .scrollbar = if (opts.on_scroll) |on_scroll| (try scrollbar_v.create(allocator, parent, null, on_scroll)).dynamic_cast(scrollbar_v).? else null, .opts = opts, }; self.menu.ctx = self; @@ -72,7 +72,7 @@ pub fn create(ctx_type: type, a: std.mem.Allocator, parent: Widget, opts: Option pub fn State(ctx_type: type) type { return struct { - a: std.mem.Allocator, + allocator: std.mem.Allocator, menu: *WidgetList, container: *WidgetList, container_widget: Widget, @@ -87,9 +87,9 @@ pub fn State(ctx_type: type) type { const options_type = Options(ctx_type); const button_type = Button.State(*Self); - pub fn deinit(self: *Self, a: std.mem.Allocator) void { - self.menu.deinit(a); - a.destroy(self); + pub fn deinit(self: *Self, allocator: std.mem.Allocator) void { + self.menu.deinit(allocator); + allocator.destroy(self); } pub fn add_header(self: *Self, w_: Widget) !*Widget { @@ -99,7 +99,7 @@ pub fn State(ctx_type: type) type { } pub fn add_item(self: *Self, label: []const u8) !void { - try self.menu.add(try Button.create(*Self, self.a, self.menu.parent, .{ + try self.menu.add(try Button.create(*Self, self.allocator, self.menu.parent, .{ .ctx = self, .on_layout = self.opts.on_layout, .label = label, @@ -111,7 +111,7 @@ pub fn State(ctx_type: type) type { } pub fn add_item_with_handler(self: *Self, label: []const u8, on_click: *const fn (_: **Self, _: *Button.State(*Self)) void) !void { - try self.menu.add(try Button.create_widget(*Self, self.a, self.menu.parent, .{ + try self.menu.add(try Button.create_widget(*Self, self.allocator, self.menu.parent, .{ .ctx = self, .on_layout = on_layout, .label = label, @@ -125,7 +125,7 @@ pub fn State(ctx_type: type) type { pub fn reset_items(self: *Self) void { for (self.menu.widgets.items, 0..) |*w, i| if (i >= self.header_count) - w.widget.deinit(self.a); + w.widget.deinit(self.allocator); self.menu.widgets.shrinkRetainingCapacity(self.header_count); } diff --git a/src/tui/MessageFilter.zig b/src/tui/MessageFilter.zig index 16e8354..3f9ba16 100644 --- a/src/tui/MessageFilter.zig +++ b/src/tui/MessageFilter.zig @@ -89,13 +89,13 @@ pub fn filter(self: Self, from_: tp.pid_ref, m: tp.message) error{Exit}!bool { } pub const List = struct { - a: Allocator, + allocator: Allocator, list: ArrayList(MessageFilter), - pub fn init(a: Allocator) List { + pub fn init(allocator: Allocator) List { return .{ - .a = a, - .list = ArrayList(MessageFilter).init(a), + .allocator = allocator, + .list = ArrayList(MessageFilter).init(allocator), }; } @@ -121,7 +121,7 @@ pub const List = struct { } pub fn filter(self: *const List, from: tp.pid_ref, m: tp.message) error{Exit}!bool { - var sfa = std.heap.stackFallback(4096, self.a); + var sfa = std.heap.stackFallback(4096, self.allocator); const a = sfa.get(); const buf = a.alloc(u8, m.buf.len) catch |e| return tp.exit_error(e, @errorReturnTrace()); defer a.free(buf); diff --git a/src/tui/Widget.zig b/src/tui/Widget.zig index bf7092c..d923d88 100644 --- a/src/tui/Widget.zig +++ b/src/tui/Widget.zig @@ -39,7 +39,7 @@ pub const Layout = union(enum) { }; pub const VTable = struct { - deinit: *const fn (ctx: *anyopaque, a: Allocator) void, + deinit: *const fn (ctx: *anyopaque, allocator: Allocator) void, send: *const fn (ctx: *anyopaque, from: tp.pid_ref, m: tp.message) error{Exit}!bool, update: *const fn (ctx: *anyopaque) void, render: *const fn (ctx: *anyopaque, theme: *const Theme) bool, @@ -62,8 +62,8 @@ pub fn to(pimpl: anytype) Self { .vtable = comptime &.{ .type_name = @typeName(child), .deinit = struct { - pub fn deinit(ctx: *anyopaque, a: Allocator) void { - return child.deinit(@as(*child, @ptrCast(@alignCast(ctx))), a); + pub fn deinit(ctx: *anyopaque, allocator: Allocator) void { + return child.deinit(@as(*child, @ptrCast(@alignCast(ctx))), allocator); } }.deinit, .send = if (@hasDecl(child, "receive")) struct { @@ -169,8 +169,8 @@ pub fn box(self: Self) Box { return Box.from(self.plane.*); } -pub fn deinit(self: Self, a: Allocator) void { - return self.vtable.deinit(self.ptr, a); +pub fn deinit(self: Self, allocator: Allocator) void { + return self.vtable.deinit(self.ptr, allocator); } pub fn msg(self: *const Self, m: anytype) error{Exit}!bool { @@ -221,9 +221,9 @@ pub fn hover(self: *Self) bool { return self.vtable.hover(self.ptr); } -pub fn empty(a: Allocator, parent: Plane, layout_: Layout) !Self { +pub fn empty(allocator: Allocator, parent: Plane, layout_: Layout) !Self { const child: type = struct { plane: Plane, layout: Layout }; - const widget = try a.create(child); + const widget = try allocator.create(child); const n = try Plane.init(&(Box{}).opts("empty"), parent); widget.* = .{ .plane = n, .layout = layout_ }; return .{ @@ -232,10 +232,10 @@ pub fn empty(a: Allocator, parent: Plane, layout_: Layout) !Self { .vtable = comptime &.{ .type_name = @typeName(child), .deinit = struct { - pub fn deinit(ctx: *anyopaque, a_: Allocator) void { + pub fn deinit(ctx: *anyopaque, allocator_: Allocator) void { const self: *child = @ptrCast(@alignCast(ctx)); self.plane.deinit(); - a_.destroy(self); + allocator_.destroy(self); } }.deinit, .send = struct { diff --git a/src/tui/WidgetList.zig b/src/tui/WidgetList.zig index 796bf32..47abf2d 100644 --- a/src/tui/WidgetList.zig +++ b/src/tui/WidgetList.zig @@ -21,7 +21,7 @@ const WidgetState = struct { plane: Plane, parent: Plane, -a: Allocator, +allocator: Allocator, widgets: ArrayList(WidgetState), layout: Layout, direction: Direction, @@ -31,33 +31,33 @@ on_render: *const fn (ctx: ?*anyopaque, theme: *const Widget.Theme) void = on_re after_render: *const fn (ctx: ?*anyopaque, theme: *const Widget.Theme) void = on_render_default, on_resize: *const fn (ctx: ?*anyopaque, self: *Self, pos_: Widget.Box) void = on_resize_default, -pub fn createH(a: Allocator, parent: Widget, name: [:0]const u8, layout_: Layout) !*Self { - const self: *Self = try a.create(Self); - self.* = try init(a, parent, name, .horizontal, layout_, Box{}); +pub fn createH(allocator: Allocator, parent: Widget, name: [:0]const u8, layout_: Layout) !*Self { + const self: *Self = try allocator.create(Self); + self.* = try init(allocator, parent, name, .horizontal, layout_, Box{}); self.plane.hide(); return self; } -pub fn createV(a: Allocator, parent: Widget, name: [:0]const u8, layout_: Layout) !*Self { - const self: *Self = try a.create(Self); - self.* = try init(a, parent, name, .vertical, layout_, Box{}); +pub fn createV(allocator: Allocator, parent: Widget, name: [:0]const u8, layout_: Layout) !*Self { + const self: *Self = try allocator.create(Self); + self.* = try init(allocator, parent, name, .vertical, layout_, Box{}); self.plane.hide(); return self; } -pub fn createBox(a: Allocator, parent: Widget, name: [:0]const u8, dir: Direction, layout_: Layout, box: Box) !*Self { - const self: *Self = try a.create(Self); - self.* = try init(a, parent, name, dir, layout_, box); +pub fn createBox(allocator: Allocator, parent: Widget, name: [:0]const u8, dir: Direction, layout_: Layout, box: Box) !*Self { + const self: *Self = try allocator.create(Self); + self.* = try init(allocator, parent, name, dir, layout_, box); self.plane.hide(); return self; } -fn init(a: Allocator, parent: Widget, name: [:0]const u8, dir: Direction, layout_: Layout, box: Box) !Self { +fn init(allocator: Allocator, parent: Widget, name: [:0]const u8, dir: Direction, layout_: Layout, box: Box) !Self { return .{ .plane = try Plane.init(&box.opts(name), parent.plane.*), .parent = parent.plane.*, - .a = a, - .widgets = ArrayList(WidgetState).init(a), + .allocator = allocator, + .widgets = ArrayList(WidgetState).init(allocator), .layout = layout_, .direction = dir, }; @@ -71,12 +71,12 @@ pub fn layout(self: *Self) Widget.Layout { return self.layout; } -pub fn deinit(self: *Self, a: std.mem.Allocator) void { +pub fn deinit(self: *Self, allocator: std.mem.Allocator) void { for (self.widgets.items) |*w| - w.widget.deinit(self.a); + w.widget.deinit(self.allocator); self.widgets.deinit(); self.plane.deinit(); - a.destroy(self); + allocator.destroy(self); } pub fn add(self: *Self, w_: Widget) !void { @@ -92,7 +92,7 @@ pub fn addP(self: *Self, w_: Widget) !*Widget { pub fn remove(self: *Self, w: Widget) void { for (self.widgets.items, 0..) |p, i| if (p.widget.ptr == w.ptr) - self.widgets.orderedRemove(i).widget.deinit(self.a); + self.widgets.orderedRemove(i).widget.deinit(self.allocator); } pub fn empty(self: *const Self) bool { @@ -108,7 +108,7 @@ pub fn swap(self: *Self, n: usize, w: Widget) Widget { pub fn replace(self: *Self, n: usize, w: Widget) void { const old = self.swap(n, w); - old.deinit(self.a); + old.deinit(self.allocator); } pub fn send(self: *Self, from: tp.pid_ref, m: tp.message) error{Exit}!bool { diff --git a/src/tui/WidgetStack.zig b/src/tui/WidgetStack.zig index 5d96dc0..ed30a62 100644 --- a/src/tui/WidgetStack.zig +++ b/src/tui/WidgetStack.zig @@ -8,19 +8,19 @@ const Widget = @import("Widget.zig"); const Self = @This(); -a: Allocator, +allocator: Allocator, widgets: ArrayList(Widget), -pub fn init(a_: Allocator) Self { +pub fn init(allocator: Allocator) Self { return .{ - .a = a_, - .widgets = ArrayList(Widget).init(a_), + .allocator = allocator, + .widgets = ArrayList(Widget).init(allocator), }; } pub fn deinit(self: *Self) void { for (self.widgets.items) |*widget| - widget.deinit(self.a); + widget.deinit(self.allocator); self.widgets.deinit(); } @@ -41,7 +41,7 @@ pub fn replace(self: *Self, n: usize, widget: Widget) void { pub fn remove(self: *Self, w: Widget) void { for (self.widgets.items, 0..) |p, i| if (p.ptr == w.ptr) - self.widgets.orderedRemove(i).deinit(self.a); + self.widgets.orderedRemove(i).deinit(self.allocator); } pub fn delete(self: *Self, name: []const u8) bool { diff --git a/src/tui/editor.zig b/src/tui/editor.zig index ae8a350..61eec6c 100644 --- a/src/tui/editor.zig +++ b/src/tui/editor.zig @@ -158,10 +158,10 @@ pub const Diagnostic = struct { severity: i32, sel: Selection, - fn deinit(self: *Diagnostic, a: std.mem.Allocator) void { - a.free(self.source); - a.free(self.code); - a.free(self.message); + fn deinit(self: *Diagnostic, allocator: std.mem.Allocator) void { + allocator.free(self.source); + allocator.free(self.code); + allocator.free(self.message); } pub const Severity = enum { Error, Warning, Information, Hint }; @@ -189,7 +189,7 @@ pub const Editor = struct { const Self = @This(); pub const Target = Self; - a: Allocator, + allocator: Allocator, plane: Plane, logger: log.Logger, @@ -299,8 +299,8 @@ pub const Editor = struct { })) return error.RestoreStateMatch; try self.open(file_path); - self.clipboard = if (clipboard.len > 0) try self.a.dupe(u8, clipboard) else null; - self.last_find_query = if (query.len > 0) try self.a.dupe(u8, clipboard) else null; + self.clipboard = if (clipboard.len > 0) try self.allocator.dupe(u8, clipboard) else null; + self.last_find_query = if (query.len > 0) try self.allocator.dupe(u8, clipboard) else null; if (!try self.view.extract(&view_cbor)) return error.RestoreView; self.scroll_dest = self.view.row; @@ -315,26 +315,26 @@ pub const Editor = struct { } } - fn init(self: *Self, a: Allocator, n: Plane) void { + fn init(self: *Self, allocator: Allocator, n: Plane) void { const logger = log.logger("editor"); var frame_rate = tp.env.get().num("frame-rate"); if (frame_rate == 0) frame_rate = 60; self.* = Self{ - .a = a, + .allocator = allocator, .plane = n, .logger = logger, .file_path = null, .buffer = null, - .handlers = EventHandler.List.init(a), + .handlers = EventHandler.List.init(allocator), .animation_lag = get_animation_max_lag(), .animation_frame_rate = frame_rate, .animation_last_time = time.microTimestamp(), - .cursels = CurSel.List.init(a), - .cursels_saved = CurSel.List.init(a), - .matches = Match.List.init(a), + .cursels = CurSel.List.init(allocator), + .cursels_saved = CurSel.List.init(allocator), + .matches = Match.List.init(allocator), .enable_terminal_cursor = tui.current().config.enable_terminal_cursor, .show_whitespace = tui.current().config.show_whitespace, - .diagnostics = std.ArrayList(Diagnostic).init(a), + .diagnostics = std.ArrayList(Diagnostic).init(allocator), }; } @@ -364,7 +364,7 @@ pub const Editor = struct { } fn buf_a(self: *const Self) !Allocator { - return if (self.buffer) |p| p.a else error.Stop; + return if (self.buffer) |p| p.allocator else error.Stop; } pub fn get_current_root(self: *const Self) ?Buffer.Root { @@ -384,14 +384,14 @@ pub const Editor = struct { } fn open(self: *Self, file_path: []const u8) !void { - var new_buf = try Buffer.create(self.a); + var new_buf = try Buffer.create(self.allocator); errdefer new_buf.deinit(); try new_buf.load_from_file_and_update(file_path); return self.open_buffer(file_path, new_buf); } fn open_scratch(self: *Self, file_path: []const u8, content: []const u8) !void { - var new_buf = try Buffer.create(self.a); + var new_buf = try Buffer.create(self.allocator); errdefer new_buf.deinit(); try new_buf.load_from_string_and_update(file_path, content); new_buf.file_exists = true; @@ -402,7 +402,7 @@ pub const Editor = struct { errdefer new_buf.deinit(); self.cancel_all_selections(); self.get_primary().reset(); - self.file_path = try self.a.dupe(u8, file_path); + self.file_path = try self.allocator.dupe(u8, file_path); if (self.buffer) |_| try self.close(); self.buffer = new_buf; @@ -410,13 +410,13 @@ pub const Editor = struct { if (new_buf.root.lines() > root_mod.max_syntax_lines) break :syntax null; const lang_override = tp.env.get().str("language"); - var content = std.ArrayList(u8).init(self.a); + var content = std.ArrayList(u8).init(self.allocator); defer content.deinit(); try new_buf.root.store(content.writer()); const syn = if (lang_override.len > 0) - syntax.create_file_type(self.a, content.items, lang_override) catch null + syntax.create_file_type(self.allocator, content.items, lang_override) catch null else - syntax.create_guess_file_type(self.a, content.items, self.file_path) catch null; + syntax.create_guess_file_type(self.allocator, content.items, self.file_path) catch null; if (syn) |syn_| project_manager.did_open(file_path, syn_.file_type, self.lsp_version, try content.toOwnedSlice()) catch {}; break :syntax syn; @@ -461,8 +461,8 @@ pub const Editor = struct { fn save_as(self: *Self, file_path: []const u8) !void { if (self.buffer) |b_mut| try b_mut.store_to_file_and_clean(file_path); - if (self.file_path) |old_file_path| self.a.free(old_file_path); - self.file_path = try self.a.dupe(u8, file_path); + if (self.file_path) |old_file_path| self.allocator.free(old_file_path); + self.file_path = try self.allocator.dupe(u8, file_path); try self.send_editor_save(self.file_path.?); self.last.dirty = false; } @@ -496,16 +496,16 @@ pub const Editor = struct { return self.get_primary(); } - fn store_undo_meta(self: *Self, a: Allocator) ![]u8 { - var meta = std.ArrayList(u8).init(a); + fn store_undo_meta(self: *Self, allocator: Allocator) ![]u8 { + var meta = std.ArrayList(u8).init(allocator); const writer = meta.writer(); for (self.cursels_saved.items) |*cursel_| if (cursel_.*) |*cursel| try cursel.write(writer); return meta.toOwnedSlice(); } - fn store_current_undo_meta(self: *Self, a: Allocator) ![]u8 { - var meta = std.ArrayList(u8).init(a); + fn store_current_undo_meta(self: *Self, allocator: Allocator) ![]u8 { + var meta = std.ArrayList(u8).init(allocator); const writer = meta.writer(); for (self.cursels.items) |*cursel_| if (cursel_.*) |*cursel| try cursel.write(writer); @@ -514,10 +514,10 @@ pub const Editor = struct { fn update_buf(self: *Self, root: Buffer.Root) !void { const b = self.buffer orelse return error.Stop; - var sfa = std.heap.stackFallback(512, self.a); - const a = sfa.get(); - const meta = try self.store_undo_meta(a); - defer a.free(meta); + var sfa = std.heap.stackFallback(512, self.allocator); + const allocator = sfa.get(); + const meta = try self.store_undo_meta(allocator); + defer allocator.free(meta); try b.store_undo(meta); b.update(root); try self.send_editor_modified(); @@ -538,10 +538,10 @@ pub const Editor = struct { if (self.buffer) |b_mut| { try self.send_editor_jump_source(); self.cancel_all_matches(); - var sfa = std.heap.stackFallback(512, self.a); - const a = sfa.get(); - const redo_meta = try self.store_current_undo_meta(a); - defer a.free(redo_meta); + var sfa = std.heap.stackFallback(512, self.allocator); + const allocator = sfa.get(); + const redo_meta = try self.store_current_undo_meta(allocator); + defer allocator.free(redo_meta); const meta = b_mut.undo(redo_meta) catch |e| switch (e) { error.Stop => { self.logger.print("nothing to undo", .{}); @@ -651,11 +651,11 @@ pub const Editor = struct { if (self.style_cache) |*cache| { if (!std.mem.eql(u8, self.style_cache_theme, theme.name)) { cache.deinit(); - self.style_cache = StyleCache.init(self.a); + self.style_cache = StyleCache.init(self.allocator); // self.logger.print("style_cache reset {s} -> {s}", .{ self.style_cache_theme, theme.name }); } } else { - self.style_cache = StyleCache.init(self.a); + self.style_cache = StyleCache.init(self.allocator); } self.style_cache_theme = theme.name; const cache: *StyleCache = &self.style_cache.?; @@ -686,11 +686,11 @@ pub const Editor = struct { const len = leaf.buf.len; var chunk_alloc: ?[:0]u8 = null; var chunk: [:0]u8 = if (len > bufsize) ret: { - const ptr = self_.a.allocSentinel(u8, len, 0) catch |e| return Buffer.Walker{ .err = e }; + const ptr = self_.allocator.allocSentinel(u8, len, 0) catch |e| return Buffer.Walker{ .err = e }; chunk_alloc = ptr; break :ret ptr; } else &bufstatic; - defer if (chunk_alloc) |p| self_.a.free(p); + defer if (chunk_alloc) |p| self_.allocator.free(p); @memcpy(chunk[0..leaf.buf.len], leaf.buf); chunk[leaf.buf.len] = 0; @@ -1063,7 +1063,7 @@ pub const Editor = struct { .theme = theme, .cache = cache, .root = root, - .pos_cache = try PosToWidthCache.init(self.a), + .pos_cache = try PosToWidthCache.init(self.allocator), }; defer ctx.pos_cache.deinit(); const range: syntax.Range = .{ @@ -1270,7 +1270,7 @@ pub const Editor = struct { defer frame.deinit(); var old = self.cursels; defer old.deinit(); - self.cursels = CurSel.List.initCapacity(self.a, old.items.len) catch return; + self.cursels = CurSel.List.initCapacity(self.allocator, old.items.len) catch return; for (old.items[0 .. old.items.len - 1], 0..) |*a_, i| if (a_.*) |*a| { for (old.items[i + 1 ..], i + 1..) |*b_, j| if (b_.*) |*b| { if (a.cursor.eql(b.cursor)) @@ -1345,15 +1345,15 @@ pub const Editor = struct { return if (someone_stopped) error.Stop else {}; } - fn with_cursor(root: Buffer.Root, move: cursor_operator, cursel: *CurSel, a: Allocator) error{Stop}!Buffer.Root { - return try move(root, &cursel.cursor, a); + fn with_cursor(root: Buffer.Root, move: cursor_operator, cursel: *CurSel, allocator: Allocator) error{Stop}!Buffer.Root { + return try move(root, &cursel.cursor, allocator); } - fn with_cursors(self: *Self, root_: Buffer.Root, move: cursor_operator, a: Allocator) error{Stop}!Buffer.Root { + fn with_cursors(self: *Self, root_: Buffer.Root, move: cursor_operator, allocator: Allocator) error{Stop}!Buffer.Root { var root = root_; for (self.cursels.items) |*cursel| { cursel.selection = null; - root = try with_cursor(root, move, cursel, a); + root = try with_cursor(root, move, cursel, allocator); } self.collapse_cursors(); return root; @@ -1409,15 +1409,15 @@ pub const Editor = struct { return if (someone_stopped) error.Stop else {}; } - fn with_cursel(root: Buffer.Root, op: cursel_operator, cursel: *CurSel, a: Allocator) error{Stop}!Buffer.Root { - return op(root, cursel, a); + fn with_cursel(root: Buffer.Root, op: cursel_operator, cursel: *CurSel, allocator: Allocator) error{Stop}!Buffer.Root { + return op(root, cursel, allocator); } - fn with_cursels(self: *Self, root_: Buffer.Root, move: cursel_operator, a: Allocator) error{Stop}!Buffer.Root { + fn with_cursels(self: *Self, root_: Buffer.Root, move: cursel_operator, allocator: Allocator) error{Stop}!Buffer.Root { var root = root_; var someone_stopped = false; for (self.cursels.items) |*cursel_| if (cursel_.*) |*cursel| { - root = with_cursel(root, move, cursel, a) catch ret: { + root = with_cursel(root, move, cursel, allocator) catch ret: { someone_stopped = true; break :ret root; }; @@ -1426,15 +1426,15 @@ pub const Editor = struct { return if (someone_stopped) error.Stop else root; } - fn with_cursel_mut(self: *Self, root: Buffer.Root, op: cursel_operator_mut, cursel: *CurSel, a: Allocator) error{Stop}!Buffer.Root { - return op(self, root, cursel, a); + fn with_cursel_mut(self: *Self, root: Buffer.Root, op: cursel_operator_mut, cursel: *CurSel, allocator: Allocator) error{Stop}!Buffer.Root { + return op(self, root, cursel, allocator); } - fn with_cursels_mut(self: *Self, root_: Buffer.Root, move: cursel_operator_mut, a: Allocator) error{Stop}!Buffer.Root { + fn with_cursels_mut(self: *Self, root_: Buffer.Root, move: cursel_operator_mut, allocator: Allocator) error{Stop}!Buffer.Root { var root = root_; var someone_stopped = false; for (self.cursels.items) |*cursel_| if (cursel_.*) |*cursel| { - root = self.with_cursel_mut(root, move, cursel, a) catch ret: { + root = self.with_cursel_mut(root, move, cursel, allocator) catch ret: { someone_stopped = true; break :ret root; }; @@ -1497,28 +1497,28 @@ pub const Editor = struct { } } - fn delete_selection(self: *Self, root: Buffer.Root, cursel: *CurSel, a: Allocator) error{Stop}!Buffer.Root { + fn delete_selection(self: *Self, root: Buffer.Root, cursel: *CurSel, allocator: Allocator) error{Stop}!Buffer.Root { var sel: Selection = cursel.selection orelse return error.Stop; sel.normalize(); cursel.cursor = sel.begin; cursel.selection = null; var size: usize = 0; - const root_ = try root.delete_range(sel, a, &size, self.plane.metrics()); + const root_ = try root.delete_range(sel, allocator, &size, self.plane.metrics()); self.nudge_delete(sel, cursel, size); return root_; } - fn delete_to(self: *Self, move: cursor_operator_const, root_: Buffer.Root, a: Allocator) error{Stop}!Buffer.Root { + fn delete_to(self: *Self, move: cursor_operator_const, root_: Buffer.Root, allocator: Allocator) error{Stop}!Buffer.Root { var all_stop = true; var root = root_; for (self.cursels.items) |*cursel_| if (cursel_.*) |*cursel| { if (cursel.selection) |_| { - root = self.delete_selection(root, cursel, a) catch continue; + root = self.delete_selection(root, cursel, allocator) catch continue; all_stop = false; continue; } with_selection_const(root, move, cursel, self.plane) catch continue; - root = self.delete_selection(root, cursel, a) catch continue; + root = self.delete_selection(root, cursel, allocator) catch continue; all_stop = false; }; @@ -1532,9 +1532,9 @@ pub const Editor = struct { const cursor_operator_const_arg = *const fn (root: Buffer.Root, cursor: *Cursor, ctx: Context, plane: Plane) error{Stop}!void; const cursor_view_operator_const = *const fn (root: Buffer.Root, cursor: *Cursor, view: *const View, plane: Plane) error{Stop}!void; const cursel_operator_const = *const fn (root: Buffer.Root, cursel: *CurSel) error{Stop}!void; - const cursor_operator = *const fn (root: Buffer.Root, cursor: *Cursor, a: Allocator) error{Stop}!Buffer.Root; - const cursel_operator = *const fn (root: Buffer.Root, cursel: *CurSel, a: Allocator) error{Stop}!Buffer.Root; - const cursel_operator_mut = *const fn (self: *Self, root: Buffer.Root, cursel: *CurSel, a: Allocator) error{Stop}!Buffer.Root; + const cursor_operator = *const fn (root: Buffer.Root, cursor: *Cursor, allocator: Allocator) error{Stop}!Buffer.Root; + const cursel_operator = *const fn (root: Buffer.Root, cursel: *CurSel, allocator: Allocator) error{Stop}!Buffer.Root; + const cursel_operator_mut = *const fn (self: *Self, root: Buffer.Root, cursel: *CurSel, allocator: Allocator) error{Stop}!Buffer.Root; fn is_not_word_char(c: []const u8) bool { if (c.len == 0) return true; @@ -1906,34 +1906,34 @@ pub const Editor = struct { fn set_clipboard(self: *Self, text: []const u8) void { if (self.clipboard) |old| - self.a.free(old); + self.allocator.free(old); self.clipboard = text; tui.current().rdr.copy_to_system_clipboard(text); } - fn copy_selection(root: Buffer.Root, sel: Selection, text_a: Allocator, plane: Plane) ![]const u8 { + fn copy_selection(root: Buffer.Root, sel: Selection, text_allocator: Allocator, plane: Plane) ![]const u8 { var size: usize = 0; _ = try root.get_range(sel, null, &size, null, plane.metrics()); - const buf__ = try text_a.alloc(u8, size); + const buf__ = try text_allocator.alloc(u8, size); return (try root.get_range(sel, buf__, null, null, plane.metrics())).?; } - pub fn get_selection(self: *const Self, sel: Selection, text_a: Allocator) ![]const u8 { - return copy_selection(try self.buf_root(), sel, text_a, self.plane); + pub fn get_selection(self: *const Self, sel: Selection, text_allocator: Allocator) ![]const u8 { + return copy_selection(try self.buf_root(), sel, text_allocator, self.plane); } - fn copy_word_at_cursor(self: *Self, text_a: Allocator) ![]const u8 { + fn copy_word_at_cursor(self: *Self, text_allocator: Allocator) ![]const u8 { const root = try self.buf_root(); const primary = self.get_primary(); const sel = if (primary.selection) |*sel| sel else try self.select_word_at_cursor(primary); - return try copy_selection(root, sel.*, text_a, self.plane); + return try copy_selection(root, sel.*, text_allocator, self.plane); } pub fn cut_selection(self: *Self, root: Buffer.Root, cursel: *CurSel) !struct { []const u8, Buffer.Root } { return if (cursel.selection) |sel| ret: { var old_selection: Selection = sel; old_selection.normalize(); - const cut_text = try copy_selection(root, sel, self.a, self.plane); + const cut_text = try copy_selection(root, sel, self.allocator, self.plane); if (cut_text.len > 100) { self.logger.print("cut:{s}...", .{std.fmt.fmtSliceEscapeLower(cut_text[0..100])}); } else { @@ -1948,11 +1948,11 @@ pub const Editor = struct { try move_cursor_buffer_end(root, &sel.end, plane); } - fn insert(self: *Self, root: Buffer.Root, cursel: *CurSel, s: []const u8, a: Allocator) !Buffer.Root { - var root_ = if (cursel.selection) |_| try self.delete_selection(root, cursel, a) else root; + fn insert(self: *Self, root: Buffer.Root, cursel: *CurSel, s: []const u8, allocator: Allocator) !Buffer.Root { + var root_ = if (cursel.selection) |_| try self.delete_selection(root, cursel, allocator) else root; const cursor = &cursel.cursor; const begin = cursel.cursor; - cursor.row, cursor.col, root_ = try root_.insert_chars(cursor.row, cursor.col, s, a, self.plane.metrics()); + cursor.row, cursor.col, root_ = try root_.insert_chars(cursor.row, cursor.col, s, allocator, self.plane.metrics()); cursor.target = cursor.col; self.nudge_insert(.{ .begin = begin, .end = cursor.* }, cursel, s.len); return root_; @@ -1970,7 +1970,7 @@ pub const Editor = struct { try move_cursor_right(root, &sel.end, self.plane); }; var first = true; - var text = std.ArrayList(u8).init(self.a); + var text = std.ArrayList(u8).init(self.allocator); for (self.cursels.items) |*cursel_| if (cursel_.*) |*cursel| { const cut_text, root = try self.cut_selection(root, cursel); if (first) { @@ -1988,10 +1988,10 @@ pub const Editor = struct { pub fn copy(self: *Self, _: Context) Result { const root = self.buf_root() catch return; var first = true; - var text = std.ArrayList(u8).init(self.a); + var text = std.ArrayList(u8).init(self.allocator); for (self.cursels.items) |*cursel_| if (cursel_.*) |*cursel| { if (cursel.selection) |sel| { - const copy_text = try copy_selection(root, sel, self.a, self.plane); + const copy_text = try copy_selection(root, sel, self.allocator, self.plane); if (first) { first = false; } else { @@ -2020,22 +2020,22 @@ pub const Editor = struct { var root = b.root; if (self.cursels.items.len == 1) { const primary = self.get_primary(); - root = try self.insert(root, primary, text, b.a); + root = try self.insert(root, primary, text, b.allocator); } else { if (std.mem.indexOfScalar(u8, text, '\n')) |_| { var pos: usize = 0; for (self.cursels.items) |*cursel_| if (cursel_.*) |*cursel| { if (std.mem.indexOfScalarPos(u8, text, pos, '\n')) |next| { - root = try self.insert(root, cursel, text[pos..next], b.a); + root = try self.insert(root, cursel, text[pos..next], b.allocator); pos = next + 1; } else { - root = try self.insert(root, cursel, text[pos..], b.a); + root = try self.insert(root, cursel, text[pos..], b.allocator); pos = 0; } }; } else { for (self.cursels.items) |*cursel_| if (cursel_.*) |*cursel| { - root = try self.insert(root, cursel, text, b.a); + root = try self.insert(root, cursel, text, b.allocator); }; } } @@ -2051,42 +2051,42 @@ pub const Editor = struct { pub fn delete_forward(self: *Self, _: Context) Result { const b = try self.buf_for_update(); - const root = try self.delete_to(move_cursor_right, b.root, b.a); + const root = try self.delete_to(move_cursor_right, b.root, b.allocator); try self.update_buf(root); self.clamp(); } pub fn delete_backward(self: *Self, _: Context) Result { const b = try self.buf_for_update(); - const root = try self.delete_to(move_cursor_left, b.root, b.a); + const root = try self.delete_to(move_cursor_left, b.root, b.allocator); try self.update_buf(root); self.clamp(); } pub fn delete_word_left(self: *Self, _: Context) Result { const b = try self.buf_for_update(); - const root = try self.delete_to(move_cursor_word_left_space, b.root, b.a); + const root = try self.delete_to(move_cursor_word_left_space, b.root, b.allocator); try self.update_buf(root); self.clamp(); } pub fn delete_word_right(self: *Self, _: Context) Result { const b = try self.buf_for_update(); - const root = try self.delete_to(move_cursor_word_right_space, b.root, b.a); + const root = try self.delete_to(move_cursor_word_right_space, b.root, b.allocator); try self.update_buf(root); self.clamp(); } pub fn delete_to_begin(self: *Self, _: Context) Result { const b = try self.buf_for_update(); - const root = try self.delete_to(move_cursor_begin, b.root, b.a); + const root = try self.delete_to(move_cursor_begin, b.root, b.allocator); try self.update_buf(root); self.clamp(); } pub fn delete_to_end(self: *Self, _: Context) Result { const b = try self.buf_for_update(); - const root = try self.delete_to(move_cursor_end, b.root, b.a); + const root = try self.delete_to(move_cursor_end, b.root, b.allocator); try self.update_buf(root); self.clamp(); } @@ -2094,7 +2094,7 @@ pub const Editor = struct { pub fn join_next_line(self: *Self, _: Context) Result { const b = try self.buf_for_update(); try self.with_cursors_const(b.root, move_cursor_end); - const root = try self.delete_to(move_cursor_right, b.root, b.a); + const root = try self.delete_to(move_cursor_right, b.root, b.allocator); try self.update_buf(root); self.clamp(); } @@ -2338,16 +2338,16 @@ pub const Editor = struct { self.clamp(); } - fn pull_cursel_up(self: *Self, root_: Buffer.Root, cursel: *CurSel, a: Allocator) error{Stop}!Buffer.Root { + fn pull_cursel_up(self: *Self, root_: Buffer.Root, cursel: *CurSel, allocator: Allocator) error{Stop}!Buffer.Root { var root = root_; const saved = cursel.*; const sel = cursel.expand_selection_to_line(root, self.plane); - var sfa = std.heap.stackFallback(4096, self.a); + var sfa = std.heap.stackFallback(4096, self.allocator); const cut_text = copy_selection(root, sel.*, sfa.get(), self.plane) catch return error.Stop; - defer a.free(cut_text); - root = try self.delete_selection(root, cursel, a); + defer allocator.free(cut_text); + root = try self.delete_selection(root, cursel, allocator); try cursel.cursor.move_up(root, self.plane.metrics()); - root = self.insert(root, cursel, cut_text, a) catch return error.Stop; + root = self.insert(root, cursel, cut_text, allocator) catch return error.Stop; cursel.* = saved; try cursel.cursor.move_up(root, self.plane.metrics()); if (cursel.selection) |*sel_| { @@ -2359,21 +2359,21 @@ pub const Editor = struct { pub fn pull_up(self: *Self, _: Context) Result { const b = try self.buf_for_update(); - const root = try self.with_cursels_mut(b.root, pull_cursel_up, b.a); + const root = try self.with_cursels_mut(b.root, pull_cursel_up, b.allocator); try self.update_buf(root); self.clamp(); } - fn pull_cursel_down(self: *Self, root_: Buffer.Root, cursel: *CurSel, a: Allocator) error{Stop}!Buffer.Root { + fn pull_cursel_down(self: *Self, root_: Buffer.Root, cursel: *CurSel, allocator: Allocator) error{Stop}!Buffer.Root { var root = root_; const saved = cursel.*; const sel = cursel.expand_selection_to_line(root, self.plane); - var sfa = std.heap.stackFallback(4096, self.a); + var sfa = std.heap.stackFallback(4096, self.allocator); const cut_text = copy_selection(root, sel.*, sfa.get(), self.plane) catch return error.Stop; - defer a.free(cut_text); - root = try self.delete_selection(root, cursel, a); + defer allocator.free(cut_text); + root = try self.delete_selection(root, cursel, allocator); try cursel.cursor.move_down(root, self.plane.metrics()); - root = self.insert(root, cursel, cut_text, a) catch return error.Stop; + root = self.insert(root, cursel, cut_text, allocator) catch return error.Stop; cursel.* = saved; try cursel.cursor.move_down(root, self.plane.metrics()); if (cursel.selection) |*sel_| { @@ -2385,20 +2385,20 @@ pub const Editor = struct { pub fn pull_down(self: *Self, _: Context) Result { const b = try self.buf_for_update(); - const root = try self.with_cursels_mut(b.root, pull_cursel_down, b.a); + const root = try self.with_cursels_mut(b.root, pull_cursel_down, b.allocator); try self.update_buf(root); self.clamp(); } - fn dupe_cursel_up(self: *Self, root_: Buffer.Root, cursel: *CurSel, a: Allocator) error{Stop}!Buffer.Root { + fn dupe_cursel_up(self: *Self, root_: Buffer.Root, cursel: *CurSel, allocator: Allocator) error{Stop}!Buffer.Root { var root = root_; const sel: Selection = if (cursel.selection) |sel_| sel_ else Selection.line_from_cursor(cursel.cursor, root, self.plane.metrics()); cursel.selection = null; - var sfa = std.heap.stackFallback(4096, self.a); + var sfa = std.heap.stackFallback(4096, self.allocator); const text = copy_selection(root, sel, sfa.get(), self.plane) catch return error.Stop; - defer a.free(text); + defer allocator.free(text); cursel.cursor = sel.begin; - root = self.insert(root, cursel, text, a) catch return error.Stop; + root = self.insert(root, cursel, text, allocator) catch return error.Stop; cursel.selection = .{ .begin = sel.begin, .end = sel.end }; cursel.cursor = sel.begin; return root; @@ -2406,42 +2406,42 @@ pub const Editor = struct { pub fn dupe_up(self: *Self, _: Context) Result { const b = try self.buf_for_update(); - const root = try self.with_cursels_mut(b.root, dupe_cursel_up, b.a); + const root = try self.with_cursels_mut(b.root, dupe_cursel_up, b.allocator); try self.update_buf(root); self.clamp(); } - fn dupe_cursel_down(self: *Self, root_: Buffer.Root, cursel: *CurSel, a: Allocator) error{Stop}!Buffer.Root { + fn dupe_cursel_down(self: *Self, root_: Buffer.Root, cursel: *CurSel, allocator: Allocator) error{Stop}!Buffer.Root { var root = root_; const sel: Selection = if (cursel.selection) |sel_| sel_ else Selection.line_from_cursor(cursel.cursor, root, self.plane.metrics()); cursel.selection = null; - var sfa = std.heap.stackFallback(4096, self.a); + var sfa = std.heap.stackFallback(4096, self.allocator); const text = copy_selection(root, sel, sfa.get(), self.plane) catch return error.Stop; - defer a.free(text); + defer allocator.free(text); cursel.cursor = sel.end; - root = self.insert(root, cursel, text, a) catch return error.Stop; + root = self.insert(root, cursel, text, allocator) catch return error.Stop; cursel.selection = .{ .begin = sel.end, .end = cursel.cursor }; return root; } pub fn dupe_down(self: *Self, _: Context) Result { const b = try self.buf_for_update(); - const root = try self.with_cursels_mut(b.root, dupe_cursel_down, b.a); + const root = try self.with_cursels_mut(b.root, dupe_cursel_down, b.allocator); try self.update_buf(root); self.clamp(); } - fn toggle_cursel_prefix(self: *Self, root_: Buffer.Root, cursel: *CurSel, a: Allocator) error{Stop}!Buffer.Root { + fn toggle_cursel_prefix(self: *Self, root_: Buffer.Root, cursel: *CurSel, allocator: Allocator) error{Stop}!Buffer.Root { var root = root_; const saved = cursel.*; const sel = cursel.expand_selection_to_line(root, self.plane); - var sfa = std.heap.stackFallback(4096, self.a); + var sfa = std.heap.stackFallback(4096, self.allocator); const alloc = sfa.get(); const text = copy_selection(root, sel.*, alloc, self.plane) catch return error.Stop; - defer a.free(text); - root = try self.delete_selection(root, cursel, a); + defer allocator.free(text); + root = try self.delete_selection(root, cursel, allocator); const new_text = text_manip.toggle_prefix_in_text(self.prefix, text, alloc) catch return error.Stop; - root = self.insert(root, cursel, new_text, a) catch return error.Stop; + root = self.insert(root, cursel, new_text, allocator) catch return error.Stop; cursel.* = saved; return root; } @@ -2453,7 +2453,7 @@ pub const Editor = struct { @memcpy(self.prefix_buf[0..prefix.len], prefix); self.prefix = self.prefix_buf[0..prefix.len]; const b = try self.buf_for_update(); - const root = try self.with_cursels_mut(b.root, toggle_cursel_prefix, b.a); + const root = try self.with_cursels_mut(b.root, toggle_cursel_prefix, b.allocator); try self.update_buf(root); } @@ -2462,35 +2462,35 @@ pub const Editor = struct { return self.toggle_prefix(command.fmt(.{comment})); } - fn indent_cursor(self: *Self, root: Buffer.Root, cursor: Cursor, a: Allocator) error{Stop}!Buffer.Root { + fn indent_cursor(self: *Self, root: Buffer.Root, cursor: Cursor, allocator: Allocator) error{Stop}!Buffer.Root { const space = " "; var cursel: CurSel = .{}; cursel.cursor = cursor; const cols = 4 - find_first_non_ws(root, cursel.cursor.row, self.plane) % 4; try smart_move_cursor_begin(root, &cursel.cursor, self.plane); - return self.insert(root, &cursel, space[0..cols], a) catch return error.Stop; + return self.insert(root, &cursel, space[0..cols], allocator) catch return error.Stop; } - fn indent_cursel(self: *Self, root_: Buffer.Root, cursel: *CurSel, a: Allocator) error{Stop}!Buffer.Root { + fn indent_cursel(self: *Self, root_: Buffer.Root, cursel: *CurSel, allocator: Allocator) error{Stop}!Buffer.Root { if (cursel.selection) |sel_| { var root = root_; var sel = sel_; sel.normalize(); while (sel.begin.row < sel.end.row) : (sel.begin.row += 1) - root = try self.indent_cursor(root, sel.begin, a); + root = try self.indent_cursor(root, sel.begin, allocator); if (sel.end.col > 0) - root = try self.indent_cursor(root, sel.end, a); + root = try self.indent_cursor(root, sel.end, allocator); return root; - } else return try self.indent_cursor(root_, cursel.cursor, a); + } else return try self.indent_cursor(root_, cursel.cursor, allocator); } pub fn indent(self: *Self, _: Context) Result { const b = try self.buf_for_update(); - const root = try self.with_cursels_mut(b.root, indent_cursel, b.a); + const root = try self.with_cursels_mut(b.root, indent_cursel, b.allocator); try self.update_buf(root); } - fn unindent_cursor(self: *Self, root: Buffer.Root, cursel: *CurSel, cursor: Cursor, a: Allocator) error{Stop}!Buffer.Root { + fn unindent_cursor(self: *Self, root: Buffer.Root, cursel: *CurSel, cursor: Cursor, allocator: Allocator) error{Stop}!Buffer.Root { const saved = cursel.*; var newroot = root; defer { @@ -2507,26 +2507,26 @@ pub const Editor = struct { sel.begin.move_begin(); try sel.end.move_to(root, sel.end.row, cols, self.plane.metrics()); if (cursel.cursor.col < cols) try cursel.cursor.move_to(root, cursel.cursor.row, cols, self.plane.metrics()); - newroot = try self.delete_selection(root, cursel, a); + newroot = try self.delete_selection(root, cursel, allocator); return newroot; } - fn unindent_cursel(self: *Self, root_: Buffer.Root, cursel: *CurSel, a: Allocator) error{Stop}!Buffer.Root { + fn unindent_cursel(self: *Self, root_: Buffer.Root, cursel: *CurSel, allocator: Allocator) error{Stop}!Buffer.Root { if (cursel.selection) |sel_| { var root = root_; var sel = sel_; sel.normalize(); while (sel.begin.row < sel.end.row) : (sel.begin.row += 1) - root = try self.unindent_cursor(root, cursel, sel.begin, a); + root = try self.unindent_cursor(root, cursel, sel.begin, allocator); if (sel.end.col > 0) - root = try self.unindent_cursor(root, cursel, sel.end, a); + root = try self.unindent_cursor(root, cursel, sel.end, allocator); return root; - } else return self.unindent_cursor(root_, cursel, cursel.cursor, a); + } else return self.unindent_cursor(root_, cursel, cursel.cursor, allocator); } pub fn unindent(self: *Self, _: Context) Result { const b = try self.buf_for_update(); - const root = try self.with_cursels_mut(b.root, unindent_cursel, b.a); + const root = try self.with_cursels_mut(b.root, unindent_cursel, b.allocator); try self.update_buf(root); } @@ -2805,7 +2805,7 @@ pub const Editor = struct { const b = try self.buf_for_update(); var root = b.root; for (self.cursels.items) |*cursel_| if (cursel_.*) |*cursel| { - root = try self.insert(root, cursel, chars, b.a); + root = try self.insert(root, cursel, chars, b.allocator); }; try self.update_buf(root); self.clamp(); @@ -2815,7 +2815,7 @@ pub const Editor = struct { const b = try self.buf_for_update(); var root = b.root; for (self.cursels.items) |*cursel_| if (cursel_.*) |*cursel| { - root = try self.insert(root, cursel, "\n", b.a); + root = try self.insert(root, cursel, "\n", b.allocator); }; try self.update_buf(root); self.clamp(); @@ -2826,15 +2826,15 @@ pub const Editor = struct { var root = b.root; for (self.cursels.items) |*cursel_| if (cursel_.*) |*cursel| { var leading_ws = @min(find_first_non_ws(root, cursel.cursor.row, self.plane), cursel.cursor.col); - var sfa = std.heap.stackFallback(512, self.a); - const a = sfa.get(); - var stream = std.ArrayList(u8).init(a); + var sfa = std.heap.stackFallback(512, self.allocator); + const allocator = sfa.get(); + var stream = std.ArrayList(u8).init(allocator); defer stream.deinit(); var writer = stream.writer(); _ = try writer.write("\n"); while (leading_ws > 0) : (leading_ws -= 1) _ = try writer.write(" "); - root = try self.insert(root, cursel, stream.items, b.a); + root = try self.insert(root, cursel, stream.items, b.allocator); }; try self.update_buf(root); self.clamp(); @@ -2845,7 +2845,7 @@ pub const Editor = struct { var root = b.root; for (self.cursels.items) |*cursel_| if (cursel_.*) |*cursel| { try move_cursor_begin(root, &cursel.cursor, self.plane); - root = try self.insert(root, cursel, "\n", b.a); + root = try self.insert(root, cursel, "\n", b.allocator); try move_cursor_left(root, &cursel.cursor, self.plane); }; try self.update_buf(root); @@ -2858,17 +2858,17 @@ pub const Editor = struct { for (self.cursels.items) |*cursel_| if (cursel_.*) |*cursel| { var leading_ws = @min(find_first_non_ws(root, cursel.cursor.row, self.plane), cursel.cursor.col); try move_cursor_begin(root, &cursel.cursor, self.plane); - root = try self.insert(root, cursel, "\n", b.a); + root = try self.insert(root, cursel, "\n", b.allocator); try move_cursor_left(root, &cursel.cursor, self.plane); - var sfa = std.heap.stackFallback(512, self.a); - const a = sfa.get(); - var stream = std.ArrayList(u8).init(a); + var sfa = std.heap.stackFallback(512, self.allocator); + const allocator = sfa.get(); + var stream = std.ArrayList(u8).init(allocator); defer stream.deinit(); var writer = stream.writer(); while (leading_ws > 0) : (leading_ws -= 1) _ = try writer.write(" "); if (stream.items.len > 0) - root = try self.insert(root, cursel, stream.items, b.a); + root = try self.insert(root, cursel, stream.items, b.allocator); }; try self.update_buf(root); self.clamp(); @@ -2879,7 +2879,7 @@ pub const Editor = struct { var root = b.root; for (self.cursels.items) |*cursel_| if (cursel_.*) |*cursel| { try move_cursor_end(root, &cursel.cursor, self.plane); - root = try self.insert(root, cursel, "\n", b.a); + root = try self.insert(root, cursel, "\n", b.allocator); }; try self.update_buf(root); self.clamp(); @@ -2891,16 +2891,16 @@ pub const Editor = struct { for (self.cursels.items) |*cursel_| if (cursel_.*) |*cursel| { var leading_ws = @min(find_first_non_ws(root, cursel.cursor.row, self.plane), cursel.cursor.col); try move_cursor_end(root, &cursel.cursor, self.plane); - var sfa = std.heap.stackFallback(512, self.a); - const a = sfa.get(); - var stream = std.ArrayList(u8).init(a); + var sfa = std.heap.stackFallback(512, self.allocator); + const allocator = sfa.get(); + var stream = std.ArrayList(u8).init(allocator); defer stream.deinit(); var writer = stream.writer(); _ = try writer.write("\n"); while (leading_ws > 0) : (leading_ws -= 1) _ = try writer.write(" "); if (stream.items.len > 0) - root = try self.insert(root, cursel, stream.items, b.a); + root = try self.insert(root, cursel, stream.items, b.allocator); }; try self.update_buf(root); self.clamp(); @@ -2935,7 +2935,7 @@ pub const Editor = struct { return; if (self.syntax) |syn| { if (self.syntax_refresh_full) { - var content = std.ArrayList(u8).init(self.a); + var content = std.ArrayList(u8).init(self.allocator); defer content.deinit(); try root.store(content.writer()); try syn.refresh_full(content.items); @@ -2945,13 +2945,13 @@ pub const Editor = struct { } self.syntax_token = token; } else { - var content = std.ArrayList(u8).init(self.a); + var content = std.ArrayList(u8).init(self.allocator); defer content.deinit(); try root.store(content.writer()); self.syntax = if (tp.env.get().is("no-syntax")) null else - syntax.create_guess_file_type(self.a, content.items, self.file_path) catch |e| switch (e) { + syntax.create_guess_file_type(self.allocator, content.items, self.file_path) catch |e| switch (e) { error.NotFound => null, else => return e, }; @@ -2965,7 +2965,7 @@ pub const Editor = struct { pub fn dump_current_line(self: *Self, _: Context) Result { const root = self.buf_root() catch return; const primary = self.get_primary(); - var tree = std.ArrayList(u8).init(self.a); + var tree = std.ArrayList(u8).init(self.allocator); defer tree.deinit(); root.debug_render_chunks(primary.cursor.row, &tree, self.plane.metrics()) catch |e| return self.logger.print("line {d}: {any}", .{ primary.cursor.row, e }); @@ -2975,7 +2975,7 @@ pub const Editor = struct { pub fn dump_current_line_tree(self: *Self, _: Context) Result { const root = self.buf_root() catch return; const primary = self.get_primary(); - var tree = std.ArrayList(u8).init(self.a); + var tree = std.ArrayList(u8).init(self.allocator); defer tree.deinit(); root.debug_line_render_tree(primary.cursor.row, &tree) catch |e| return self.logger.print("line {d} ast: {any}", .{ primary.cursor.row, e }); @@ -3052,7 +3052,7 @@ pub const Editor = struct { self.cancel_all_matches(); if (std.mem.indexOfScalar(u8, query, '\n')) |_| return; self.logger.print("find:{s}", .{std.fmt.fmtSliceEscapeLower(query)}); - var rg = try find_f(self.a, query, "A"); + var rg = try find_f(self.allocator, query, "A"); defer rg.deinit(); if (write_buffer) { var rg_buffer = rg.bufferedWriter(); @@ -3064,23 +3064,23 @@ pub const Editor = struct { pub fn push_find_history(self: *Self, query: []const u8) void { if (query.len == 0) return; const history = if (self.find_history) |*hist| hist else ret: { - self.find_history = std.ArrayList([]const u8).init(self.a); + self.find_history = std.ArrayList([]const u8).init(self.allocator); break :ret &self.find_history.?; }; for (history.items, 0..) |entry, i| if (std.mem.eql(u8, entry, query)) - self.a.free(history.orderedRemove(i)); - const new = self.a.dupe(u8, query) catch return; + self.allocator.free(history.orderedRemove(i)); + const new = self.allocator.dupe(u8, query) catch return; (history.addOne() catch return).* = new; } fn set_last_find_query(self: *Self, query: []const u8) void { if (self.last_find_query) |last| { if (query.ptr != last.ptr) { - self.a.free(last); - self.last_find_query = self.a.dupe(u8, query) catch return; + self.allocator.free(last); + self.last_find_query = self.allocator.dupe(u8, query) catch return; } - } else self.last_find_query = self.a.dupe(u8, query) catch return; + } else self.last_find_query = self.allocator.dupe(u8, query) catch return; } pub fn find_in_buffer(self: *Self, query: []const u8) !void { @@ -3104,12 +3104,12 @@ pub const Editor = struct { defer self.add_match_done(); var ctx: Ctx = .{ .self = self }; self.init_matches_update(); - try root.find_all_ranges(query, &ctx, Ctx.cb, self.a); + try root.find_all_ranges(query, &ctx, Ctx.cb, self.allocator); } fn find_in_buffer_async(self: *Self, query: []const u8) !void { const finder = struct { - a: Allocator, + allocator: Allocator, query: []const u8, parent: tp.pid_ref, root: Buffer.Root, @@ -3140,7 +3140,7 @@ pub const Editor = struct { } }; defer fdr.parent.send(.{ "A", "done", fdr.token }) catch {}; - defer fdr.a.free(fdr.query); + defer fdr.allocator.free(fdr.query); var ctx: Ctx = .{ .fdr = fdr }; try fdr.root.find_all_ranges(fdr.query, &ctx, Ctx.cb, fdr.a); try fdr.send_batch(); @@ -3165,16 +3165,16 @@ pub const Editor = struct { } }; self.init_matches_update(); - const fdr = try self.a.create(finder); + const fdr = try self.allocator.create(finder); fdr.* = .{ - .a = self.a, - .query = try self.a.dupe(u8, query), + .a = self.allocator, + .query = try self.allocator.dupe(u8, query), .parent = tp.self_pid(), .root = try self.buf_root(), .token = self.match_token, - .matches = Match.List.init(self.a), + .matches = Match.List.init(self.allocator), }; - const pid = try tp.spawn_link(self.a, fdr, finder.start, "editor.find"); + const pid = try tp.spawn_link(self.allocator, fdr, finder.start, "editor.find"); pid.deinit(); } @@ -3555,7 +3555,7 @@ pub const Editor = struct { return; } if (self.get_formatter()) |fmtr| { - var args = std.ArrayList(u8).init(self.a); + var args = std.ArrayList(u8).init(self.allocator); const writer = args.writer(); try cbor.writeArrayHeader(writer, fmtr.len); for (fmtr) |arg| try cbor.writeValue(writer, arg); @@ -3590,14 +3590,14 @@ pub const Editor = struct { .pos = .{ .cursor = sel.begin }, .old_primary = primary.*, .old_primary_reversed = reversed, - .whole_file = if (primary.selection) |_| null else std.ArrayList(u8).init(self.a), + .whole_file = if (primary.selection) |_| null else std.ArrayList(u8).init(self.allocator), }; errdefer self.filter_deinit(); const state = &self.filter.?; var buf: [1024]u8 = undefined; const json = try cmd.to_json(&buf); self.logger.print("filter: start {s}", .{json}); - var sp = try tp.subprocess.init(self.a, cmd, "filter", .Pipe); + var sp = try tp.subprocess.init(self.allocator, cmd, "filter", .Pipe); defer { sp.close() catch {}; sp.deinit(); @@ -3665,7 +3665,7 @@ pub const Editor = struct { self.filter = null; } - fn to_upper_cursel(self: *Self, root_: Buffer.Root, cursel: *CurSel, a: Allocator) error{Stop}!Buffer.Root { + fn to_upper_cursel(self: *Self, root_: Buffer.Root, cursel: *CurSel, allocator: Allocator) error{Stop}!Buffer.Root { var root = root_; const saved = cursel.*; const sel = if (cursel.selection) |*sel| sel else ret: { @@ -3674,27 +3674,27 @@ pub const Editor = struct { move_cursor_word_end(root, &sel.end, self.plane) catch return error.Stop; break :ret sel; }; - var sfa = std.heap.stackFallback(4096, self.a); + var sfa = std.heap.stackFallback(4096, self.allocator); const cut_text = copy_selection(root, sel.*, sfa.get(), self.plane) catch return error.Stop; - defer a.free(cut_text); - const cd = CaseData.init(a) catch return error.Stop; + defer allocator.free(cut_text); + const cd = CaseData.init(allocator) catch return error.Stop; defer cd.deinit(); - const ucased = cd.toUpperStr(a, cut_text) catch return error.Stop; - defer a.free(ucased); - root = try self.delete_selection(root, cursel, a); - root = self.insert(root, cursel, ucased, a) catch return error.Stop; + const ucased = cd.toUpperStr(allocator, cut_text) catch return error.Stop; + defer allocator.free(ucased); + root = try self.delete_selection(root, cursel, allocator); + root = self.insert(root, cursel, ucased, allocator) catch return error.Stop; cursel.* = saved; return root; } pub fn to_upper(self: *Self, _: Context) Result { const b = try self.buf_for_update(); - const root = try self.with_cursels_mut(b.root, to_upper_cursel, b.a); + const root = try self.with_cursels_mut(b.root, to_upper_cursel, b.allocator); try self.update_buf(root); self.clamp(); } - fn to_lower_cursel(self: *Self, root_: Buffer.Root, cursel: *CurSel, a: Allocator) error{Stop}!Buffer.Root { + fn to_lower_cursel(self: *Self, root_: Buffer.Root, cursel: *CurSel, allocator: Allocator) error{Stop}!Buffer.Root { var root = root_; const saved = cursel.*; const sel = if (cursel.selection) |*sel| sel else ret: { @@ -3703,29 +3703,29 @@ pub const Editor = struct { move_cursor_word_end(root, &sel.end, self.plane) catch return error.Stop; break :ret sel; }; - var sfa = std.heap.stackFallback(4096, self.a); + var sfa = std.heap.stackFallback(4096, self.allocator); const cut_text = copy_selection(root, sel.*, sfa.get(), self.plane) catch return error.Stop; - defer a.free(cut_text); - const cd = CaseData.init(a) catch return error.Stop; + defer allocator.free(cut_text); + const cd = CaseData.init(allocator) catch return error.Stop; defer cd.deinit(); - const ucased = cd.toLowerStr(a, cut_text) catch return error.Stop; - defer a.free(ucased); - root = try self.delete_selection(root, cursel, a); - root = self.insert(root, cursel, ucased, a) catch return error.Stop; + const ucased = cd.toLowerStr(allocator, cut_text) catch return error.Stop; + defer allocator.free(ucased); + root = try self.delete_selection(root, cursel, allocator); + root = self.insert(root, cursel, ucased, allocator) catch return error.Stop; cursel.* = saved; return root; } pub fn to_lower(self: *Self, _: Context) Result { const b = try self.buf_for_update(); - const root = try self.with_cursels_mut(b.root, to_lower_cursel, b.a); + const root = try self.with_cursels_mut(b.root, to_lower_cursel, b.allocator); try self.update_buf(root); self.clamp(); } }; -pub fn create(a: Allocator, parent: Widget) !Widget { - return EditorWidget.create(a, parent); +pub fn create(allocator: Allocator, parent: Widget) !Widget { + return EditorWidget.create(allocator, parent); } pub const EditorWidget = struct { @@ -3744,19 +3744,19 @@ pub const EditorWidget = struct { const Self = @This(); const Commands = command.Collection(Editor); - fn create(a: Allocator, parent: Widget) !Widget { - const container = try WidgetList.createH(a, parent, "editor.container", .dynamic); - const self: *Self = try a.create(Self); - try self.init(a, container.widget()); + fn create(allocator: Allocator, parent: Widget) !Widget { + const container = try WidgetList.createH(allocator, parent, "editor.container", .dynamic); + const self: *Self = try allocator.create(Self); + try self.init(allocator, container.widget()); try self.commands.init(&self.editor); const editorWidget = Widget.to(self); - try container.add(try editor_gutter.create(a, container.widget(), editorWidget, &self.editor)); + try container.add(try editor_gutter.create(allocator, container.widget(), editorWidget, &self.editor)); try container.add(editorWidget); - try container.add(try scrollbar_v.create(a, container.widget(), editorWidget, EventHandler.to_unowned(container))); + try container.add(try scrollbar_v.create(allocator, container.widget(), editorWidget, EventHandler.to_unowned(container))); return container.widget(); } - fn init(self: *Self, a: Allocator, parent: Widget) !void { + fn init(self: *Self, allocator: Allocator, parent: Widget) !void { var n = try Plane.init(&(Widget.Box{}).opts("editor"), parent.plane.*); errdefer n.deinit(); @@ -3765,16 +3765,16 @@ pub const EditorWidget = struct { .plane = n, .editor = undefined, }; - self.editor.init(a, n); + self.editor.init(allocator, n); errdefer self.editor.deinit(); try self.editor.push_cursor(); } - pub fn deinit(self: *Self, a: Allocator) void { + pub fn deinit(self: *Self, allocator: Allocator) void { self.commands.deinit(); self.editor.deinit(); self.plane.deinit(); - a.destroy(self); + allocator.destroy(self); } pub fn update(self: *Self) void { @@ -3932,9 +3932,9 @@ pub const PosToWidthCache = struct { const Self = @This(); - pub fn init(a: Allocator) !Self { + pub fn init(allocator: Allocator) !Self { return .{ - .cache = try std.ArrayList(usize).initCapacity(a, 2048), + .cache = try std.ArrayList(usize).initCapacity(allocator, 2048), }; } diff --git a/src/tui/editor_gutter.zig b/src/tui/editor_gutter.zig index ead5462..bc8ddaa 100644 --- a/src/tui/editor_gutter.zig +++ b/src/tui/editor_gutter.zig @@ -19,7 +19,7 @@ const tui = @import("tui.zig"); const command = @import("command.zig"); const ed = @import("editor.zig"); -a: Allocator, +allocator: Allocator, plane: Plane, parent: Widget, @@ -40,10 +40,10 @@ const Self = @This(); const Kind = enum { insert, modified, delete }; const Symbol = struct { kind: Kind, line: usize }; -pub fn create(a: Allocator, parent: Widget, event_source: Widget, editor: *ed.Editor) !Widget { - const self: *Self = try a.create(Self); +pub fn create(allocator: Allocator, parent: Widget, event_source: Widget, editor: *ed.Editor) !Widget { + const self: *Self = try allocator.create(Self); self.* = .{ - .a = a, + .allocator = allocator, .plane = try Plane.init(&(Widget.Box{}).opts(@typeName(Self)), parent.plane.*), .parent = parent, .linenum = tui.current().config.gutter_line_numbers, @@ -51,7 +51,7 @@ pub fn create(a: Allocator, parent: Widget, event_source: Widget, editor: *ed.Ed .highlight = tui.current().config.highlight_current_line_gutter, .editor = editor, .diff = try diff.create(), - .diff_symbols = std.ArrayList(Symbol).init(a), + .diff_symbols = std.ArrayList(Symbol).init(allocator), }; try tui.current().message_filters.add(MessageFilter.bind(self, filter_receive)); try event_source.subscribe(EventHandler.bind(self, handle_event)); @@ -62,12 +62,12 @@ pub fn widget(self: *Self) Widget { return Widget.to(self); } -pub fn deinit(self: *Self, a: Allocator) void { +pub fn deinit(self: *Self, allocator: Allocator) void { self.diff_symbols_clear(); self.diff_symbols.deinit(); tui.current().message_filters.remove_ptr(self); self.plane.deinit(); - a.destroy(self); + allocator.destroy(self); } fn diff_symbols_clear(self: *Self) void { diff --git a/src/tui/filelist_view.zig b/src/tui/filelist_view.zig index 8e4a093..6402d83 100644 --- a/src/tui/filelist_view.zig +++ b/src/tui/filelist_view.zig @@ -76,10 +76,10 @@ pub fn create(allocator: Allocator, parent: Plane) !Widget { return Widget.to(self); } -pub fn deinit(self: *Self, a: Allocator) void { +pub fn deinit(self: *Self, allocator: Allocator) void { self.plane.deinit(); self.commands.deinit(); - a.destroy(self); + allocator.destroy(self); } fn scrollbar_style(sb: *scrollbar_v, theme: *const Widget.Theme) Widget.Theme.Style { diff --git a/src/tui/home.zig b/src/tui/home.zig index b1d2f6a..a1ddd68 100644 --- a/src/tui/home.zig +++ b/src/tui/home.zig @@ -15,7 +15,7 @@ const tui = @import("tui.zig"); const command = @import("command.zig"); const fonts = @import("fonts.zig"); -a: std.mem.Allocator, +allocator: std.mem.Allocator, plane: Plane, parent: Plane, fire: ?Fire = null, @@ -24,17 +24,17 @@ menu: *Menu.State(*Self), const Self = @This(); -pub fn create(a: std.mem.Allocator, parent: Widget) !Widget { - const self: *Self = try a.create(Self); +pub fn create(allocator: std.mem.Allocator, parent: Widget) !Widget { + const self: *Self = try allocator.create(Self); var n = try Plane.init(&(Widget.Box{}).opts("editor"), parent.plane.*); errdefer n.deinit(); const w = Widget.to(self); self.* = .{ - .a = a, + .allocator = allocator, .parent = parent.plane.*, .plane = n, - .menu = try Menu.create(*Self, a, w, .{ .ctx = self, .on_render = menu_on_render }), + .menu = try Menu.create(*Self, allocator, w, .{ .ctx = self, .on_render = menu_on_render }), }; try self.commands.init(self); try self.menu.add_item_with_handler("Help ······················· :h", menu_action_help); @@ -50,12 +50,12 @@ pub fn create(a: std.mem.Allocator, parent: Widget) !Widget { return w; } -pub fn deinit(self: *Self, a: std.mem.Allocator) void { - self.menu.deinit(a); +pub fn deinit(self: *Self, allocator: std.mem.Allocator) void { + self.menu.deinit(allocator); self.commands.deinit(); self.plane.deinit(); if (self.fire) |*fire| fire.deinit(); - a.destroy(self); + allocator.destroy(self); } pub fn update(self: *Self) void { @@ -186,7 +186,7 @@ pub fn handle_resize(self: *Self, pos: Widget.Box) void { self.plane.resize_simple(@intCast(pos.h), @intCast(pos.w)) catch return; if (self.fire) |*fire| { fire.deinit(); - self.fire = Fire.init(self.a, self.plane) catch return; + self.fire = Fire.init(self.allocator, self.plane) catch return; } } @@ -213,7 +213,7 @@ const cmds = struct { self.fire = if (self.fire) |*fire| ret: { fire.deinit(); break :ret null; - } else try Fire.init(self.a, self.plane); + } else try Fire.init(self.allocator, self.plane); } }; @@ -239,12 +239,12 @@ const Fire = struct { const MAX_COLOR = 256; const LAST_COLOR = MAX_COLOR - 1; - fn init(a: std.mem.Allocator, plane: Plane) !Fire { + fn init(allocator: std.mem.Allocator, plane: Plane) !Fire { const pos = Widget.Box.from(plane); const FIRE_H = @as(u16, @intCast(pos.h)) * 2; const FIRE_W = @as(u16, @intCast(pos.w)); var self: Fire = .{ - .allocator = a, + .allocator = allocator, .plane = plane, .prng = std.Random.DefaultPrng.init(blk: { var seed: u64 = undefined; @@ -255,7 +255,7 @@ const Fire = struct { .FIRE_W = FIRE_W, .FIRE_SZ = FIRE_H * FIRE_W, .FIRE_LAST_ROW = (FIRE_H - 1) * FIRE_W, - .screen_buf = try a.alloc(u8, FIRE_H * FIRE_W), + .screen_buf = try allocator.alloc(u8, FIRE_H * FIRE_W), }; var buf_idx: u16 = 0; diff --git a/src/tui/inputview.zig b/src/tui/inputview.zig index 1c137f4..147d6b6 100644 --- a/src/tui/inputview.zig +++ b/src/tui/inputview.zig @@ -15,7 +15,7 @@ const EventHandler = @import("EventHandler.zig"); pub const name = "inputview"; -a: Allocator, +allocator: Allocator, parent: Plane, plane: Plane, last_count: u64 = 0, @@ -30,27 +30,27 @@ const Entry = struct { }; const Buffer = ArrayList(Entry); -pub fn create(a: Allocator, parent: Plane) !Widget { - const self: *Self = try a.create(Self); +pub fn create(allocator: Allocator, parent: Plane) !Widget { + const self: *Self = try allocator.create(Self); var n = try Plane.init(&(Widget.Box{}).opts_vscroll(@typeName(Self)), parent); errdefer n.deinit(); self.* = .{ - .a = a, + .allocator = allocator, .parent = parent, .plane = n, - .buffer = Buffer.init(a), + .buffer = Buffer.init(allocator), }; try tui.current().input_listeners.add(EventHandler.bind(self, listen)); return Widget.to(self); } -pub fn deinit(self: *Self, a: Allocator) void { +pub fn deinit(self: *Self, allocator: Allocator) void { tui.current().input_listeners.remove_ptr(self); for (self.buffer.items) |item| self.buffer.allocator.free(item.json); self.buffer.deinit(); self.plane.deinit(); - a.destroy(self); + allocator.destroy(self); } pub fn render(self: *Self, theme: *const Widget.Theme) bool { @@ -96,7 +96,7 @@ fn append(self: *Self, json: []const u8) !void { (try self.buffer.addOne()).* = .{ .time = ts, .tdiff = tdiff, - .json = try self.a.dupeZ(u8, json), + .json = try self.allocator.dupeZ(u8, json), }; } diff --git a/src/tui/inspector_view.zig b/src/tui/inspector_view.zig index b048b12..91e0c87 100644 --- a/src/tui/inspector_view.zig +++ b/src/tui/inspector_view.zig @@ -27,13 +27,13 @@ last_node: usize = 0, const Self = @This(); -pub fn create(a: Allocator, parent: Plane) !Widget { +pub fn create(allocator: Allocator, parent: Plane) !Widget { if (tui.current().mainview.dynamic_cast(mainview)) |mv_| if (mv_.get_editor()) |editor| { - const self: *Self = try a.create(Self); + const self: *Self = try allocator.create(Self); self.* = .{ .plane = try Plane.init(&(Widget.Box{}).opts_vscroll(name), parent), .editor = editor, - .pos_cache = try ed.PosToWidthCache.init(a), + .pos_cache = try ed.PosToWidthCache.init(allocator), }; try editor.handlers.add(EventHandler.bind(self, ed_receive)); @@ -42,11 +42,11 @@ pub fn create(a: Allocator, parent: Plane) !Widget { return error.NotFound; } -pub fn deinit(self: *Self, a: Allocator) void { +pub fn deinit(self: *Self, allocator: Allocator) void { self.editor.handlers.remove_ptr(self); tui.current().message_filters.remove_ptr(self); self.plane.deinit(); - a.destroy(self); + allocator.destroy(self); } pub fn render(self: *Self, theme: *const Widget.Theme) bool { diff --git a/src/tui/logview.zig b/src/tui/logview.zig index 2636529..8ea7e9e 100644 --- a/src/tui/logview.zig +++ b/src/tui/logview.zig @@ -39,15 +39,15 @@ const Level = enum { err, }; -pub fn create(a: Allocator, parent: Plane) !Widget { - const self: *Self = try a.create(Self); +pub fn create(allocator: Allocator, parent: Plane) !Widget { + const self: *Self = try allocator.create(Self); self.* = .{ .plane = try Plane.init(&(Widget.Box{}).opts(name), parent) }; return Widget.to(self); } -pub fn deinit(self: *Self, a: Allocator) void { +pub fn deinit(self: *Self, allocator: Allocator) void { self.plane.deinit(); - a.destroy(self); + allocator.destroy(self); } pub fn render(self: *Self, theme: *const Widget.Theme) bool { @@ -140,7 +140,7 @@ fn get_buffer() *Buffer { return if (persistent_buffer) |*p| p else @panic("logview.get_buffer called before init"); } -pub fn init(a: Allocator) void { +pub fn init(allocator: Allocator) void { if (persistent_buffer) |_| return; - persistent_buffer = Buffer.init(a); + persistent_buffer = Buffer.init(allocator); } diff --git a/src/tui/mainview.zig b/src/tui/mainview.zig index 66dc541..116b3e6 100644 --- a/src/tui/mainview.zig +++ b/src/tui/mainview.zig @@ -28,7 +28,7 @@ const filelist_view = @import("filelist_view.zig"); const Self = @This(); const Commands = command.Collection(cmds); -a: std.mem.Allocator, +allocator: std.mem.Allocator, plane: Plane, widgets: *WidgetList, widgets_widget: Widget, @@ -61,30 +61,30 @@ const FileListType = enum { find_in_files, }; -pub fn create(a: std.mem.Allocator) !Widget { - const self = try a.create(Self); +pub fn create(allocator: std.mem.Allocator) !Widget { + const self = try allocator.create(Self); self.* = .{ - .a = a, + .allocator = allocator, .plane = tui.current().stdplane(), .widgets = undefined, .widgets_widget = undefined, - .floating_views = WidgetStack.init(a), + .floating_views = WidgetStack.init(allocator), .location_history = try location_history.create(), - .file_stack = std.ArrayList([]const u8).init(a), + .file_stack = std.ArrayList([]const u8).init(allocator), .view_widget_idx = 0, }; try self.commands.init(self); const w = Widget.to(self); - const widgets = try WidgetList.createV(a, w, @typeName(Self), .dynamic); + const widgets = try WidgetList.createV(allocator, w, @typeName(Self), .dynamic); self.widgets = widgets; self.widgets_widget = widgets.widget(); if (tui.current().config.top_bar.len > 0) { - self.top_bar = try widgets.addP(try @import("status/bar.zig").create(a, w, tui.current().config.top_bar, .none, null)); + self.top_bar = try widgets.addP(try @import("status/bar.zig").create(allocator, w, tui.current().config.top_bar, .none, null)); self.view_widget_idx += 1; } - try widgets.add(try Widget.empty(a, self.widgets_widget.plane.*, .dynamic)); + try widgets.add(try Widget.empty(allocator, self.widgets_widget.plane.*, .dynamic)); if (tui.current().config.bottom_bar.len > 0) { - self.bottom_bar = try widgets.addP(try @import("status/bar.zig").create(a, w, tui.current().config.bottom_bar, .grip, EventHandler.bind(self, handle_bottom_bar_event))); + self.bottom_bar = try widgets.addP(try @import("status/bar.zig").create(allocator, w, tui.current().config.bottom_bar, .grip, EventHandler.bind(self, handle_bottom_bar_event))); } if (tp.env.get().is("show-input")) self.toggle_inputview_async(); @@ -93,14 +93,14 @@ pub fn create(a: std.mem.Allocator) !Widget { return w; } -pub fn deinit(self: *Self, a: std.mem.Allocator) void { +pub fn deinit(self: *Self, allocator: std.mem.Allocator) void { self.close_all_panel_views(); self.clear_file_stack(); self.file_stack.deinit(); self.commands.deinit(); - self.widgets.deinit(a); + self.widgets.deinit(allocator); self.floating_views.deinit(); - a.destroy(self); + allocator.destroy(self); } pub fn receive(self: *Self, from_: tp.pid_ref, m: tp.message) error{Exit}!bool { @@ -180,12 +180,12 @@ fn toggle_panel_view(self: *Self, view: anytype, enable_only: bool) !void { } } } else { - try panels.add(try view.create(self.a, self.widgets.plane)); + try panels.add(try view.create(self.allocator, self.widgets.plane)); } } else { - const panels = try WidgetList.createH(self.a, self.widgets.widget(), "panel", .{ .static = self.panel_height orelse self.box().h / 5 }); + const panels = try WidgetList.createH(self.allocator, self.widgets.widget(), "panel", .{ .static = self.panel_height orelse self.box().h / 5 }); try self.widgets.add(panels.widget()); - try panels.add(try view.create(self.a, self.widgets.plane)); + try panels.add(try view.create(self.allocator, self.widgets.plane)); self.panels = panels; } tui.current().resize(); @@ -211,7 +211,7 @@ fn toggle_view(self: *Self, view: anytype) !void { if (self.widgets.get(@typeName(view))) |w| { self.widgets.remove(w.*); } else { - try self.widgets.add(try view.create(self.a, self.plane)); + try self.widgets.add(try view.create(self.allocator, self.plane)); } tui.current().resize(); } @@ -269,8 +269,8 @@ const cmds = struct { tui.current().rdr.set_terminal_working_directory(project); if (self.top_bar) |bar| _ = try bar.msg(.{ "PRJ", "open" }); if (self.bottom_bar) |bar| _ = try bar.msg(.{ "PRJ", "open" }); - if (try project_manager.request_most_recent_file(self.a)) |file_path| { - defer self.a.free(file_path); + if (try project_manager.request_most_recent_file(self.allocator)) |file_path| { + defer self.allocator.free(file_path); try tp.self_pid().send(.{ "cmd", "navigate", .{ .file = file_path } }); } } @@ -523,7 +523,7 @@ pub fn handle_editor_event(self: *Self, _: tp.pid_ref, m: tp.message) tp.result if (try m.match(.{ "E", "close" })) { if (self.pop_file_stack(editor.file_path)) |file_path| { - defer self.a.free(file_path); + defer self.allocator.free(file_path); self.show_previous_async(file_path); } else self.show_home_async(); self.editor = null; @@ -537,7 +537,7 @@ pub fn handle_editor_event(self: *Self, _: tp.pid_ref, m: tp.message) tp.result sel.normalize(); if (sel.end.row - sel.begin.row > ed.max_match_lines) return self.clear_auto_find(editor); - const text = editor.get_selection(sel, self.a) catch return self.clear_auto_find(editor); + const text = editor.get_selection(sel, self.allocator) catch return self.clear_auto_find(editor); if (text.len == 0) return self.clear_auto_find(editor); if (!self.is_last_match_text(text)) { @@ -552,7 +552,7 @@ pub fn find_in_files(self: *Self, query: []const u8) !void { log.logger("find").print("finding files...", .{}); const find_f = ripgrep.find_in_files; if (std.mem.indexOfScalar(u8, query, '\n')) |_| return; - var rg = try find_f(self.a, query, "FIF"); + var rg = try find_f(self.allocator, query, "FIF"); defer rg.deinit(); } @@ -600,7 +600,7 @@ fn is_last_match_text(self: *Self, text: []const u8) bool { fn store_last_match_text(self: *Self, text: ?[]const u8) void { if (self.last_match_text) |old| - self.a.free(old); + self.allocator.free(old); self.last_match_text = text; } @@ -614,10 +614,10 @@ pub fn walk(self: *Self, ctx: *anyopaque, f: Widget.WalkFn, w: *Widget) bool { fn create_editor(self: *Self) !void { if (self.editor) |editor| if (editor.file_path) |file_path| self.push_file_stack(file_path) catch {}; - self.widgets.replace(self.view_widget_idx, try Widget.empty(self.a, self.plane, .dynamic)); + self.widgets.replace(self.view_widget_idx, try Widget.empty(self.allocator, self.plane, .dynamic)); command.executeName("enter_mode_default", .{}) catch {}; - var editor_widget = try ed.create(self.a, Widget.to(self)); - errdefer editor_widget.deinit(self.a); + var editor_widget = try ed.create(self.allocator, Widget.to(self)); + errdefer editor_widget.deinit(self.allocator); if (editor_widget.get("editor")) |editor| { if (self.top_bar) |bar| editor.subscribe(EventHandler.to_unowned(bar)) catch @panic("subscribe unsupported"); if (self.bottom_bar) |bar| editor.subscribe(EventHandler.to_unowned(bar)) catch @panic("subscribe unsupported"); @@ -647,15 +647,15 @@ fn show_home_async(_: *Self) void { fn create_home(self: *Self) !void { tui.reset_drag_context(); if (self.editor) |_| return; - var home_widget = try home.create(self.a, Widget.to(self)); - errdefer home_widget.deinit(self.a); + var home_widget = try home.create(self.allocator, Widget.to(self)); + errdefer home_widget.deinit(self.allocator); self.widgets.replace(self.view_widget_idx, home_widget); tui.current().resize(); } fn write_restore_info(self: *Self) void { if (self.editor) |editor| { - var sfa = std.heap.stackFallback(512, self.a); + var sfa = std.heap.stackFallback(512, self.allocator); const a = sfa.get(); var meta = std.ArrayList(u8).init(a); editor.write_state(meta.writer()) catch return; @@ -672,8 +672,8 @@ fn read_restore_info(self: *Self) !void { const file = try std.fs.cwd().openFile(file_name, .{ .mode = .read_only }); defer file.close(); const stat = try file.stat(); - var buf = try self.a.alloc(u8, @intCast(stat.size)); - defer self.a.free(buf); + var buf = try self.allocator.alloc(u8, @intCast(stat.size)); + defer self.allocator.free(buf); const size = try file.readAll(buf); try editor.extract_state(buf[0..size]); } @@ -682,20 +682,20 @@ fn read_restore_info(self: *Self) !void { fn push_file_stack(self: *Self, file_path: []const u8) !void { for (self.file_stack.items, 0..) |file_path_, i| if (std.mem.eql(u8, file_path, file_path_)) - self.a.free(self.file_stack.orderedRemove(i)); - (try self.file_stack.addOne()).* = try self.a.dupe(u8, file_path); + self.allocator.free(self.file_stack.orderedRemove(i)); + (try self.file_stack.addOne()).* = try self.allocator.dupe(u8, file_path); } fn pop_file_stack(self: *Self, closed: ?[]const u8) ?[]const u8 { if (closed) |file_path| for (self.file_stack.items, 0..) |file_path_, i| if (std.mem.eql(u8, file_path, file_path_)) - self.a.free(self.file_stack.orderedRemove(i)); + self.allocator.free(self.file_stack.orderedRemove(i)); return self.file_stack.popOrNull(); } fn clear_file_stack(self: *Self) void { - for (self.file_stack.items) |file_path| self.a.free(file_path); + for (self.file_stack.items) |file_path| self.allocator.free(file_path); self.file_stack.clearRetainingCapacity(); } diff --git a/src/tui/mode/input/flow.zig b/src/tui/mode/input/flow.zig index 17c5d17..528916f 100644 --- a/src/tui/mode/input/flow.zig +++ b/src/tui/mode/input/flow.zig @@ -18,16 +18,16 @@ const eql = @import("std").mem.eql; const Self = @This(); const input_buffer_size = 1024; -a: Allocator, +allocator: Allocator, input: ArrayList(u8), last_cmd: []const u8 = "", leader: ?struct { keypress: u32, modifiers: u32 } = null, -pub fn create(a: Allocator) !tui.Mode { - const self: *Self = try a.create(Self); +pub fn create(allocator: Allocator) !tui.Mode { + const self: *Self = try allocator.create(Self); self.* = .{ - .a = a, - .input = try ArrayList(u8).initCapacity(a, input_buffer_size), + .allocator = allocator, + .input = try ArrayList(u8).initCapacity(allocator, input_buffer_size), }; return .{ .handler = EventHandler.to_owned(self), @@ -39,7 +39,7 @@ pub fn create(a: Allocator) !tui.Mode { pub fn deinit(self: *Self) void { self.input.deinit(); - self.a.destroy(self); + self.allocator.destroy(self); } pub fn receive(self: *Self, _: tp.pid_ref, m: tp.message) error{Exit}!bool { diff --git a/src/tui/mode/input/helix/insert.zig b/src/tui/mode/input/helix/insert.zig index 41ca65f..b274bfc 100644 --- a/src/tui/mode/input/helix/insert.zig +++ b/src/tui/mode/input/helix/insert.zig @@ -17,17 +17,17 @@ const eql = @import("std").mem.eql; const Self = @This(); const input_buffer_size = 1024; -a: Allocator, +allocator: Allocator, input: ArrayList(u8), last_cmd: []const u8 = "", leader: ?struct { keypress: u32, modifiers: u32 } = null, commands: Commands = undefined, -pub fn create(a: Allocator) !tui.Mode { - const self: *Self = try a.create(Self); +pub fn create(allocator: Allocator) !tui.Mode { + const self: *Self = try allocator.create(Self); self.* = .{ - .a = a, - .input = try ArrayList(u8).initCapacity(a, input_buffer_size), + .allocator = allocator, + .input = try ArrayList(u8).initCapacity(allocator, input_buffer_size), }; try self.commands.init(self); return .{ @@ -42,7 +42,7 @@ pub fn create(a: Allocator) !tui.Mode { pub fn deinit(self: *Self) void { self.commands.deinit(); self.input.deinit(); - self.a.destroy(self); + self.allocator.destroy(self); } pub fn receive(self: *Self, _: tp.pid_ref, m: tp.message) error{Exit}!bool { diff --git a/src/tui/mode/input/helix/normal.zig b/src/tui/mode/input/helix/normal.zig index 12f940e..9d03ef9 100644 --- a/src/tui/mode/input/helix/normal.zig +++ b/src/tui/mode/input/helix/normal.zig @@ -17,18 +17,18 @@ const eql = @import("std").mem.eql; const Self = @This(); const input_buffer_size = 1024; -a: Allocator, +allocator: Allocator, input: ArrayList(u8), last_cmd: []const u8 = "", leader: ?struct { keypress: u32, modifiers: u32 } = null, count: usize = 0, commands: Commands = undefined, -pub fn create(a: Allocator) !tui.Mode { - const self: *Self = try a.create(Self); +pub fn create(allocator: Allocator) !tui.Mode { + const self: *Self = try allocator.create(Self); self.* = .{ - .a = a, - .input = try ArrayList(u8).initCapacity(a, input_buffer_size), + .allocator = allocator, + .input = try ArrayList(u8).initCapacity(allocator, input_buffer_size), }; try self.commands.init(self); return .{ @@ -44,7 +44,7 @@ pub fn create(a: Allocator) !tui.Mode { pub fn deinit(self: *Self) void { self.commands.deinit(); self.input.deinit(); - self.a.destroy(self); + self.allocator.destroy(self); } pub fn receive(self: *Self, _: tp.pid_ref, m: tp.message) error{Exit}!bool { diff --git a/src/tui/mode/input/helix/select.zig b/src/tui/mode/input/helix/select.zig index 321c5ab..36a2b34 100644 --- a/src/tui/mode/input/helix/select.zig +++ b/src/tui/mode/input/helix/select.zig @@ -17,18 +17,18 @@ const eql = @import("std").mem.eql; const Self = @This(); const input_buffer_size = 1024; -a: Allocator, +allocator: Allocator, input: ArrayList(u8), last_cmd: []const u8 = "", leader: ?struct { keypress: u32, modifiers: u32 } = null, count: usize = 0, commands: Commands = undefined, -pub fn create(a: Allocator) !tui.Mode { - const self: *Self = try a.create(Self); +pub fn create(allocator: Allocator) !tui.Mode { + const self: *Self = try allocator.create(Self); self.* = .{ - .a = a, - .input = try ArrayList(u8).initCapacity(a, input_buffer_size), + .allocator = allocator, + .input = try ArrayList(u8).initCapacity(allocator, input_buffer_size), }; try self.commands.init(self); return .{ @@ -44,7 +44,7 @@ pub fn create(a: Allocator) !tui.Mode { pub fn deinit(self: *Self) void { self.commands.deinit(); self.input.deinit(); - self.a.destroy(self); + self.allocator.destroy(self); } pub fn receive(self: *Self, _: tp.pid_ref, m: tp.message) error{Exit}!bool { diff --git a/src/tui/mode/input/home.zig b/src/tui/mode/input/home.zig index d0514d1..9623dd4 100644 --- a/src/tui/mode/input/home.zig +++ b/src/tui/mode/input/home.zig @@ -12,14 +12,14 @@ const EventHandler = @import("../../EventHandler.zig"); const Self = @This(); -a: std.mem.Allocator, +allocator: std.mem.Allocator, f: usize = 0, leader: ?struct { keypress: u32, modifiers: u32 } = null, -pub fn create(a: std.mem.Allocator) !tui.Mode { - const self: *Self = try a.create(Self); +pub fn create(allocator: std.mem.Allocator) !tui.Mode { + const self: *Self = try allocator.create(Self); self.* = .{ - .a = a, + .allocator = allocator, }; return .{ .handler = EventHandler.to_owned(self), @@ -30,7 +30,7 @@ pub fn create(a: std.mem.Allocator) !tui.Mode { } pub fn deinit(self: *Self) void { - self.a.destroy(self); + self.allocator.destroy(self); } pub fn receive(self: *Self, _: tp.pid_ref, m: tp.message) error{Exit}!bool { diff --git a/src/tui/mode/input/vim/insert.zig b/src/tui/mode/input/vim/insert.zig index 109f69c..3a2e6c1 100644 --- a/src/tui/mode/input/vim/insert.zig +++ b/src/tui/mode/input/vim/insert.zig @@ -17,17 +17,17 @@ const eql = @import("std").mem.eql; const Self = @This(); const input_buffer_size = 1024; -a: Allocator, +allocator: Allocator, input: ArrayList(u8), last_cmd: []const u8 = "", leader: ?struct { keypress: u32, modifiers: u32 } = null, commands: Commands = undefined, -pub fn create(a: Allocator) !tui.Mode { - const self: *Self = try a.create(Self); +pub fn create(allocator: Allocator) !tui.Mode { + const self: *Self = try allocator.create(Self); self.* = .{ - .a = a, - .input = try ArrayList(u8).initCapacity(a, input_buffer_size), + .allocator = allocator, + .input = try ArrayList(u8).initCapacity(allocator, input_buffer_size), }; try self.commands.init(self); return .{ @@ -42,7 +42,7 @@ pub fn create(a: Allocator) !tui.Mode { pub fn deinit(self: *Self) void { self.commands.deinit(); self.input.deinit(); - self.a.destroy(self); + self.allocator.destroy(self); } pub fn receive(self: *Self, _: tp.pid_ref, m: tp.message) error{Exit}!bool { diff --git a/src/tui/mode/input/vim/normal.zig b/src/tui/mode/input/vim/normal.zig index 0fbd73e..bf99361 100644 --- a/src/tui/mode/input/vim/normal.zig +++ b/src/tui/mode/input/vim/normal.zig @@ -17,18 +17,18 @@ const eql = @import("std").mem.eql; const Self = @This(); const input_buffer_size = 1024; -a: Allocator, +allocator: Allocator, input: ArrayList(u8), last_cmd: []const u8 = "", leader: ?struct { keypress: u32, modifiers: u32 } = null, count: usize = 0, commands: Commands = undefined, -pub fn create(a: Allocator) !tui.Mode { - const self: *Self = try a.create(Self); +pub fn create(allocator: Allocator) !tui.Mode { + const self: *Self = try allocator.create(Self); self.* = .{ - .a = a, - .input = try ArrayList(u8).initCapacity(a, input_buffer_size), + .allocator = allocator, + .input = try ArrayList(u8).initCapacity(allocator, input_buffer_size), }; try self.commands.init(self); return .{ @@ -44,7 +44,7 @@ pub fn create(a: Allocator) !tui.Mode { pub fn deinit(self: *Self) void { self.commands.deinit(); self.input.deinit(); - self.a.destroy(self); + self.allocator.destroy(self); } pub fn receive(self: *Self, _: tp.pid_ref, m: tp.message) error{Exit}!bool { diff --git a/src/tui/mode/input/vim/visual.zig b/src/tui/mode/input/vim/visual.zig index 440cc00..92c578b 100644 --- a/src/tui/mode/input/vim/visual.zig +++ b/src/tui/mode/input/vim/visual.zig @@ -17,18 +17,18 @@ const eql = @import("std").mem.eql; const Self = @This(); const input_buffer_size = 1024; -a: Allocator, +allocator: Allocator, input: ArrayList(u8), last_cmd: []const u8 = "", leader: ?struct { keypress: u32, modifiers: u32 } = null, count: usize = 0, commands: Commands = undefined, -pub fn create(a: Allocator) !tui.Mode { - const self: *Self = try a.create(Self); +pub fn create(allocator: Allocator) !tui.Mode { + const self: *Self = try allocator.create(Self); self.* = .{ - .a = a, - .input = try ArrayList(u8).initCapacity(a, input_buffer_size), + .allocator = allocator, + .input = try ArrayList(u8).initCapacity(allocator, input_buffer_size), }; try self.commands.init(self); return .{ @@ -44,7 +44,7 @@ pub fn create(a: Allocator) !tui.Mode { pub fn deinit(self: *Self) void { self.commands.deinit(); self.input.deinit(); - self.a.destroy(self); + self.allocator.destroy(self); } pub fn receive(self: *Self, _: tp.pid_ref, m: tp.message) error{Exit}!bool { diff --git a/src/tui/mode/mini/file_browser.zig b/src/tui/mode/mini/file_browser.zig index 2a36add..c7d50db 100644 --- a/src/tui/mode/mini/file_browser.zig +++ b/src/tui/mode/mini/file_browser.zig @@ -19,7 +19,7 @@ const max_complete_paths = 1024; pub fn Create(options: type) type { return struct { - a: std.mem.Allocator, + allocator: std.mem.Allocator, file_path: std.ArrayList(u8), query: std.ArrayList(u8), match: std.ArrayList(u8), @@ -34,14 +34,14 @@ pub fn Create(options: type) type { type: enum { dir, file, link }, }; - pub fn create(a: std.mem.Allocator, _: command.Context) !*Self { - const self: *Self = try a.create(Self); + pub fn create(allocator: std.mem.Allocator, _: command.Context) !*Self { + const self: *Self = try allocator.create(Self); self.* = .{ - .a = a, - .file_path = std.ArrayList(u8).init(a), - .query = std.ArrayList(u8).init(a), - .match = std.ArrayList(u8).init(a), - .entries = std.ArrayList(Entry).init(a), + .allocator = allocator, + .file_path = std.ArrayList(u8).init(allocator), + .query = std.ArrayList(u8).init(allocator), + .match = std.ArrayList(u8).init(allocator), + .entries = std.ArrayList(Entry).init(allocator), }; try tui.current().message_filters.add(MessageFilter.bind(self, receive_path_entry)); try options.load_entries(self); @@ -57,7 +57,7 @@ pub fn Create(options: type) type { self.match.deinit(); self.query.deinit(); self.file_path.deinit(); - self.a.destroy(self); + self.allocator.destroy(self); } pub fn handler(self: *Self) EventHandler { @@ -171,7 +171,7 @@ pub fn Create(options: type) type { } fn clear_entries(self: *Self) void { - for (self.entries.items) |entry| self.a.free(entry.name); + for (self.entries.items) |entry| self.allocator.free(entry.name); self.entries.clearRetainingCapacity(); } @@ -246,11 +246,11 @@ pub fn Create(options: type) type { var path: []const u8 = undefined; var file_name: []const u8 = undefined; if (try m.match(.{ tp.any, tp.any, tp.any, tp.extract(&path), "DIR", tp.extract(&file_name) })) { - (try self.entries.addOne()).* = .{ .name = try self.a.dupe(u8, file_name), .type = .dir }; + (try self.entries.addOne()).* = .{ .name = try self.allocator.dupe(u8, file_name), .type = .dir }; } else if (try m.match(.{ tp.any, tp.any, tp.any, tp.extract(&path), "LINK", tp.extract(&file_name) })) { - (try self.entries.addOne()).* = .{ .name = try self.a.dupe(u8, file_name), .type = .link }; + (try self.entries.addOne()).* = .{ .name = try self.allocator.dupe(u8, file_name), .type = .link }; } else if (try m.match(.{ tp.any, tp.any, tp.any, tp.extract(&path), "FILE", tp.extract(&file_name) })) { - (try self.entries.addOne()).* = .{ .name = try self.a.dupe(u8, file_name), .type = .file }; + (try self.entries.addOne()).* = .{ .name = try self.allocator.dupe(u8, file_name), .type = .file }; } else { log.logger("file_browser").err("receive", tp.unexpected(m)); } diff --git a/src/tui/mode/mini/find.zig b/src/tui/mode/mini/find.zig index b151399..ce35162 100644 --- a/src/tui/mode/mini/find.zig +++ b/src/tui/mode/mini/find.zig @@ -18,7 +18,7 @@ const ArrayList = @import("std").ArrayList; const Self = @This(); -a: Allocator, +allocator: Allocator, input: ArrayList(u8), last_input: ArrayList(u8), start_view: ed.View, @@ -26,20 +26,20 @@ start_cursor: ed.Cursor, editor: *ed.Editor, history_pos: ?usize = null, -pub fn create(a: Allocator, _: command.Context) !*Self { +pub fn create(allocator: Allocator, _: command.Context) !*Self { if (tui.current().mainview.dynamic_cast(mainview)) |mv_| if (mv_.get_editor()) |editor| { - const self: *Self = try a.create(Self); + const self: *Self = try allocator.create(Self); self.* = .{ - .a = a, - .input = ArrayList(u8).init(a), - .last_input = ArrayList(u8).init(a), + .allocator = allocator, + .input = ArrayList(u8).init(allocator), + .last_input = ArrayList(u8).init(allocator), .start_view = editor.view, .start_cursor = editor.get_primary().cursor, .editor = editor, }; if (editor.get_primary().selection) |sel| ret: { - const text = editor.get_selection(sel, self.a) catch break :ret; - defer self.a.free(text); + const text = editor.get_selection(sel, self.allocator) catch break :ret; + defer self.allocator.free(text); try self.input.appendSlice(text); } return self; @@ -50,7 +50,7 @@ pub fn create(a: Allocator, _: command.Context) !*Self { pub fn deinit(self: *Self) void { self.input.deinit(); self.last_input.deinit(); - self.a.destroy(self); + self.allocator.destroy(self); } pub fn handler(self: *Self) EventHandler { @@ -210,7 +210,7 @@ fn find_history_prev(self: *Self) void { } else { self.history_pos = history.items.len - 1; if (self.input.items.len > 0) - self.editor.push_find_history(self.editor.a.dupe(u8, self.input.items) catch return); + self.editor.push_find_history(self.editor.allocator.dupe(u8, self.input.items) catch return); if (eql(u8, history.items[self.history_pos.?], self.input.items) and self.history_pos.? > 0) self.history_pos = self.history_pos.? - 1; } diff --git a/src/tui/mode/mini/find_in_files.zig b/src/tui/mode/mini/find_in_files.zig index 221f380..d6ac3e6 100644 --- a/src/tui/mode/mini/find_in_files.zig +++ b/src/tui/mode/mini/find_in_files.zig @@ -17,23 +17,23 @@ const eql = @import("std").mem.eql; const Self = @This(); -a: Allocator, +allocator: Allocator, buf: [1024]u8 = undefined, input: []u8 = "", last_buf: [1024]u8 = undefined, last_input: []u8 = "", mainview: *mainview, -pub fn create(a: Allocator, _: command.Context) !*Self { - const self: *Self = try a.create(Self); +pub fn create(allocator: Allocator, _: command.Context) !*Self { + const self: *Self = try allocator.create(Self); if (tui.current().mainview.dynamic_cast(mainview)) |mv| { self.* = .{ - .a = a, + .allocator = allocator, .mainview = mv, }; if (mv.get_editor()) |editor| if (editor.get_primary().selection) |sel| ret: { - const text = editor.get_selection(sel, self.a) catch break :ret; - defer self.a.free(text); + const text = editor.get_selection(sel, self.allocator) catch break :ret; + defer self.allocator.free(text); @memcpy(self.buf[0..text.len], text); self.input = self.buf[0..text.len]; }; @@ -43,7 +43,7 @@ pub fn create(a: Allocator, _: command.Context) !*Self { } pub fn deinit(self: *Self) void { - self.a.destroy(self); + self.allocator.destroy(self); } pub fn handler(self: *Self) EventHandler { diff --git a/src/tui/mode/mini/goto.zig b/src/tui/mode/mini/goto.zig index ef8889f..1ff545c 100644 --- a/src/tui/mode/mini/goto.zig +++ b/src/tui/mode/mini/goto.zig @@ -16,16 +16,16 @@ const fmt = @import("std").fmt; const Self = @This(); -a: Allocator, +allocator: Allocator, buf: [30]u8 = undefined, input: ?usize = null, start: usize, -pub fn create(a: Allocator, _: command.Context) !*Self { - const self: *Self = try a.create(Self); +pub fn create(allocator: Allocator, _: command.Context) !*Self { + const self: *Self = try allocator.create(Self); if (tui.current().mainview.dynamic_cast(mainview)) |mv_| if (mv_.get_editor()) |editor| { self.* = .{ - .a = a, + .allocator = allocator, .start = editor.get_primary().cursor.row + 1, }; return self; @@ -34,7 +34,7 @@ pub fn create(a: Allocator, _: command.Context) !*Self { } pub fn deinit(self: *Self) void { - self.a.destroy(self); + self.allocator.destroy(self); } pub fn handler(self: *Self) EventHandler { diff --git a/src/tui/mode/mini/move_to_char.zig b/src/tui/mode/mini/move_to_char.zig index 1c7aa0f..ddecb7c 100644 --- a/src/tui/mode/mini/move_to_char.zig +++ b/src/tui/mode/mini/move_to_char.zig @@ -17,7 +17,7 @@ const fmt = @import("std").fmt; const Self = @This(); -a: Allocator, +allocator: Allocator, key: [6]u8 = undefined, direction: Direction, operation: Operation, @@ -32,13 +32,13 @@ const Operation = enum { select, }; -pub fn create(a: Allocator, ctx: command.Context) !*Self { +pub fn create(allocator: Allocator, ctx: command.Context) !*Self { var right: bool = true; const select = if (tui.current().mainview.dynamic_cast(mainview)) |mv| if (mv.get_editor()) |editor| if (editor.get_primary().selection) |_| true else false else false else false; _ = ctx.args.match(.{tp.extract(&right)}) catch return error.NotFound; - const self: *Self = try a.create(Self); + const self: *Self = try allocator.create(Self); self.* = .{ - .a = a, + .allocator = allocator, .direction = if (right) .right else .left, .operation = if (select) .select else .move, }; @@ -46,7 +46,7 @@ pub fn create(a: Allocator, ctx: command.Context) !*Self { } pub fn deinit(self: *Self) void { - self.a.destroy(self); + self.allocator.destroy(self); } pub fn handler(self: *Self) EventHandler { diff --git a/src/tui/mode/mini/open_file.zig b/src/tui/mode/mini/open_file.zig index 9910954..f7204b3 100644 --- a/src/tui/mode/mini/open_file.zig +++ b/src/tui/mode/mini/open_file.zig @@ -26,8 +26,8 @@ pub fn load_entries(self: *Type) !void { if (std.mem.lastIndexOf(u8, old_path, "/")) |pos| try self.file_path.appendSlice(old_path[0 .. pos + 1]); if (editor.get_primary().selection) |sel| ret: { - const text = editor.get_selection(sel, self.a) catch break :ret; - defer self.a.free(text); + const text = editor.get_selection(sel, self.allocator) catch break :ret; + defer self.allocator.free(text); if (!(text.len > 2 and std.mem.eql(u8, text[0..2], ".."))) self.file_path.clearRetainingCapacity(); try self.file_path.appendSlice(text); diff --git a/src/tui/mode/mini/save_as.zig b/src/tui/mode/mini/save_as.zig index 3a26172..40315a6 100644 --- a/src/tui/mode/mini/save_as.zig +++ b/src/tui/mode/mini/save_as.zig @@ -23,8 +23,8 @@ pub fn load_entries(self: *Type) !void { if (tui.current().mainview.dynamic_cast(mainview)) |mv_| if (mv_.get_editor()) |editor| { try self.file_path.appendSlice(editor.file_path orelse ""); if (editor.get_primary().selection) |sel| ret: { - const text = editor.get_selection(sel, self.a) catch break :ret; - defer self.a.free(text); + const text = editor.get_selection(sel, self.allocator) catch break :ret; + defer self.allocator.free(text); if (!(text.len > 2 and std.mem.eql(u8, text[0..2], ".."))) self.file_path.clearRetainingCapacity(); try self.file_path.appendSlice(text); diff --git a/src/tui/mode/overlay/command_palette.zig b/src/tui/mode/overlay/command_palette.zig index 921cafc..9bcc4c9 100644 --- a/src/tui/mode/overlay/command_palette.zig +++ b/src/tui/mode/overlay/command_palette.zig @@ -24,7 +24,7 @@ pub fn load_entries(palette: *Type) !void { } pub fn add_menu_entry(palette: *Type, entry: *Entry, matches: ?[]const usize) !void { - var value = std.ArrayList(u8).init(palette.a); + var value = std.ArrayList(u8).init(palette.allocator); defer value.deinit(); const writer = value.writer(); try cbor.writeValue(writer, entry.name); diff --git a/src/tui/mode/overlay/open_recent.zig b/src/tui/mode/overlay/open_recent.zig index 842c94a..276ec0a 100644 --- a/src/tui/mode/overlay/open_recent.zig +++ b/src/tui/mode/overlay/open_recent.zig @@ -25,7 +25,7 @@ const mainview = @import("../../mainview.zig"); const Self = @This(); const max_recent_files: usize = 25; -a: std.mem.Allocator, +allocator: std.mem.Allocator, f: usize = 0, menu: *Menu.State(*Self), inputbox: *InputBox.State(*Self), @@ -36,18 +36,18 @@ need_select_first: bool = true, longest: usize = 0, commands: Commands = undefined, -pub fn create(a: std.mem.Allocator) !tui.Mode { +pub fn create(allocator: std.mem.Allocator) !tui.Mode { const mv = tui.current().mainview.dynamic_cast(mainview) orelse return error.NotFound; - const self: *Self = try a.create(Self); + const self: *Self = try allocator.create(Self); self.* = .{ - .a = a, - .menu = try Menu.create(*Self, a, tui.current().mainview, .{ + .allocator = allocator, + .menu = try Menu.create(*Self, allocator, tui.current().mainview, .{ .ctx = self, .on_render = on_render_menu, .on_resize = on_resize_menu, }), .logger = log.logger(@typeName(Self)), - .inputbox = (try self.menu.add_header(try InputBox.create(*Self, self.a, self.menu.menu.parent, .{ + .inputbox = (try self.menu.add_header(try InputBox.create(*Self, self.allocator, self.menu.menu.parent, .{ .ctx = self, .label = "Search files by name", }))).dynamic_cast(InputBox.State(*Self)) orelse unreachable, @@ -71,7 +71,7 @@ pub fn deinit(self: *Self) void { if (tui.current().mainview.dynamic_cast(mainview)) |mv| mv.floating_views.remove(self.menu.container_widget); self.logger.deinit(); - self.a.destroy(self); + self.allocator.destroy(self); } inline fn menu_width(self: *Self) usize { @@ -141,7 +141,7 @@ fn menu_action_open_file(menu: **Menu.State(*Self), button: *Button.State(*Menu. } fn add_item(self: *Self, file_name: []const u8, matches: ?[]const u8) !void { - var label = std.ArrayList(u8).init(self.a); + var label = std.ArrayList(u8).init(self.allocator); defer label.deinit(); const writer = label.writer(); try cbor.writeValue(writer, file_name); diff --git a/src/tui/mode/overlay/open_recent_project.zig b/src/tui/mode/overlay/open_recent_project.zig index 49ba3a5..67c536a 100644 --- a/src/tui/mode/overlay/open_recent_project.zig +++ b/src/tui/mode/overlay/open_recent_project.zig @@ -24,24 +24,24 @@ pub const Match = struct { pub fn deinit(palette: *Type) void { for (palette.entries.items) |entry| - palette.a.free(entry.name); + palette.allocator.free(entry.name); } pub fn load_entries(palette: *Type) !void { - const rsp = try project_manager.request_recent_projects(palette.a); - defer palette.a.free(rsp.buf); + const rsp = try project_manager.request_recent_projects(palette.allocator); + defer palette.allocator.free(rsp.buf); var iter: []const u8 = rsp.buf; var len = try cbor.decodeArrayHeader(&iter); while (len > 0) : (len -= 1) { var name_: []const u8 = undefined; if (try cbor.matchValue(&iter, cbor.extract(&name_))) { - (try palette.entries.addOne()).* = .{ .name = try palette.a.dupe(u8, name_) }; + (try palette.entries.addOne()).* = .{ .name = try palette.allocator.dupe(u8, name_) }; } else return error.InvalidMessageField; } } pub fn add_menu_entry(palette: *Type, entry: *Entry, matches: ?[]const usize) !void { - var value = std.ArrayList(u8).init(palette.a); + var value = std.ArrayList(u8).init(palette.allocator); defer value.deinit(); const writer = value.writer(); try cbor.writeValue(writer, entry.name); diff --git a/src/tui/mode/overlay/palette.zig b/src/tui/mode/overlay/palette.zig index e1f21f1..19515d5 100644 --- a/src/tui/mode/overlay/palette.zig +++ b/src/tui/mode/overlay/palette.zig @@ -26,7 +26,7 @@ const max_menu_width = 80; pub fn Create(options: type) type { return struct { - a: std.mem.Allocator, + allocator: std.mem.Allocator, menu: *Menu.State(*Self), inputbox: *InputBox.State(*Self), logger: log.Logger, @@ -47,12 +47,12 @@ pub fn Create(options: type) type { pub const MenuState = Menu.State(*Self); pub const ButtonState = Button.State(*Menu.State(*Self)); - pub fn create(a: std.mem.Allocator) !tui.Mode { + pub fn create(allocator: std.mem.Allocator) !tui.Mode { const mv = tui.current().mainview.dynamic_cast(mainview) orelse return error.NotFound; - const self: *Self = try a.create(Self); + const self: *Self = try allocator.create(Self); self.* = .{ - .a = a, - .menu = try Menu.create(*Self, a, tui.current().mainview, .{ + .allocator = allocator, + .menu = try Menu.create(*Self, allocator, tui.current().mainview, .{ .ctx = self, .on_render = on_render_menu, .on_resize = on_resize_menu, @@ -61,13 +61,13 @@ pub fn Create(options: type) type { .on_click5 = mouse_click_button5, }), .logger = log.logger(@typeName(Self)), - .inputbox = (try self.menu.add_header(try InputBox.create(*Self, self.a, self.menu.menu.parent, .{ + .inputbox = (try self.menu.add_header(try InputBox.create(*Self, self.allocator, self.menu.menu.parent, .{ .ctx = self, .label = options.label, }))).dynamic_cast(InputBox.State(*Self)) orelse unreachable, .hints = if (tui.current().input_mode) |m| m.keybind_hints else null, .view_rows = get_view_rows(tui.current().screen()), - .entries = std.ArrayList(Entry).init(a), + .entries = std.ArrayList(Entry).init(allocator), }; self.menu.scrollbar.?.style_factory = scrollbar_style; if (self.hints) |hints| { @@ -96,7 +96,7 @@ pub fn Create(options: type) type { if (tui.current().mainview.dynamic_cast(mainview)) |mv| mv.floating_views.remove(self.menu.container_widget); self.logger.deinit(); - self.a.destroy(self); + self.allocator.destroy(self); } fn scrollbar_style(sb: *scrollbar_v, theme: *const Widget.Theme) Widget.Theme.Style { @@ -325,7 +325,7 @@ pub fn Create(options: type) type { fn query_entries(self: *Self, query: []const u8) error{OutOfMemory}!usize { var searcher = try fuzzig.Ascii.init( - self.a, + self.allocator, self.longest, // haystack max size self.longest, // needle max size .{ .case_sensitive = false }, @@ -338,7 +338,7 @@ pub fn Create(options: type) type { matches: []const usize, }; - var matches = std.ArrayList(Match).init(self.a); + var matches = std.ArrayList(Match).init(self.allocator); for (self.entries.items) |*entry| { const match = searcher.scoreMatches(entry.name, query); @@ -346,7 +346,7 @@ pub fn Create(options: type) type { (try matches.addOne()).* = .{ .entry = entry, .score = score, - .matches = try self.a.dupe(usize, match.matches), + .matches = try self.allocator.dupe(usize, match.matches), }; } if (matches.items.len == 0) return 0; diff --git a/src/tui/mode/overlay/theme_palette.zig b/src/tui/mode/overlay/theme_palette.zig index fe965fd..9415986 100644 --- a/src/tui/mode/overlay/theme_palette.zig +++ b/src/tui/mode/overlay/theme_palette.zig @@ -29,7 +29,7 @@ pub fn load_entries(palette: *Type) !void { } pub fn add_menu_entry(palette: *Type, entry: *Entry, matches: ?[]const usize) !void { - var value = std.ArrayList(u8).init(palette.a); + var value = std.ArrayList(u8).init(palette.allocator); defer value.deinit(); const writer = value.writer(); try cbor.writeValue(writer, entry.name); diff --git a/src/tui/scrollbar_v.zig b/src/tui/scrollbar_v.zig index 211c4d6..aca549b 100644 --- a/src/tui/scrollbar_v.zig +++ b/src/tui/scrollbar_v.zig @@ -28,8 +28,8 @@ style_factory: ?*const fn (self: *Self, theme: *const Widget.Theme) Widget.Theme const Self = @This(); -pub fn create(a: Allocator, parent: Widget, event_source: ?Widget, event_sink: EventHandler) !Widget { - const self: *Self = try a.create(Self); +pub fn create(allocator: Allocator, parent: Widget, event_source: ?Widget, event_sink: EventHandler) !Widget { + const self: *Self = try allocator.create(Self); self.* = .{ .plane = try Plane.init(&(Widget.Box{}).opts(@typeName(Self)), parent.plane.*), .event_sink = event_sink, @@ -44,9 +44,9 @@ pub fn widget(self: *Self) Widget { return Widget.to(self); } -pub fn deinit(self: *Self, a: Allocator) void { +pub fn deinit(self: *Self, allocator: Allocator) void { self.plane.deinit(); - a.destroy(self); + allocator.destroy(self); } pub fn layout(_: *Self) Widget.Layout { diff --git a/src/tui/status/bar.zig b/src/tui/status/bar.zig index a79dd2f..d1d42e2 100644 --- a/src/tui/status/bar.zig +++ b/src/tui/status/bar.zig @@ -9,13 +9,13 @@ const Self = @This(); pub const Style = enum { none, grip }; -pub fn create(a: std.mem.Allocator, parent: Widget, config: []const u8, style: Style, event_handler: ?Widget.EventHandler) !Widget { - var w = try WidgetList.createH(a, parent, "statusbar", .{ .static = 1 }); +pub fn create(allocator: std.mem.Allocator, parent: Widget, config: []const u8, style: Style, event_handler: ?Widget.EventHandler) !Widget { + var w = try WidgetList.createH(allocator, parent, "statusbar", .{ .static = 1 }); if (style == .grip) w.after_render = render_grip; w.ctx = w; var it = std.mem.splitScalar(u8, config, ' '); while (it.next()) |widget_name| - try w.add(try status_widget.create(widget_name, a, w.plane, event_handler) orelse continue); + try w.add(try status_widget.create(widget_name, allocator, w.plane, event_handler) orelse continue); return w.widget(); } diff --git a/src/tui/status/blank.zig b/src/tui/status/blank.zig index c0ecfe9..e1fee8a 100644 --- a/src/tui/status/blank.zig +++ b/src/tui/status/blank.zig @@ -12,8 +12,8 @@ const Self = @This(); pub fn Create(comptime layout_: Widget.Layout) @import("widget.zig").CreateFunction { return struct { - fn create(a: std.mem.Allocator, parent: Plane, event_handler: ?Widget.EventHandler) @import("widget.zig").CreateError!Widget { - const self: *Self = try a.create(Self); + fn create(allocator: std.mem.Allocator, parent: Plane, event_handler: ?Widget.EventHandler) @import("widget.zig").CreateError!Widget { + const self: *Self = try allocator.create(Self); self.* = .{ .plane = try Plane.init(&(Widget.Box{}).opts(@typeName(Self)), parent), .layout = layout_, @@ -24,9 +24,9 @@ pub fn Create(comptime layout_: Widget.Layout) @import("widget.zig").CreateFunct }.create; } -pub fn deinit(self: *Self, a: std.mem.Allocator) void { +pub fn deinit(self: *Self, allocator: std.mem.Allocator) void { self.plane.deinit(); - a.destroy(self); + allocator.destroy(self); } pub fn layout(self: *Self) Widget.Layout { diff --git a/src/tui/status/clock.zig b/src/tui/status/clock.zig index ef42ec6..350247f 100644 --- a/src/tui/status/clock.zig +++ b/src/tui/status/clock.zig @@ -26,22 +26,22 @@ const Level = enum { err, }; -pub fn create(a: std.mem.Allocator, parent: Plane, event_handler: ?Widget.EventHandler) @import("widget.zig").CreateError!Widget { - var env = std.process.getEnvMap(a) catch |e| return tp.exit_error(e, @errorReturnTrace()); +pub fn create(allocator: std.mem.Allocator, parent: Plane, event_handler: ?Widget.EventHandler) @import("widget.zig").CreateError!Widget { + var env = std.process.getEnvMap(allocator) catch |e| return tp.exit_error(e, @errorReturnTrace()); defer env.deinit(); - const self: *Self = try a.create(Self); + const self: *Self = try allocator.create(Self); self.* = .{ - .allocator = a, + .allocator = allocator, .plane = try Plane.init(&(Widget.Box{}).opts(@typeName(Self)), parent), .on_event = event_handler, - .tz = zeit.local(a, &env) catch |e| return tp.exit_error(e, @errorReturnTrace()), + .tz = zeit.local(allocator, &env) catch |e| return tp.exit_error(e, @errorReturnTrace()), }; try tui.current().message_filters.add(MessageFilter.bind(self, receive_tick)); self.update_tick_timer(.init); return Widget.to(self); } -pub fn deinit(self: *Self, a: std.mem.Allocator) void { +pub fn deinit(self: *Self, allocator: std.mem.Allocator) void { tui.current().message_filters.remove_ptr(self); if (self.tick_timer) |*t| { t.cancel() catch {}; @@ -50,7 +50,7 @@ pub fn deinit(self: *Self, a: std.mem.Allocator) void { } self.tz.deinit(); self.plane.deinit(); - a.destroy(self); + allocator.destroy(self); } pub fn receive(self: *Self, from: tp.pid_ref, m: tp.message) error{Exit}!bool { diff --git a/src/tui/status/diagstate.zig b/src/tui/status/diagstate.zig index ae51bfd..d0b00a4 100644 --- a/src/tui/status/diagstate.zig +++ b/src/tui/status/diagstate.zig @@ -19,8 +19,8 @@ rendered: [:0]const u8 = "", const Self = @This(); -pub fn create(a: Allocator, parent: Plane, event_handler: ?Widget.EventHandler) @import("widget.zig").CreateError!Widget { - return Button.create_widget(Self, a, parent, .{ +pub fn create(allocator: Allocator, parent: Plane, event_handler: ?Widget.EventHandler) @import("widget.zig").CreateError!Widget { + return Button.create_widget(Self, allocator, parent, .{ .ctx = .{}, .label = "", .on_click = on_click, diff --git a/src/tui/status/filestate.zig b/src/tui/status/filestate.zig index 099fdeb..9b3228c 100644 --- a/src/tui/status/filestate.zig +++ b/src/tui/status/filestate.zig @@ -13,7 +13,7 @@ const Button = @import("../Button.zig"); const command = @import("../command.zig"); const tui = @import("../tui.zig"); -a: Allocator, +allocator: Allocator, name: []const u8, name_buf: [512]u8 = undefined, previous_title: []const u8 = "", @@ -34,10 +34,10 @@ file: bool = false, const project_icon = ""; const Self = @This(); -pub fn create(a: Allocator, parent: Plane, event_handler: ?Widget.EventHandler) @import("widget.zig").CreateError!Widget { - const btn = try Button.create(Self, a, parent, .{ +pub fn create(allocator: Allocator, parent: Plane, event_handler: ?Widget.EventHandler) @import("widget.zig").CreateError!Widget { + const btn = try Button.create(Self, allocator, parent, .{ .ctx = .{ - .a = a, + .allocator = allocator, .name = "", .file_type = "", .lines = 0, diff --git a/src/tui/status/keystate.zig b/src/tui/status/keystate.zig index 15ea117..5a608e0 100644 --- a/src/tui/status/keystate.zig +++ b/src/tui/status/keystate.zig @@ -31,10 +31,10 @@ const Self = @This(); const idle_msg = "🐶"; pub const width = idle_msg.len + 20; -pub fn create(a: Allocator, parent: Plane, _: ?Widget.EventHandler) @import("widget.zig").CreateError!Widget { +pub fn create(allocator: Allocator, parent: Plane, _: ?Widget.EventHandler) @import("widget.zig").CreateError!Widget { var frame_rate = tp.env.get().num("frame-rate"); if (frame_rate == 0) frame_rate = 60; - const self: *Self = try a.create(Self); + const self: *Self = try allocator.create(Self); self.* = .{ .plane = try Plane.init(&(Widget.Box{}).opts(@typeName(Self)), parent), .wipe_after_frames = @divTrunc(frame_rate, 2), @@ -47,10 +47,10 @@ pub fn widget(self: *Self) Widget { return Widget.to(self); } -pub fn deinit(self: *Self, a: Allocator) void { +pub fn deinit(self: *Self, allocator: Allocator) void { tui.current().input_listeners.remove_ptr(self); self.plane.deinit(); - a.destroy(self); + allocator.destroy(self); } pub fn layout(_: *Self) Widget.Layout { diff --git a/src/tui/status/linenumstate.zig b/src/tui/status/linenumstate.zig index 46fefa6..4b382ca 100644 --- a/src/tui/status/linenumstate.zig +++ b/src/tui/status/linenumstate.zig @@ -18,8 +18,8 @@ rendered: [:0]const u8 = "", const Self = @This(); -pub fn create(a: Allocator, parent: Plane, event_handler: ?Widget.EventHandler) @import("widget.zig").CreateError!Widget { - return Button.create_widget(Self, a, parent, .{ +pub fn create(allocator: Allocator, parent: Plane, event_handler: ?Widget.EventHandler) @import("widget.zig").CreateError!Widget { + return Button.create_widget(Self, allocator, parent, .{ .ctx = .{}, .label = "", .on_click = on_click, diff --git a/src/tui/status/minilog.zig b/src/tui/status/minilog.zig index 67e104f..708d8a9 100644 --- a/src/tui/status/minilog.zig +++ b/src/tui/status/minilog.zig @@ -26,20 +26,20 @@ const Level = enum { err, }; -pub fn create(a: std.mem.Allocator, parent: Plane, event_handler: ?Widget.EventHandler) @import("widget.zig").CreateError!Widget { - const self: *Self = try a.create(Self); +pub fn create(allocator: std.mem.Allocator, parent: Plane, event_handler: ?Widget.EventHandler) @import("widget.zig").CreateError!Widget { + const self: *Self = try allocator.create(Self); self.* = .{ .plane = try Plane.init(&(Widget.Box{}).opts(@typeName(Self)), parent), - .msg = std.ArrayList(u8).init(a), + .msg = std.ArrayList(u8).init(allocator), .on_event = event_handler, }; - logview.init(a); + logview.init(allocator); try tui.current().message_filters.add(MessageFilter.bind(self, receive_log)); try log.subscribe(); return Widget.to(self); } -pub fn deinit(self: *Self, a: std.mem.Allocator) void { +pub fn deinit(self: *Self, allocator: std.mem.Allocator) void { if (self.clear_timer) |*t| { t.cancel() catch {}; t.deinit(); @@ -49,7 +49,7 @@ pub fn deinit(self: *Self, a: std.mem.Allocator) void { log.unsubscribe() catch {}; tui.current().message_filters.remove_ptr(self); self.plane.deinit(); - a.destroy(self); + allocator.destroy(self); } pub fn receive(self: *Self, from: tp.pid_ref, m: tp.message) error{Exit}!bool { diff --git a/src/tui/status/modestate.zig b/src/tui/status/modestate.zig index c7025f0..9eb8b43 100644 --- a/src/tui/status/modestate.zig +++ b/src/tui/status/modestate.zig @@ -15,8 +15,8 @@ const ed = @import("../editor.zig"); const tui = @import("../tui.zig"); const CreateError = @import("widget.zig").CreateError; -pub fn create(a: Allocator, parent: Plane, event_handler: ?Widget.EventHandler) CreateError!Widget { - return Button.create_widget(void, a, parent, .{ +pub fn create(allocator: Allocator, parent: Plane, event_handler: ?Widget.EventHandler) CreateError!Widget { + return Button.create_widget(void, allocator, parent, .{ .ctx = {}, .label = tui.get_mode(), .on_click = on_click, diff --git a/src/tui/status/modstate.zig b/src/tui/status/modstate.zig index fde44ec..ed73f58 100644 --- a/src/tui/status/modstate.zig +++ b/src/tui/status/modstate.zig @@ -23,8 +23,8 @@ const Self = @This(); pub const width = 5; -pub fn create(a: Allocator, parent: Plane, _: ?Widget.EventHandler) @import("widget.zig").CreateError!Widget { - const self: *Self = try a.create(Self); +pub fn create(allocator: Allocator, parent: Plane, _: ?Widget.EventHandler) @import("widget.zig").CreateError!Widget { + const self: *Self = try allocator.create(Self); self.* = .{ .plane = try Plane.init(&(Widget.Box{}).opts(@typeName(Self)), parent), }; @@ -36,10 +36,10 @@ pub fn widget(self: *Self) Widget { return Widget.to(self); } -pub fn deinit(self: *Self, a: Allocator) void { +pub fn deinit(self: *Self, allocator: Allocator) void { tui.current().input_listeners.remove_ptr(self); self.plane.deinit(); - a.destroy(self); + allocator.destroy(self); } pub fn layout(_: *Self) Widget.Layout { diff --git a/src/tui/status/selectionstate.zig b/src/tui/status/selectionstate.zig index 9e5d5b4..d954408 100644 --- a/src/tui/status/selectionstate.zig +++ b/src/tui/status/selectionstate.zig @@ -19,8 +19,8 @@ on_event: ?Widget.EventHandler, const Self = @This(); -pub fn create(a: Allocator, parent: Plane, event_handler: ?Widget.EventHandler) @import("widget.zig").CreateError!Widget { - const self: *Self = try a.create(Self); +pub fn create(allocator: Allocator, parent: Plane, event_handler: ?Widget.EventHandler) @import("widget.zig").CreateError!Widget { + const self: *Self = try allocator.create(Self); self.* = .{ .plane = try Plane.init(&(Widget.Box{}).opts(@typeName(Self)), parent), .on_event = event_handler, @@ -28,9 +28,9 @@ pub fn create(a: Allocator, parent: Plane, event_handler: ?Widget.EventHandler) return Widget.to(self); } -pub fn deinit(self: *Self, a: Allocator) void { +pub fn deinit(self: *Self, allocator: Allocator) void { self.plane.deinit(); - a.destroy(self); + allocator.destroy(self); } pub fn layout(self: *Self) Widget.Layout { diff --git a/src/tui/status/widget.zig b/src/tui/status/widget.zig index c0a4f32..5e7ada7 100644 --- a/src/tui/status/widget.zig +++ b/src/tui/status/widget.zig @@ -16,9 +16,9 @@ const widgets = std.static_string_map.StaticStringMap(CreateFunction).initCompti .{ "clock", @import("clock.zig").create }, }); pub const CreateError = error{ OutOfMemory, Exit }; -pub const CreateFunction = *const fn (a: std.mem.Allocator, parent: Plane, event_handler: ?Widget.EventHandler) CreateError!Widget; +pub const CreateFunction = *const fn (allocator: std.mem.Allocator, parent: Plane, event_handler: ?Widget.EventHandler) CreateError!Widget; -pub fn create(name: []const u8, a: std.mem.Allocator, parent: Plane, event_handler: ?Widget.EventHandler) CreateError!?Widget { +pub fn create(name: []const u8, allocator: std.mem.Allocator, parent: Plane, event_handler: ?Widget.EventHandler) CreateError!?Widget { const create_ = widgets.get(name) orelse return null; - return try create_(a, parent, event_handler); + return try create_(allocator, parent, event_handler); } diff --git a/src/tui/tui.zig b/src/tui/tui.zig index fa42b39..afc43e7 100644 --- a/src/tui/tui.zig +++ b/src/tui/tui.zig @@ -25,7 +25,7 @@ const Timer = std.time.Timer; const Mutex = std.Thread.Mutex; const maxInt = std.math.maxInt; -a: Allocator, +allocator: Allocator, rdr: renderer, config: config, frame_time: usize, // in microseconds @@ -68,30 +68,30 @@ const Self = @This(); const Receiver = tp.Receiver(*Self); const Commands = command.Collection(cmds); -const StartArgs = struct { a: Allocator }; +const StartArgs = struct { allocator: Allocator }; -pub fn spawn(a: Allocator, ctx: *tp.context, eh: anytype, env: ?*const tp.env) !tp.pid { - return try ctx.spawn_link(StartArgs{ .a = a }, start, "tui", eh, env); +pub fn spawn(allocator: Allocator, ctx: *tp.context, eh: anytype, env: ?*const tp.env) !tp.pid { + return try ctx.spawn_link(StartArgs{ .allocator = allocator }, start, "tui", eh, env); } fn start(args: StartArgs) tp.result { _ = tp.set_trap(true); - var self = init(args.a) catch |e| return tp.exit_error(e, @errorReturnTrace()); + var self = init(args.allocator) catch |e| return tp.exit_error(e, @errorReturnTrace()); errdefer self.deinit(); tp.receive(&self.receiver); } -fn init(a: Allocator) !*Self { - var self = try a.create(Self); +fn init(allocator: Allocator) !*Self { + var self = try allocator.create(Self); var conf_buf: ?[]const u8 = null; - var conf = root.read_config(a, &conf_buf); - defer if (conf_buf) |buf| a.free(buf); + var conf = root.read_config(allocator, &conf_buf); + defer if (conf_buf) |buf| allocator.free(buf); const theme = get_theme_by_name(conf.theme) orelse get_theme_by_name("dark_modern") orelse return tp.exit("unknown theme"); conf.theme = theme.name; - conf.input_mode = try a.dupe(u8, conf.input_mode); - conf.top_bar = try a.dupe(u8, conf.top_bar); - conf.bottom_bar = try a.dupe(u8, conf.bottom_bar); + conf.input_mode = try allocator.dupe(u8, conf.input_mode); + conf.top_bar = try allocator.dupe(u8, conf.top_bar); + conf.bottom_bar = try allocator.dupe(u8, conf.bottom_bar); const frame_rate: usize = @intCast(tp.env.get().num("frame-rate")); if (frame_rate != 0) @@ -100,17 +100,17 @@ fn init(a: Allocator) !*Self { const frame_clock = try tp.metronome.init(frame_time); self.* = .{ - .a = a, + .allocator = allocator, .config = conf, - .rdr = try renderer.init(a, self, tp.env.get().is("no-alternate")), + .rdr = try renderer.init(allocator, self, tp.env.get().is("no-alternate")), .frame_time = frame_time, .frame_clock = frame_clock, .frame_clock_running = true, .receiver = Receiver.init(receive, self), .mainview = undefined, - .message_filters = MessageFilter.List.init(a), + .message_filters = MessageFilter.List.init(allocator), .input_mode = null, - .input_listeners = EventHandler.List.init(a), + .input_listeners = EventHandler.List.init(allocator), .logger = log.logger("tui"), .init_timer = try tp.timeout.init_ms(init_delay, tp.message.fmt(.{"init"})), .theme = theme, @@ -131,13 +131,13 @@ fn init(a: Allocator) !*Self { errdefer self.deinit(); switch (builtin.os.tag) { .windows => { - self.keepalive_timer = try tp.self_pid().delay_send_cancellable(a, "tui.keepalive", keepalive, .{"keepalive"}); + self.keepalive_timer = try tp.self_pid().delay_send_cancellable(allocator, "tui.keepalive", keepalive, .{"keepalive"}); }, else => { try self.listen_sigwinch(); }, } - self.mainview = try mainview.create(a); + self.mainview = try mainview.create(allocator); self.resize(); self.set_terminal_style(); try self.rdr.render(); @@ -167,7 +167,7 @@ fn deinit(self: *Self) void { } if (self.input_mode) |*m| m.deinit(); self.commands.deinit(); - self.mainview.deinit(self.a); + self.mainview.deinit(self.allocator); self.message_filters.deinit(); self.input_listeners.deinit(); if (self.frame_clock_running) @@ -177,7 +177,7 @@ fn deinit(self: *Self) void { self.rdr.stop(); self.rdr.deinit(); self.logger.deinit(); - self.a.destroy(self); + self.allocator.destroy(self); } fn listen_sigwinch(self: *Self) tp.result { @@ -192,7 +192,7 @@ fn update_mouse_idle_timer(self: *Self) void { t.deinit(); self.mouse_idle_timer = null; } - self.mouse_idle_timer = tp.self_pid().delay_send_cancellable(self.a, "tui.mouse_idle_timer", delay, .{"MOUSE_IDLE"}) catch return; + self.mouse_idle_timer = tp.self_pid().delay_send_cancellable(self.allocator, "tui.mouse_idle_timer", delay, .{"MOUSE_IDLE"}) catch return; } fn receive(self: *Self, from: tp.pid_ref, m: tp.message) tp.result { @@ -542,14 +542,14 @@ pub fn refresh_hover(self: *Self) void { } pub fn save_config(self: *const Self) !void { - try root.write_config(self.config, self.a); + try root.write_config(self.config, self.allocator); } fn enter_overlay_mode(self: *Self, mode: type) command.Result { if (self.mini_mode) |_| try cmds.exit_mini_mode(self, .{}); if (self.input_mode_outer) |_| try cmds.exit_overlay_mode(self, .{}); self.input_mode_outer = self.input_mode; - self.input_mode = try mode.create(self.a); + self.input_mode = try mode.create(self.allocator); } const cmds = struct { @@ -627,24 +627,24 @@ const cmds = struct { if (self.input_mode_outer) |_| try exit_overlay_mode(self, .{}); if (self.input_mode) |*m| m.deinit(); self.input_mode = if (std.mem.eql(u8, mode, "vim/normal")) - try @import("mode/input/vim/normal.zig").create(self.a) + try @import("mode/input/vim/normal.zig").create(self.allocator) else if (std.mem.eql(u8, mode, "vim/insert")) - try @import("mode/input/vim/insert.zig").create(self.a) + try @import("mode/input/vim/insert.zig").create(self.allocator) else if (std.mem.eql(u8, mode, "vim/visual")) - try @import("mode/input/vim/visual.zig").create(self.a) + try @import("mode/input/vim/visual.zig").create(self.allocator) else if (std.mem.eql(u8, mode, "helix/normal")) - try @import("mode/input/helix/normal.zig").create(self.a) + try @import("mode/input/helix/normal.zig").create(self.allocator) else if (std.mem.eql(u8, mode, "helix/insert")) - try @import("mode/input/helix/insert.zig").create(self.a) + try @import("mode/input/helix/insert.zig").create(self.allocator) else if (std.mem.eql(u8, mode, "helix/select")) - try @import("mode/input/helix/select.zig").create(self.a) + try @import("mode/input/helix/select.zig").create(self.allocator) else if (std.mem.eql(u8, mode, "flow")) - try @import("mode/input/flow.zig").create(self.a) + try @import("mode/input/flow.zig").create(self.allocator) else if (std.mem.eql(u8, mode, "home")) - try @import("mode/input/home.zig").create(self.a) + try @import("mode/input/home.zig").create(self.allocator) else ret: { self.logger.print("unknown mode {s}", .{mode}); - break :ret try @import("mode/input/flow.zig").create(self.a); + break :ret try @import("mode/input/flow.zig").create(self.allocator); }; // self.logger.print("input mode: {s}", .{(self.input_mode orelse return).description}); } @@ -713,7 +713,7 @@ const cmds = struct { self.input_mode_outer = null; self.mini_mode = null; } - const mode_instance = try mode.create(self.a, ctx); + const mode_instance = try mode.create(self.allocator, ctx); self.input_mode = .{ .handler = mode_instance.handler(), .name = mode_instance.name(),