diff options
| -rw-r--r-- | src/Macro.zig | 4 | ||||
| -rw-r--r-- | src/Names.zig | 2 | ||||
| -rw-r--r-- | src/builtins_json.zig | 2 | ||||
| -rw-r--r-- | src/hunks.zig | 16 | ||||
| -rw-r--r-- | src/locations.zig | 8 | ||||
| -rw-r--r-- | src/recent.zig | 2 | ||||
| -rw-r--r-- | src/sam_edit.zig | 6 | ||||
| -rw-r--r-- | src/selection_pipe.zig | 2 | ||||
| -rw-r--r-- | src/syntax.zig | 35 | ||||
| -rw-r--r-- | src/wire.zig | 26 |
10 files changed, 45 insertions, 58 deletions
diff --git a/src/Macro.zig b/src/Macro.zig index 7475992e..b619e523 100644 --- a/src/Macro.zig +++ b/src/Macro.zig @@ -91,7 +91,7 @@ const names = [_]struct { cp: u21, name: []const u8 }{ /// Keys in helix's notation: a plain character as itself, anything else /// in angle brackets with its modifiers (`<C-r>`, `<A-(>`, `<ret>`). -pub fn encode(gpa: std.mem.Allocator, keys: []const Stored) ![]u8 { +pub fn encode(gpa: std.mem.Allocator, keys: []const Stored) error{OutOfMemory}![]u8 { var out: std.ArrayList(u8) = .empty; errdefer out.deinit(gpa); for (keys) |k| { @@ -117,7 +117,7 @@ pub fn encode(gpa: std.mem.Allocator, keys: []const Stored) ![]u8 { } /// The keys helix notation names; what it cannot read ends the list. -pub fn decode(gpa: std.mem.Allocator, text: []const u8) ![]Stored { +pub fn decode(gpa: std.mem.Allocator, text: []const u8) error{OutOfMemory}![]Stored { var out: std.ArrayList(Stored) = .empty; errdefer out.deinit(gpa); var i: usize = 0; diff --git a/src/Names.zig b/src/Names.zig index a3fff314..d9597994 100644 --- a/src/Names.zig +++ b/src/Names.zig @@ -84,7 +84,7 @@ pub fn queryText(n: *const Names) []const u8 { return n.query_buf[0..n.query_len]; } -pub fn add(n: *Names, gpa: std.mem.Allocator, row_in: []const u8, key: usize, key_len: usize, base: u16, ref: u32) !void { +pub fn add(n: *Names, gpa: std.mem.Allocator, row_in: []const u8, key: usize, key_len: usize, base: u16, ref: u32) error{OutOfMemory}!void { if (n.cands.items.len >= max_cands) return; const text = row_in[0..@min(row_in.len, std.math.maxInt(u16))]; try n.cands.append(gpa, .{ diff --git a/src/builtins_json.zig b/src/builtins_json.zig index f5543dba..e8ec5768 100644 --- a/src/builtins_json.zig +++ b/src/builtins_json.zig @@ -19,7 +19,7 @@ fn lessName(_: void, a: Entry, b: Entry) bool { return std.mem.lessThan(u8, a.name, b.name); } -pub fn write(w: *std.Io.Writer) !void { +pub fn write(w: *std.Io.Writer) std.Io.Writer.Error!void { var all: [pardes.builtin_rows.len]Entry = undefined; var len: usize = 0; // This build's own frontend's words (a desktop build has the other's diff --git a/src/hunks.zig b/src/hunks.zig index 00d4cc97..00fe265b 100644 --- a/src/hunks.zig +++ b/src/hunks.zig @@ -162,7 +162,7 @@ pub fn sourceRoot(p: *Pardes, dir: []const u8, content: []const u8) []const u8 { var base: []const u8 = dir; for (0..8) |_| { if (locations.sourceText(p, p.scratch.allocator(), base, path) != null) return base; - base = std.fs.path.dirname(base) orelse return dir; + base = std.Io.Dir.path.dirname(base) orelse return dir; } return dir; } @@ -176,7 +176,7 @@ fn findSource(p: *Pardes, memo: *SourceMemo, dir: []const u8, path: []const u8) var base: []const u8 = dir; for (0..8) |_| { if (locations.sourceText(p, arena, base, path)) |text| { - memo.shown = if (base.ptr == dir.ptr) path else try std.fs.path.relativePosix(arena, "/", dir, text.path); + memo.shown = if (base.ptr == dir.ptr) path else try std.Io.Dir.path.relativePosix(arena, "/", dir, text.path); var lines: std.ArrayList([]const u8) = .empty; var split = std.mem.splitScalar(u8, text.bytes, '\n'); while (split.next()) |line| try lines.append(arena, std.mem.trimEnd(u8, line, "\r")); @@ -188,7 +188,7 @@ fn findSource(p: *Pardes, memo: *SourceMemo, dir: []const u8, path: []const u8) memo.declarations = try arena.dupe(syntax.ContextDeclaration, hit.analysis.declarations); return; } - base = std.fs.path.dirname(base) orelse return; + base = std.Io.Dir.path.dirname(base) orelse return; } } @@ -670,7 +670,7 @@ test "a hunk the file has moved since is found where it went, inside its declara defer tmp.cleanup(); // Two lines more above it than the patch knows of. try tmp.dir.writeFile(testing.io, .{ .sub_path = "a.zig", .data = "// one\n// two\nconst S = struct {\n fn f() void {\n a();\n b();\n }\n};\n" }); - var buf: [std.fs.max_path_bytes]u8 = undefined; + var buf: [std.Io.Dir.max_path_bytes]u8 = undefined; const dir = buf[0..try tmp.dir.realPath(testing.io, &buf)]; const patch = \\--- a.zig @@ -722,11 +722,11 @@ test "a .patch looked at opens its +Diff, and Diff goes to the text and back" { defer tmp.cleanup(); try tmp.dir.writeFile(testing.io, .{ .sub_path = "x.txt", .data = "b\n" }); try tmp.dir.writeFile(testing.io, .{ .sub_path = "c.patch", .data = "--- x.txt\n+++ x.txt\n@@ -1 +1 @@\n-a\n+b\n" }); - var buf: [std.fs.max_path_bytes]u8 = undefined; + var buf: [std.Io.Dir.max_path_bytes]u8 = undefined; const dir = buf[0..try tmp.dir.realPath(testing.io, &buf)]; - const patch = try std.fs.path.join(testing.allocator, &.{ dir, "c.patch" }); + const patch = try std.Io.Dir.path.join(testing.allocator, &.{ dir, "c.patch" }); defer testing.allocator.free(patch); - const hunks_path = try std.fs.path.join(testing.allocator, &.{ dir, "+Diff" }); + const hunks_path = try std.Io.Dir.path.join(testing.allocator, &.{ dir, "+Diff" }); defer testing.allocator.free(hunks_path); const Count = struct { fn of(pp: *Pardes, path: []const u8) usize { @@ -784,7 +784,7 @@ test "a hunk edited since, beside siblings with its signature's tail, is found i \\} \\ }); - var buf: [std.fs.max_path_bytes]u8 = undefined; + var buf: [std.Io.Dir.max_path_bytes]u8 = undefined; const dir = buf[0..try tmp.dir.realPath(testing.io, &buf)]; const patch = \\--- a.rs diff --git a/src/locations.zig b/src/locations.zig index e8c31bf0..f6a0cf9c 100644 --- a/src/locations.zig +++ b/src/locations.zig @@ -51,7 +51,7 @@ pub fn freeRows(gpa: std.mem.Allocator, rows: []Row) void { /// A copy of `rows` and all they own, gpa's: rows are a blob (File.State /// `location_rows`), made again rather than written. -pub fn cloneRows(gpa: std.mem.Allocator, rows: []const Row) ![]Row { +pub fn cloneRows(gpa: std.mem.Allocator, rows: []const Row) error{OutOfMemory}![]Row { const out = try gpa.alloc(Row, rows.len); var made: usize = 0; errdefer { @@ -84,7 +84,7 @@ pub fn freeRowList(gpa: std.mem.Allocator, rows: *std.ArrayList(Row)) void { /// `row` onto a list being built, with copies of its own of the path and /// the colours it borrows. -pub fn appendRow(gpa: std.mem.Allocator, rows: *std.ArrayList(Row), row: Row) !void { +pub fn appendRow(gpa: std.mem.Allocator, rows: *std.ArrayList(Row), row: Row) error{OutOfMemory}!void { var owned = row; owned.path = try gpa.dupe(u8, row.path); errdefer gpa.free(owned.path); @@ -227,8 +227,8 @@ const Source = struct { path: []const u8, bytes: []const u8 }; /// A file's text as a look from `dir` finds it: an open pane's, unsaved /// edits and all, else the disk's. Null for a PDF or one not there. pub fn sourceText(p: *pardes.Pardes, arena: std.mem.Allocator, dir: []const u8, path: []const u8) ?Source { - if (std.ascii.eqlIgnoreCase(std.fs.path.extension(path), ".pdf")) return null; - const lexical = std.fs.path.resolvePosix(arena, &.{ dir, path }) catch return null; + if (std.ascii.eqlIgnoreCase(std.Io.Dir.path.extension(path), ".pdf")) return null; + const lexical = std.Io.Dir.path.resolvePosix(arena, &.{ dir, path }) catch return null; var pathbuf: [4096]u8 = undefined; const full = if (filesystem.resolve(p, path, dir, &pathbuf)) |resolved| resolved.path else lexical; for (p.panes) |slot| if (slot) |pane| { diff --git a/src/recent.zig b/src/recent.zig index 4f744750..31ed9c4c 100644 --- a/src/recent.zig +++ b/src/recent.zig @@ -170,7 +170,7 @@ pub const List = struct { } /// An entry as a line of the file, `<line> <col> <aline> <acol> <path>`. - pub fn writeEntry(e: Entry, w: *std.Io.Writer) !void { + pub fn writeEntry(e: Entry, w: *std.Io.Writer) std.Io.Writer.Error!void { // A name with a newline in it would read back as two lines: not kept. if (std.mem.indexOfScalar(u8, e.path, '\n') == null) try w.print("{d} {d} {d} {d} {s}\n", .{ e.line, e.col, e.aline, e.acol, e.path }); diff --git a/src/sam_edit.zig b/src/sam_edit.zig index a6ed5772..3886f9eb 100644 --- a/src/sam_edit.zig +++ b/src/sam_edit.zig @@ -670,8 +670,8 @@ const Exec = struct { var home: [4096]u8 = undefined; const name = try ex.arena.dupe(u8, @import("fs.zig").expandHome(name_in, &home)); if (name.len > 0 and name[0] == '/') return name; - const dir = std.fs.path.dirnamePosix(ex.files.items[fi].name) orelse "/"; - return std.fs.path.resolvePosix(ex.arena, &.{ dir, name }); + const dir = std.Io.Dir.path.dirnamePosix(ex.files.items[fi].name) orelse "/"; + return std.Io.Dir.path.resolvePosix(ex.arena, &.{ dir, name }); } /// The open file named `path`, a scratch too. @@ -1034,7 +1034,7 @@ const Exec = struct { /// The text after `ops`, which are in order and do not overlap (a job's /// with its output in place). -pub fn apply(gpa: std.mem.Allocator, text: []const u8, ops: []const Op) ![]u8 { +pub fn apply(gpa: std.mem.Allocator, text: []const u8, ops: []const Op) error{OutOfMemory}![]u8 { var n: usize = text.len; for (ops) |o| n = n - (o.q1 - o.q0) + o.text.len; const out = try gpa.alloc(u8, n); diff --git a/src/selection_pipe.zig b/src/selection_pipe.zig index 8d06077e..200eff95 100644 --- a/src/selection_pipe.zig +++ b/src/selection_pipe.zig @@ -51,7 +51,7 @@ pub const Job = struct { token: u32 = 0, env: [][]u8 = &.{}, - pub fn copy(gpa: std.mem.Allocator, request: Request) !*Job { + pub fn copy(gpa: std.mem.Allocator, request: Request) error{OutOfMemory}!*Job { const job = try gpa.create(Job); errdefer gpa.destroy(job); job.* = .{ diff --git a/src/syntax.zig b/src/syntax.zig index a498357c..753b11b1 100644 --- a/src/syntax.zig +++ b/src/syntax.zig @@ -298,7 +298,7 @@ pub fn highlightFileRange(gpa: std.mem.Allocator, path: []const u8, content: []c const zone = tracy.zone(@src(), "highlightFileRange"); defer zone.end(); if (!enabled) return &.{}; - const selected = (try forExt(std.fs.path.extension(path))) orelse return &.{}; + const selected = (try forExt(std.Io.Dir.path.extension(path))) orelse return &.{}; const start_byte = @min(start_raw, content.len); const end_byte = @max(start_byte, @min(end_raw, content.len)); const source = content[start_byte..end_byte]; @@ -313,7 +313,7 @@ pub fn highlightFileRange(gpa: std.mem.Allocator, path: []const u8, content: []c /// ready here, on the loop, so the worker only reads its query. pub fn readyApart(path: []const u8) bool { if (!enabled) return false; - const selected = (forExt(std.fs.path.extension(path)) catch return false) orelse return false; + const selected = (forExt(std.Io.Dir.path.extension(path)) catch return false) orelse return false; return !std.mem.eql(u8, selected.name, "markdown") and !std.mem.eql(u8, selected.name, "typst"); } @@ -322,7 +322,7 @@ pub fn readyApart(path: []const u8) bool { /// is only read); `halt` ends the parse early. After `readyApart`. pub fn highlightApart(gpa: std.mem.Allocator, path: []const u8, source: []const u8, halt: *const std.atomic.Value(bool)) ![]u8 { if (comptime !enabled) return &.{}; - const shared = (try forExt(std.fs.path.extension(path))) orelse return &.{}; + const shared = (try forExt(std.Io.Dir.path.extension(path))) orelse return &.{}; const tree = try parseApart(shared.lang, source, halt); defer tree.destroy(); if (halt.load(.monotonic)) return error.Canceled; @@ -379,7 +379,7 @@ pub const ContextDeclaration = struct { pub fn supportsPath(path: []const u8) bool { if (!enabled) return false; - const ext = std.fs.path.extension(path); + const ext = std.Io.Dir.path.extension(path); for (specs) |spec| for (spec.exts) |choice| { if (std.ascii.eqlIgnoreCase(ext, choice)) return true; }; @@ -390,7 +390,7 @@ pub fn supportsPath(path: []const u8) bool { /// (helix's Alt-o and kin). Opaque outside this file; null without a grammar. pub fn parseTree(path: []const u8, content: []const u8) ?*anyopaque { if (!enabled) return null; - const selected = (forExt(std.fs.path.extension(path)) catch return null) orelse return null; + const selected = (forExt(std.Io.Dir.path.extension(path)) catch return null) orelse return null; const tree = selected.parser.parseString(content, null) orelse return null; if (held_trees) |h| h.born.append(h.meta, @ptrCast(tree)) catch {}; return @ptrCast(tree); @@ -510,7 +510,7 @@ fn objectName(o: Object) []const u8 { /// The grammar's textobject query for `path`, compiled the first time; null /// when the grammar has none. fn objectQuery(path: []const u8) ?*ts.Query { - const ext = std.fs.path.extension(path); + const ext = std.Io.Dir.path.extension(path); for (&specs) |*spec| for (spec.exts) |choice| { if (!std.ascii.eqlIgnoreCase(ext, choice)) continue; if (spec.objects) |q| return q; @@ -557,11 +557,12 @@ fn matchSpan(q: *const ts.Query, match: anytype, capture: u32, text: []const u8) const want = if (pred[2].type == .string) q.stringValueForId(pred[2].value_id) orelse continue else for (match.captures) |c| { if (c.index == pred[2].value_id) break text[@min(c.node.startByte(), text.len)..@min(c.node.endByte(), text.len)]; } else continue; - if (std.mem.eql(u8, op, "eq?")) { - if (!std.mem.eql(u8, subject, want)) return null; - } else if (std.mem.eql(u8, op, "match?")) { - var re = regexp.Regex.compile(want) catch continue; - if ((re.find(subject, 0, subject.len, subject.len) catch null) == null) return null; + switch (std.meta.stringToEnum(enum { @"eq?", @"match?" }, op) orelse continue) { + .@"eq?" => if (!std.mem.eql(u8, subject, want)) return null, + .@"match?" => { + var re = regexp.Regex.compile(want) catch continue; + if ((re.find(subject, 0, subject.len, subject.len) catch null) == null) return null; + }, } } return found; @@ -652,7 +653,7 @@ pub const SourceAnalysis = struct { pub fn analyzeSource(gpa: std.mem.Allocator, path: []const u8, content: []const u8, want_declarations: bool, want_colors: bool) !SourceAnalysis { if (!enabled or content.len == 0 or (!want_declarations and !want_colors)) return .{}; - const selected = (try forExt(std.fs.path.extension(path))) orelse return .{}; + const selected = (try forExt(std.Io.Dir.path.extension(path))) orelse return .{}; const tree = selected.parser.parseString(content, null) orelse return .{}; defer tree.destroy(); var result: SourceAnalysis = .{}; @@ -677,7 +678,7 @@ pub fn contextDeclarations(gpa: std.mem.Allocator, path: []const u8, content: [] pub fn declarationsApart(gpa: std.mem.Allocator, path: []const u8, content: []const u8, halt: *const std.atomic.Value(bool)) ![]ContextDeclaration { if (comptime !enabled) return &.{}; if (content.len == 0) return &.{}; - const ext = std.fs.path.extension(path); + const ext = std.Io.Dir.path.extension(path); const spec = specs: for (&specs) |*spec| { for (spec.exts) |choice| if (std.ascii.eqlIgnoreCase(ext, choice)) break :specs spec; } else return &.{}; @@ -915,7 +916,7 @@ pub fn highlightLocations(gpa: std.mem.Allocator, content: []const u8, start_byt while (lines.next()) |line| { defer offset += line.len + 1; const code = codeAfterLocation(line) orelse continue; - const ext = std.fs.path.extension(code.path); + const ext = std.Io.Dir.path.extension(code.path); if (!std.mem.eql(u8, ext, memo_ext)) { memo_ext = ext; memo = forExt(ext) catch null; @@ -972,7 +973,7 @@ pub fn highlightLocationRows(gpa: std.mem.Allocator, content: []const u8, rows: const previous = rows[sources[end - 1].index]; if (!std.mem.eql(u8, row.path, first_row.path) or row.at.line != previous.at.line +| 1) break; } - const language = (forExt(std.fs.path.extension(first_row.path)) catch null); + const language = (forExt(std.Io.Dir.path.extension(first_row.path)) catch null); if (language) |selected| { var code_len: usize = 0; for (sources[first..end]) |source| { @@ -1247,7 +1248,7 @@ const DiffWindow = struct { }; fn paintDiffPiece(gpa: std.mem.Allocator, window: DiffWindow, bytes: []const u8, at: usize, kinds: []const diff.Kind, path: []const u8) !void { - const selected: ?Selected = if (enabled and syntax_started) (forExt(std.fs.path.extension(path)) catch null) else null; + const selected: ?Selected = if (enabled and syntax_started) (forExt(std.Io.Dir.path.extension(path)) catch null) else null; if (selected) |sel| { const hash = std.hash.Wyhash.hash(std.hash.Wyhash.hash(0, sel.name), bytes); diff_clock += 1; @@ -2008,7 +2009,7 @@ test "syntax source analysis preserves declarations and injected colors" { // Compare the previous named-node walk to the cursor walk, including // source ordering, wrapper deduplication and inclusive declaration ends. - const selected = (try forExt(std.fs.path.extension(fixture.path))).?; + const selected = (try forExt(std.Io.Dir.path.extension(fixture.path))).?; const tree = selected.parser.parseString(fixture.source, null).?; defer tree.destroy(); var reference: std.ArrayList(ContextDeclaration) = .empty; diff --git a/src/wire.zig b/src/wire.zig index e39e25b4..65b93bf1 100644 --- a/src/wire.zig +++ b/src/wire.zig @@ -396,11 +396,6 @@ fn clientTag(msg: ClientMsg) ClientTag { }; } -/// Does the build this frontend was compiled with carry pixel dimensions in a -/// resize? The FIELD is comptime-conditional (pardes.zig `CellPixels`); the -/// WIRE is not. -const has_cell_pixels = @hasField(pardes.CellPixels, "w"); - fn putMetrics(w: *std.Io.Writer, metrics: ?pardes.RowMetrics) Error!void { try w.writeByte(@intFromBool(metrics != null)); if (metrics) |m| { @@ -525,11 +520,8 @@ pub fn encodeClient(out: []u8, msg: ClientMsg) Error![]const u8 { .resize => |rs| { try w.writeInt(u16, rs.cols, .little); try w.writeInt(u16, rs.rows, .little); - // The conventional 1:2 cell aspect when this build has no - // pixels of its own, which is the same default the field - // carries where it exists. - try w.writeInt(u16, if (comptime has_cell_pixels) rs.cell_pixels.w else 8, .little); - try w.writeInt(u16, if (comptime has_cell_pixels) rs.cell_pixels.h else 16, .little); + try w.writeInt(u16, rs.cell_pixels.w, .little); + try w.writeInt(u16, rs.cell_pixels.h, .little); try putMetrics(&w, rs.row_metrics); }, .paste => |b| try putSlice32(&w, b), @@ -605,10 +597,7 @@ pub fn decodeClient(tag: u8, payload: []const u8) Error!ClientMsg { .resize => blk: { var ev: pardes.Event = .{ .resize = .{ .cols = try getCols(&r), .rows = try getRows(&r) } }; const px_w = try r.takeInt(u16, .little); - const px_h = try r.takeInt(u16, .little); - // Read either way — the bytes are on the wire — and kept only by a - // build that has somewhere to keep them. - if (comptime has_cell_pixels) ev.resize.cell_pixels = .{ .w = px_w, .h = px_h }; + ev.resize.cell_pixels = .{ .w = px_w, .h = try r.takeInt(u16, .little) }; ev.resize.row_metrics = try getMetrics(&r); break :blk .{ .event = ev }; }, @@ -727,12 +716,9 @@ test "detached wire: every Event variant round-trips" { const got = (try roundClient(&buf, .{ .event = .{ .resize = .{ .cols = 56, .rows = 14 } } })).event.resize; try testing.expectEqual(@as(u16, 56), got.cols); try testing.expectEqual(@as(u16, 14), got.rows); - // Pixels travel whether or not this build has them; where it does, the - // conventional 1:2 default survives the trip. - if (comptime has_cell_pixels) { - try testing.expectEqual(@as(u16, 8), got.cell_pixels.w); - try testing.expectEqual(@as(u16, 16), got.cell_pixels.h); - } + // The conventional 1:2 default survives the trip. + try testing.expectEqual(@as(u16, 8), got.cell_pixels.w); + try testing.expectEqual(@as(u16, 16), got.cell_pixels.h); } try testing.expectEqualStrings("clip", (try roundClient(&buf, .{ .event = .{ .paste = "clip" } })).event.paste); try testing.expectEqualStrings("Look /x", (try roundClient(&buf, .{ .event = .{ .command = "Look /x" } })).event.command); |
