summaryrefslogtreecommitdiff
path: root/test/session.zig
diff options
context:
space:
mode:
Diffstat (limited to 'test/session.zig')
-rw-r--r--test/session.zig20
1 files changed, 20 insertions, 0 deletions
diff --git a/test/session.zig b/test/session.zig
index 71d723a4..71627dad 100644
--- a/test/session.zig
+++ b/test/session.zig
@@ -196,12 +196,17 @@ pub const Session = struct {
// As the server does (src/9p_io.zig): a clunk's held lines run then.
if (q.op == .release) pardes.ctlfs.runClosedLines(pardesOf(s));
s.drain();
+ // A Restore asked for is performed once its write is answered (the
+ // write's reply holds nothing of the core it replaces).
+ s.restoreIfAsked();
return r;
}
fn drain(s: *Session) void {
while (pardesOf(s).nextEffect()) |e| switch (e) {
.save_file, .save_text => s.saved += 1,
+ // Into the session's state (a database in memory, or its file).
+ .write_dump => pardes.host_io.writeDump(pardesOf(s), pardesOf(s).dump_out.?),
.lsp => |q| if (s.languages) |io| s.askServer(io, .{ .id = q.id, .kind = q.kind, .pane = q.pane, .offset = q.offset, .arg = q.arg.slice() }),
else => {},
};
@@ -224,6 +229,21 @@ pub const Session = struct {
p.update(.{ .lsp_resp = .{ .id = req.id, .rows = rows } });
}
+ /// A Restore the write asked for, performed as a host performs it after
+ /// the write is answered (host_io.restoreCore): the dump read, and the
+ /// new core in the old one's place.
+ fn restoreIfAsked(s: *Session) void {
+ const p = pardesOf(s);
+ const gpa = p.gpa;
+ const name = p.takeRestore() orelse return;
+ const bytes = pardes.dump.restoreBytes(p, gpa, name) catch |err| return p.reportError(p.active, "Restore", err);
+ defer gpa.free(bytes);
+ const nc = pardes.dump.restore(p, bytes, name) catch |err| return p.reportError(p.active, "Restore", err);
+ p.deinit();
+ s.core = nc;
+ s.drain();
+ }
+
fn pardesOf(s: *Session) *Pardes {
return @ptrCast(@alignCast(s.core));
}