summaryrefslogtreecommitdiff
path: root/core
diff options
context:
space:
mode:
Diffstat (limited to 'core')
-rw-r--r--core/Core.zig16
-rw-r--r--core/Effect.zig5
-rw-r--r--core/File.zig15
-rw-r--r--core/Query.zig4
-rw-r--r--core/ninep/ctl.zig4
-rw-r--r--core/ninep/events.zig2
-rw-r--r--core/ninep/pane.zig4
-rw-r--r--core/replica.zig31
8 files changed, 68 insertions, 13 deletions
diff --git a/core/Core.zig b/core/Core.zig
index 188df34c..b8ca9439 100644
--- a/core/Core.zig
+++ b/core/Core.zig
@@ -701,13 +701,21 @@ pub fn recentKeeps(path: []const u8) bool {
/// Recent keeps it.
pub fn noteClosed(p: *Pardes, pane: *const Pane) void {
const d = recentPlace(pane) orelse return;
- // The host asked first, always: what Recent holds is the
- // 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;
+ if (!onDisk(pane) and p.recent.get(d.path) == null) return;
p.recent.closed(p.recentGpa(), d.path, d.line, d.col, d.aline, d.acol);
}
+/// Whether a pane's file is one Recent keeps, as its open or last write
+/// learned it (File.State.on_disk; a kind's open read its file): never the
+/// disk, so a close or a pane installed asks nothing (a client's own Del or
+/// Zerox is instant). A file gone since that the watch has not said is
+/// noted all the same; Recent's reader skips it (Jump.jumpBy).
+pub fn onDisk(pane: *const Pane) bool {
+ if (pane.file) |f| return f.on_disk and !f.disk_gone;
+ if (pane.addon) |k| return filesystem.localPath(k.path) != null;
+ return false;
+}
+
pub const RecentPlace = struct { path: []const u8, line: u32, col: u32, aline: u32 = 0, acol: u32 = 0 };
/// Where a pane is, as Recent keeps it: a file's dot, a kind's pane's
diff --git a/core/Effect.zig b/core/Effect.zig
index 89a9b2e2..4d2009fb 100644
--- a/core/Effect.zig
+++ b/core/Effect.zig
@@ -165,9 +165,10 @@ pub fn perform(p: *Pardes, e: Effect) void {
// Edited while it was written: what is on disk is not this.
if (saved.saved_revision != saved.revision) return;
saved.disk_gone = false;
+ saved.on_disk = filesystem.localPath(saved.path) != null;
ctlfs.events.noteLog(p, .save, saved_pane);
// On disk now, a new file too: Recent has it, open.
- if (saved.output == null and Pardes.recentKeeps(saved.path)) p.recent.opened(p.recentGpa(), saved.path);
+ if (saved.output == null and saved.on_disk) p.recent.opened(p.recentGpa(), saved.path);
if (!saved.watch_after_save) return;
saved.watch_after_save = false;
if (filesystem.localPath(saved.path) != null)
@@ -242,6 +243,7 @@ pub fn perform(p: *Pardes, e: Effect) void {
} else if (w.clean != null and w.clean.? == f.revision) {
f.saved_revision = f.revision;
f.disk_gone = false;
+ f.on_disk = filesystem.localPath(f.path) != null;
ctlfs.events.noteLog(p, .save, pane);
} else ctlfs.events.noteLogAs(p, .save, pane, w.path);
}
@@ -307,6 +309,7 @@ fn promoteSaved(p: *Pardes, id: u8, path: []const u8) void {
pane.tag.own = null;
f.saved_revision = f.revision;
f.disk_gone = false;
+ f.on_disk = filesystem.localPath(f.path) != null;
ctlfs.events.noteLog(p, .save, pane);
p.recent.opened(p.recentGpa(), f.path);
if (filesystem.localPath(f.path) != null)
diff --git a/core/File.zig b/core/File.zig
index 36e014b3..fdf57fdf 100644
--- a/core/File.zig
+++ b/core/File.zig
@@ -122,6 +122,11 @@ pub const State = struct {
/// Its file was deleted on disk: said once (`deleted`) until it is
/// written or found again.
disk_gone: bool = false,
+ /// Its text was read from, or written to, a file of this host's disk
+ /// at its path (not the served tree's, nor a name never saved): what
+ /// Recent keeps (Pardes.onDisk), learned where that read or write ran,
+ /// so a close asks the disk nothing.
+ on_disk: bool = false,
/// A +Pager pane (`pardes -`): no line numbers, its program's colours
/// through Filter until it is toggled off.
pager: bool = false,
@@ -572,7 +577,7 @@ pub fn open(p: *Pardes, id: usize, path: []const u8, line: usize) !*Pane {
errdefer p.gpa.free(content);
const total = lineCount(content);
const scroll: usize = if (line > 0 and line <= total) line - 1 else 0;
- pane.file = .{ .path = path_copy, .content = content, .scroll = scroll, .history = history };
+ pane.file = .{ .path = path_copy, .content = content, .scroll = scroll, .history = history, .on_disk = filesystem.localPath(path) != null };
pane.body.cur_pinned = true;
pane.body.cur_row = @intCast(scroll);
p.installPane(id, pane);
@@ -959,7 +964,7 @@ pub fn zerox(p: *Pardes, from: usize, to: usize) !*Pane {
if (f.twin == 0) {
const group = try p.gpa.dupe(u8, f.path);
errdefer p.gpa.free(group);
- try p.twin_groups.append(p.gpa, .{ .id = p.next_twin, .saved_revision = f.saved_revision, .saved_hash = f.saved_hash, .saved_len = f.saved_len, .disk_newer = f.disk_newer, .disk_gone = f.disk_gone, .path = group });
+ try p.twin_groups.append(p.gpa, .{ .id = p.next_twin, .saved_revision = f.saved_revision, .saved_hash = f.saved_hash, .saved_len = f.saved_len, .disk_newer = f.disk_newer, .disk_gone = f.disk_gone, .on_disk = f.on_disk, .path = group });
f.twin = p.next_twin;
p.next_twin +%= 1;
}
@@ -977,6 +982,7 @@ pub fn zerox(p: *Pardes, from: usize, to: usize) !*Pane {
.saved_len = f.saved_len,
.disk_newer = f.disk_newer,
.disk_gone = f.disk_gone,
+ .on_disk = f.on_disk,
.mtime = f.mtime,
.scroll = f.scroll,
.tree_context = f.tree_context,
@@ -1019,6 +1025,7 @@ pub const TwinGroup = struct {
saved_len: ?usize,
disk_newer: ?u64,
disk_gone: bool,
+ on_disk: bool,
path: []u8,
};
@@ -1050,7 +1057,7 @@ pub fn syncTwins(p: *Pardes) void {
}
for (members[0..n]) |f| {
if (f.saved_revision == group.saved_revision and f.saved_hash == group.saved_hash and f.saved_len == group.saved_len and
- f.disk_newer == group.disk_newer and f.disk_gone == group.disk_gone and std.mem.eql(u8, f.path, group.path)) continue;
+ f.disk_newer == group.disk_newer and f.disk_gone == group.disk_gone and f.on_disk == group.on_disk and std.mem.eql(u8, f.path, group.path)) continue;
// This one changed: the group, and every other twin, take it.
if (!std.mem.eql(u8, f.path, group.path)) {
const path = p.gpa.dupe(u8, f.path) catch break;
@@ -1062,6 +1069,7 @@ pub fn syncTwins(p: *Pardes) void {
group.saved_len = f.saved_len;
group.disk_newer = f.disk_newer;
group.disk_gone = f.disk_gone;
+ group.on_disk = f.on_disk;
for (members[0..n], member_panes[0..n]) |other, other_pane| {
if (other == f) continue;
other.saved_revision = f.saved_revision;
@@ -1069,6 +1077,7 @@ pub fn syncTwins(p: *Pardes) void {
other.saved_len = f.saved_len;
other.disk_newer = f.disk_newer;
other.disk_gone = f.disk_gone;
+ other.on_disk = f.on_disk;
if (!std.mem.eql(u8, other.path, f.path)) {
const path = p.gpa.dupe(u8, f.path) catch continue;
p.gpa.free(other.path);
diff --git a/core/Query.zig b/core/Query.zig
index 615919c1..30b07e92 100644
--- a/core/Query.zig
+++ b/core/Query.zig
@@ -1751,9 +1751,11 @@ fn promote(p: *Pardes, qid: usize, id: usize) void {
f.saved_hash = null;
f.saved_len = null;
f.disk_gone = false;
+ // Its text was read from that file to preview it (displayPreview).
+ f.on_disk = filesystem.localPath(f.path) != null;
f.syntax_dirty = true;
pane.attached_to = null;
- if (Pardes.recentKeeps(f.path)) p.recent.opened(p.recentGpa(), f.path);
+ if (f.on_disk) p.recent.opened(p.recentGpa(), f.path);
if (filesystem.localPath(f.path) != null) p.emit(.{ .watch = .{ .pane = @intCast(id), .on = true } });
pardes.ctlfs.events.noteLog(p, .rename, pane);
p.panes[qid].?.query.?.preview = 0;
diff --git a/core/ninep/ctl.zig b/core/ninep/ctl.zig
index 2f008927..2b26c3e2 100644
--- a/core/ninep/ctl.zig
+++ b/core/ninep/ctl.zig
@@ -1281,7 +1281,8 @@ pub fn getFile(p: *Pardes, pane: *Pane, path: []const u8) GetError!void {
f.disk_newer = null;
f.disk_newer_warned = false;
f.disk_gone = false;
- if (fs.localPath(path) != null) p.emit(.{ .watch = .{ .pane = @intCast(id), .on = true } });
+ f.on_disk = fs.localPath(path) != null;
+ if (f.on_disk) p.emit(.{ .watch = .{ .pane = @intCast(id), .on = true } });
}
/// What Get and Edit's `e` fail with, as their callers say it (the 9P
@@ -1312,6 +1313,7 @@ pub fn get(p: *Pardes, pane: *Pane) GetError!void {
f.saved_len = f.content.len;
f.disk_newer = null;
f.disk_gone = false;
+ f.on_disk = fs.localPath(f.path) != null;
if (discarded) {
var rec: [32]u8 = undefined;
pardes.ctlfs.events.notePath(p, "changed", std.fmt.bufPrint(&rec, "{d} reloaded", .{pane.serial}) catch unreachable); // a u32 fits 32
diff --git a/core/ninep/events.zig b/core/ninep/events.zig
index 6946401b..2d539cca 100644
--- a/core/ninep/events.zig
+++ b/core/ninep/events.zig
@@ -148,7 +148,7 @@ pub fn announce(p: *Pardes) void {
noteLog(p, .new, pane);
// A file, PDF or image opened (a look, a Restore, a boot): first in
// Recent.
- if (pardes.Pardes.recentPlace(pane)) |d| if (pardes.Pardes.recentKeeps(d.path)) p.recent.opened(p.recentGpa(), d.path);
+ if (pardes.Pardes.recentPlace(pane)) |d| if (pardes.Pardes.onDisk(pane)) p.recent.opened(p.recentGpa(), d.path);
}
}
diff --git a/core/ninep/pane.zig b/core/ninep/pane.zig
index e9e43095..b940bdd6 100644
--- a/core/ninep/pane.zig
+++ b/core/ninep/pane.zig
@@ -943,7 +943,9 @@ pub fn nameBuffer(p: *Pardes, id: usize, full: []const u8, preserve_tag: bool) !
look.invalidateLookHover(p, id);
p.emit(.{ .watch = .{ .pane = @intCast(id), .on = false } });
events.noteLog(p, .rename, pane);
- if (f.output == null and pardes.Pardes.recentKeeps(f.path)) p.recent.opened(p.recentGpa(), f.path);
+ // A name given: whether a file there is on disk is the disk's to say.
+ f.on_disk = f.output == null and pardes.Pardes.recentKeeps(f.path);
+ if (f.on_disk) p.recent.opened(p.recentGpa(), f.path);
}
/// Diagnostics go to the +Errors buffer of the pane's directory.
diff --git a/core/replica.zig b/core/replica.zig
index dc5d99a4..5ce8454e 100644
--- a/core/replica.zig
+++ b/core/replica.zig
@@ -5062,7 +5062,8 @@ const SeenHost = struct {
of(ctx).linked += 1;
}
fn watchTheme(_: ?*anyopaque, _: u32, _: bool) void {}
- const vtable: pardes.Host.VTable = .{ .watched = TestHost.watched, .set_clipboard = setClipboard, .read_clipboard = readClipboard, .open_link = openLink, .watch_theme = watchTheme };
+ fn watchFile(_: ?*anyopaque, _: u8, _: []const u8, _: bool, _: pardes.WatchMode) void {}
+ const vtable: pardes.Host.VTable = .{ .watched = TestHost.watched, .set_clipboard = setClipboard, .read_clipboard = readClipboard, .open_link = openLink, .watch_theme = watchTheme, .watch_file = watchFile };
fn host(h: *SeenHost) pardes.Host {
return .{ .ctx = h, .vtable = &vtable };
}
@@ -5163,3 +5164,31 @@ test "a client's yank and paste of the system clipboard are its own frontend's:
_ = try a.own(.{ .command = "ClipYank" });
try std.testing.expectEqual(@as(u32, 1), h.yanked);
}
+
+test "a client's own Zerox and Del of a file pane are instant: what Recent keeps of the file is what its open learned, not a question to the disk; Recent has its place as the session's always did" {
+ const gpa = std.testing.allocator;
+ var h: SeenHost = .{};
+ const a = try Authority.init(gpa, .{ .cols = 80, .rows = 24, .file = "mise.toml" }, h.host(), false);
+ defer a.deinit();
+ h.core = a.core;
+ var cwd: [std.Io.Dir.max_path_bytes]u8 = undefined;
+ var line: [std.Io.Dir.max_path_bytes + 32]u8 = undefined;
+ var path_buf: [std.Io.Dir.max_path_bytes + 32]u8 = undefined;
+ const dir = std.mem.span(@as([*:0]u8, @ptrCast(std.c.getcwd(&cwd, cwd.len) orelse return error.NoCwd)));
+ const path = try std.fmt.bufPrint(&path_buf, "{s}/build.zig.zon", .{dir});
+ _ = try a.local(.{ .command = try std.fmt.bufPrint(&line, "Look {s}", .{path}) });
+ const r = try joinedFresh(a);
+ defer r.deinit();
+ // The twin, then each closed: the twin, the file.
+ for ([_][]const u8{ "Zerox", "Del", "Del" }) |cmd| {
+ const msg = try gpa.dupe(u8, try r.input(.{ .command = cmd }));
+ defer gpa.free(msg);
+ try std.testing.expectEqual(@as(usize, 1), r.applied);
+ r.confirm(try a.take(msg));
+ r.settle();
+ try agrees(a, r);
+ }
+ try std.testing.expectEqual(@as(u32, 0), r.stats.stopped);
+ try std.testing.expectEqual(@as(u32, 0), r.stats.mispredicted);
+ try std.testing.expect(a.core.recent.get(path) != null);
+}