From 80f4398f1fed8d46d73cab8045005c02189b34fc Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Fri, 6 Nov 2026 12:40:11 -0300 Subject: idioms #14, the rest: wire's has_cell_pixels (@hasField on a struct that always has the field) goes with its comptime branches, syntax's predicate ops are a stringToEnum switch, the public surfaces of sam_edit, locations, Names, Macro, selection_pipe, recent and builtins_json name their sets (OutOfMemory, Writer.Error), and std.fs.path and max_path_bytes are std.Io.Dir's Co-Authored-By: Claude Fable 5.1 Claude-Session: https://claude.ai/code/session_016Y9MNAtZenFv4weoMD3cge --- src/hunks.zig | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'src/hunks.zig') 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 -- cgit v1.3