summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-11-04 23:28:52 -0300
committerGabriel Schneider <[email protected]>2026-11-05 01:00:59 -0300
commit43739b4eb99f2b68ec2368e6ec69491b2d9ab0b4 (patch)
tree13a088e2ab1629b520eb178e2ff972aab8675c74 /src
parentb6e7d53f6700988c33266b20eb3505bc3471451b (diff)
downloadpardes-43739b4eb99f2b68ec2368e6ec69491b2d9ab0b4.tar.gz
pardes-43739b4eb99f2b68ec2368e6ec69491b2d9ab0b4.zip
recent: the old `recent` file's import goes (List.read and Store.load's branch for a store not made yet, the store in use since 2026-10-24), and with it List.write, the format's other half only its test used; closed takes the selection's anchor itself, closedSel its only caller's spelling; recent.zig's test reads a record back through parseLine, docs/next-store.md says the import went
Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_016Y9MNAtZenFv4weoMD3cge
Diffstat (limited to 'src')
-rw-r--r--src/Store.zig20
-rw-r--r--src/pardes.zig2
-rw-r--r--src/recent.zig68
3 files changed, 20 insertions, 70 deletions
diff --git a/src/Store.zig b/src/Store.zig
index 9c726705..87dba4f7 100644
--- a/src/Store.zig
+++ b/src/Store.zig
@@ -293,23 +293,13 @@ fn parseMeta(body: []const u8) ?Meta {
return m;
}
-/// The store read at start; the old `recent` file beside it read into the
-/// list once, when there is no store yet, so nobody's list is lost.
+/// The store read at start.
pub fn load(s: *Store, p: *Pardes) void {
const path = s.path orelse return;
if (comptime !pardes.hosted) return;
defer s.loaded = true;
const io = ioOf();
- const file = host(Dir.openFile, .{ cwd(), io, path, Dir.OpenFileOptions{} }) catch |err| {
- if (err != error.FileNotFound) return;
- const dir = std.fs.path.dirname(path) orelse return;
- var buf: [4096 + 16]u8 = undefined;
- const old = std.fmt.bufPrint(&buf, "{s}/recent", .{dir}) catch return;
- const bytes = host(Dir.readFileAlloc, .{ cwd(), io, old, p.gpa, std.Io.Limit.limited(1 << 20) }) catch return;
- defer p.gpa.free(bytes);
- p.recent.read(p.recentGpa(), bytes);
- return;
- };
+ const file = host(Dir.openFile, .{ cwd(), io, path, Dir.OpenFileOptions{} }) catch return;
defer host(File.close, .{ file, io });
const st = host(File.stat, .{ file, io }) catch return;
s.readFile(p, file, st);
@@ -932,7 +922,7 @@ test "store: two windows share Recent, each reading the other's writes on use; a
a.saveRecent();
b.recent.opened(b.recentGpa(), "/w/b.zig");
b.saveRecent();
- a.recent.closed(a.recentGpa(), "/w/a.zig", 7, 3);
+ a.recent.closed(a.recentGpa(), "/w/a.zig", 7, 3, 0, 0);
a.saveRecent();
// Each has both, in the order of the log: a closed last, then b.
a.store.refresh(a);
@@ -981,7 +971,7 @@ test "store: the cap holds, compaction keeps the newest, Recent keeps its 200" {
for (0..3000) |i| {
const file = std.fmt.bufPrint(&name, "/w/file{d}.zig", .{i}) catch unreachable;
a.recent.opened(a.recentGpa(), file);
- a.recent.closed(a.recentGpa(), file, 1, 1);
+ a.recent.closed(a.recentGpa(), file, 1, 1, 0, 0);
a.saveRecent();
try testing.expect(fileSize(path) <= a.store.cap);
if (a.store.inode != last_inode) inodes += 1;
@@ -1192,7 +1182,7 @@ test "zz store timings on a 90 MiB store (STORE_TIMES=<dir>)" {
for (0..100) |i| {
const f = std.fmt.bufPrint(&name, "/w/new{d}.zig", .{i}) catch unreachable;
p.recent.opened(p.recentGpa(), f);
- p.recent.closed(p.recentGpa(), f, 1, 1);
+ p.recent.closed(p.recentGpa(), f, 1, 1, 0, 0);
p.saveRecent();
}
const flush_ns = (nowNs() - t) / 100;
diff --git a/src/pardes.zig b/src/pardes.zig
index 8f08ca06..d63c7beb 100644
--- a/src/pardes.zig
+++ b/src/pardes.zig
@@ -4334,7 +4334,7 @@ pub const Pardes = struct {
// authority's, and a step that asked only when it did not know the
// file would ask on one side and not the other.
if (!recentKeeps(d.path) and p.recent.get(d.path) == null) return;
- p.recent.closedSel(p.recentGpa(), d.path, d.line, d.col, d.aline, d.acol);
+ p.recent.closed(p.recentGpa(), d.path, d.line, d.col, d.aline, d.acol);
}
pub const RecentPlace = struct { path: []const u8, line: u32, col: u32, aline: u32 = 0, acol: u32 = 0 };
diff --git a/src/recent.zig b/src/recent.zig
index 2e3aabde..b8e275f5 100644
--- a/src/recent.zig
+++ b/src/recent.zig
@@ -61,14 +61,10 @@ pub const List = struct {
l.dirty = true;
}
- /// `path` closed with its dot at `line`:`col`: where a reopen lands.
- /// Its place in the list is its opening's.
- pub fn closed(l: *List, gpa: std.mem.Allocator, path: []const u8, line: u32, col: u32) void {
- l.closedSel(gpa, path, line, col, 0, 0);
- }
-
- /// `closed`, with the selection's anchor too (0 0 for none).
- pub fn closedSel(l: *List, gpa: std.mem.Allocator, path: []const u8, line: u32, col: u32, aline: u32, acol: u32) void {
+ /// `path` closed with its dot at `line`:`col` and its selection's anchor
+ /// at `aline`:`acol` (0 0 for none): where a reopen lands. Its place in
+ /// the list is its opening's.
+ pub fn closed(l: *List, gpa: std.mem.Allocator, path: []const u8, line: u32, col: u32, aline: u32, acol: u32) void {
const i = l.find(path) orelse found: {
l.opened(gpa, path);
// Out of memory for it: nothing to note the dot on.
@@ -148,46 +144,13 @@ pub const List = struct {
return l.entries.items[l.find(path) orelse return null];
}
- /// One line a file, `<line> <col> <aline> <acol> <path>`, most recent
- /// first: the old `recent` file, and a store record's body, a line.
- pub fn write(l: *const List, w: *std.Io.Writer) !void {
- for (l.entries.items) |e| try writeEntry(e, w);
- }
-
+ /// A store record's body, `<line> <col> <aline> <acol> <path>`, a line.
pub fn writeEntry(e: Entry, w: *std.Io.Writer) !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 });
}
- /// The lines `write` wrote (the old `recent` file), each changed for
- /// the store to hear of; a line that is not one is passed over.
- pub fn read(l: *List, gpa: std.mem.Allocator, bytes: []const u8) void {
- var lines = std.mem.splitScalar(u8, bytes, '\n');
- while (lines.next()) |line| {
- if (l.entries.items.len >= cap) break;
- // Numbers, then the path (which starts with `/`): two of them in
- // a list written before the anchor was kept, four since.
- var nums: [4]u32 = @splat(0);
- var n: usize = 0;
- var rest = line;
- while (rest.len > 0 and rest[0] != '/' and n < nums.len) : (n += 1) {
- const sp = std.mem.indexOfScalar(u8, rest, ' ') orelse break;
- nums[n] = std.fmt.parseInt(u32, rest[0..sp], 10) catch break;
- rest = rest[sp + 1 ..];
- }
- if (n != 2 and n != 4) continue;
- const path = rest;
- if (path.len == 0 or path[0] != '/' or l.find(path) != null) continue;
- const owned = gpa.dupe(u8, path) catch return;
- l.entries.append(gpa, .{ .path = owned, .line = nums[0], .col = nums[1], .aline = nums[2], .acol = nums[3], .changed = true }) catch {
- gpa.free(owned);
- return;
- };
- l.dirty = true;
- }
- }
-
/// One record's body read back: `<line> <col> <aline> <acol> <path>`.
pub fn parseLine(line: []const u8) ?struct { nums: [4]u32, path: []const u8 } {
var nums: [4]u32 = @splat(0);
@@ -208,28 +171,25 @@ test "the list keeps a path once, most recent first, its dot from closing, cappe
defer l.deinit(gpa);
l.opened(gpa, "/a");
l.opened(gpa, "/b");
- l.closed(gpa, "/a", 7, 3);
+ l.closed(gpa, "/a", 7, 3, 0, 0);
l.opened(gpa, "/a");
try std.testing.expectEqualStrings("/a", l.entries.items[0].path);
try std.testing.expectEqual(@as(usize, 2), l.entries.items.len);
try std.testing.expectEqual(@as(u32, 7), l.get("/a").?.line);
var buf: [256]u8 = undefined;
var w = std.Io.Writer.fixed(&buf);
- try l.write(&w);
+ for (l.entries.items) |e| try List.writeEntry(e, &w);
try std.testing.expectEqualStrings("7 3 0 0 /a\n0 0 0 0 /b\n", w.buffered());
- var again: List = .{};
- defer again.deinit(gpa);
- again.read(gpa, w.buffered());
- again.read(gpa, "junk\n");
- // A list written before the anchor was kept still reads.
- again.read(gpa, "4 2 /old\n");
- try std.testing.expectEqual(@as(u32, 4), again.get("/old").?.line);
- try std.testing.expectEqual(@as(usize, 3), again.entries.items.len);
+ // Each line a store record's body, read back.
+ const back = List.parseLine("7 3 0 0 /a").?;
+ try std.testing.expectEqual(@as(u32, 7), back.nums[0]);
+ try std.testing.expectEqualStrings("/a", back.path);
+ try std.testing.expect(List.parseLine("junk") == null);
for (0..cap + 5) |i| {
var name: [16]u8 = undefined;
const path = std.fmt.bufPrint(&name, "/f{d}", .{i}) catch unreachable;
l.opened(gpa, path);
- l.closed(gpa, path, 1, 1);
+ l.closed(gpa, path, 1, 1, 0, 0);
}
try std.testing.expectEqual(@as(usize, cap), l.entries.items.len);
}
@@ -242,7 +202,7 @@ test "the cap drops the oldest closed file, never an open one" {
// The oldest is open; the next is closed.
l.opened(gpa, "/open");
l.opened(gpa, "/shut");
- l.closed(gpa, "/shut", 1, 1);
+ l.closed(gpa, "/shut", 1, 1, 0, 0);
for (2..cap) |i| l.opened(gpa, std.fmt.bufPrint(&name, "/f{d}", .{i}) catch unreachable);
try std.testing.expectEqual(@as(usize, cap), l.entries.items.len);
l.opened(gpa, "/new");