summaryrefslogtreecommitdiff
path: root/src/dump.zig
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-11-12 10:56:42 -0300
committerGabriel Schneider <[email protected]>2026-11-17 12:15:01 -0300
commitf2b02c455f2bcdfb905a015eefbb630a28b4b12e (patch)
treec344c7ad42ec288dd5e1ebd0eb6d25f5aa2fbccc /src/dump.zig
parentfc38c73c59f7855a4caad8aa4d3bb8e023309c13 (diff)
downloadpardes-f2b02c455f2bcdfb905a015eefbb630a28b4b12e.tar.gz
pardes-f2b02c455f2bcdfb905a015eefbb630a28b4b12e.zip
addons: an addon can hand the frontend a GPU scene (ABI 3.1), and a snake drawn by shaders does; a commit's patch keeps its own +Diff pane; a real ZLS checked through the window build
ABI 3.1 appends an optional `gpu` callback and its context to pa_paint: one self-contained sketchbook SGPU v1 scene for the pane, at most 4 MiB, copied during the call, the last successful call winning. The SDL frontend runs it on its own GPU through sketchbook's executor and composites its target texture into the pane; replicas carry the scene beside the authoritative pane frame; cells and rasters stay the fallback for terminals, older hosts and frontends without an executor. addons/snake_shader is such an addon (`zig build snake-shader`, the SnakeShader word: a board that follows its pane, buffered turns, a CRT look), with test/gpu_snake.py, test/gpu_snake_interaction.py and test/gpu_upgrade.py. Commit patches open as `+Diff-<short-hash>` and reuse only their own commit's pane, so another paged patch no longer replaces one already open. The language-server client looks in the standard per-user bin directory, which desktop launchers often leave out of PATH, and takes an empty answer that beats the startup progress notification onto the wire; test/real_zls.py checks imports, hover, references, rename previews, diagnostics and completion against a real ZLS from a private home. The dump's schema reader skips two fields older builds persisted, and a replica's shadow of a kind ticks when the authority's does. The reference, the guide, the building and setup notes and the changelog say so. The working copy as it stood on 2026-11-12; message written by Claude from the diff, at the author's request.
Diffstat (limited to 'src/dump.zig')
-rw-r--r--src/dump.zig75
1 files changed, 68 insertions, 7 deletions
diff --git a/src/dump.zig b/src/dump.zig
index 517544fa..a880c7e1 100644
--- a/src/dump.zig
+++ b/src/dump.zig
@@ -747,6 +747,7 @@ pub fn loadPane(p: *Pardes, id: usize, bytes: []const u8) !*pardes.panes.Pane {
const SlotRecord = struct {
name: []const u8 = "",
version: u32 = 0,
+ gen: u32 = 0,
path: []const u8 = "",
where: []const u8 = "",
art: @import("surface.zig").Placement.Art = .{},
@@ -774,7 +775,7 @@ const SlotRecord = struct {
pub fn slotWrite(s: *const Kind.Slot, gpa: std.mem.Allocator, w: *std.Io.Writer) !void {
var place: [32]u8 = undefined;
- var r: SlotRecord = .{ .name = s.nameOf(), .version = s.version, .path = s.path, .art = s.art, .record = s.record, .where = s.where_text.slice(), .values = s.values.slice(), .live = s.live, .next_tick = s.next_tick, .views = s.views, .focused = s.focused, .cancelled = s.cancelled, .prefix = s.prefix.slice(), .refused = s.refused.slice(), .tail = s.tail.slice(), .selection = s.selection };
+ var r: SlotRecord = .{ .name = s.nameOf(), .version = s.version, .gen = s.gen, .path = s.path, .art = s.art, .record = s.record, .where = s.where_text.slice(), .values = s.values.slice(), .live = s.live, .next_tick = s.next_tick, .views = s.views, .focused = s.focused, .cancelled = s.cancelled, .prefix = s.prefix.slice(), .refused = s.refused.slice(), .tail = s.tail.slice(), .selection = s.selection };
var owned: ?[]u8 = null;
defer if (owned) |o| s.gpa.free(o);
if (s.ops != null) {
@@ -806,7 +807,7 @@ pub fn slotRead(out: *Kind.Slot, gpa: std.mem.Allocator, bytes: []const u8) !voi
var arena: std.heap.ArenaAllocator = .init(gpa);
defer arena.deinit();
const r = try walk.load(SlotRecord, arena.allocator(), bytes, null);
- out.* = .{ .gpa = gpa, .arena = .init(gpa), .version = r.version, .art = r.art, .live = r.live, .next_tick = r.next_tick, .views = r.views, .focused = r.focused, .cancelled = r.cancelled };
+ out.* = .{ .gpa = gpa, .arena = .init(gpa), .version = r.version, .gen = r.gen, .art = r.art, .live = r.live, .next_tick = r.next_tick, .views = r.views, .focused = r.focused, .cancelled = r.cancelled };
errdefer out.free();
@memcpy(out.name[0..@min(15, r.name.len)], r.name[0..@min(15, r.name.len)]);
out.path = try gpa.dupe(u8, r.path);
@@ -844,11 +845,14 @@ pub fn reviveSlot(p: *Pardes, id: usize, s: *Kind.Slot) void {
if (!Kind.reopen(p, id, s, bytes)) {
s.ops = null;
s.live = false;
- } else if (s.ops == null) {
- // A replica's Shadow is the authority's pane as it is: it ticks
- // when that one does, not because it was loaded (a kind opened
- // here ticks to lay itself out).
- s.next_tick, s.views, s.focused = kept;
+ } else {
+ s.version = p.kinds.kinds[k].version;
+ if (s.ops == null) {
+ // A replica's Shadow is the authority's pane as it is: it ticks
+ // when that one does, not because it was loaded (a kind opened
+ // here ticks to lay itself out).
+ s.next_tick, s.views, s.focused = kept;
+ }
}
}
@@ -1125,3 +1129,60 @@ test "an old dump's file, a byte dump, is read by -l and by a Restore of its pat
defer gpa.free(again);
try std.testing.expectEqualSlices(u8, bytes, again);
}
+
+test "restored syntax context caches are rebuilt rather than loaded with the core allocator" {
+ const gpa = std.testing.allocator;
+ var syntax_gpa: std.heap.DebugAllocator(.{}) = .init;
+ defer std.testing.expect(syntax_gpa.deinit() == .ok) catch @panic("syntax allocator leaked");
+ const opts: Pardes.Options = .{ .tty_only = true, .tree_sitter_allocator = syntax_gpa.allocator() };
+ const p = try Pardes.init(gpa, opts);
+ defer p.deinit();
+ const pane = try p.setTestFile("fn example() void {}\n");
+ const f = &pane.file.?;
+ const declarations = try p.tree_sitter_gpa.alloc(pardes.syntax.ContextDeclaration, 1);
+ @memset(std.mem.sliceAsBytes(declarations), 0);
+ f.context.replace(p.tree_sitter_gpa, declarations, f.revision);
+ // Older builds persisted these two fields; the schema reader must skip them too.
+ const OldFile = struct {
+ path: []const u8,
+ content: []const u8,
+ history: *pardes.panes.File.History,
+ context_declarations: []pardes.syntax.ContextDeclaration,
+ context_revision: ?u32,
+ };
+ const old_bytes = try walk.save(OldFile, gpa, &.{
+ .path = f.path,
+ .content = f.content,
+ .history = f.history,
+ .context_declarations = f.context.declarations,
+ .context_revision = f.context.revision,
+ });
+ defer gpa.free(old_bytes);
+ var arena: std.heap.ArenaAllocator = .init(gpa);
+ defer arena.deinit();
+ const old = try walk.load(pardes.panes.File.State, arena.allocator(), old_bytes, null);
+ try std.testing.expectEqual(@as(usize, 0), old.context.declarations.len);
+ try std.testing.expectEqual(@as(?u32, null), old.context.revision);
+ const bytes = try dumpBytes(p);
+ defer gpa.free(bytes);
+ const q = try load(gpa, opts, bytes, null);
+ defer q.deinit();
+ for (q.panes) |slot| if (slot) |restored| if (restored.file) |file| {
+ try std.testing.expectEqual(@as(usize, 0), file.context.declarations.len);
+ try std.testing.expectEqual(@as(?u32, null), file.context.revision);
+ };
+}
+
+test "optional GPU addon reload generation survives a replica dump" {
+ const gpa = std.testing.allocator;
+ var original: Kind.Slot = .{ .gpa = gpa, .arena = .init(gpa), .gen = 7, .live = true };
+ defer original.free();
+ var bytes: std.Io.Writer.Allocating = .init(gpa);
+ defer bytes.deinit();
+ try slotWrite(&original, gpa, &bytes.writer);
+ var restored: Kind.Slot = undefined;
+ try slotRead(&restored, gpa, bytes.written());
+ defer restored.free();
+ try std.testing.expectEqual(original.gen, restored.gen);
+ try std.testing.expectEqual(walk.digest(Kind.Slot, &original), walk.digest(Kind.Slot, &restored));
+}