summaryrefslogtreecommitdiff
path: root/src/ninep
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-11-05 00:21:19 -0300
committerGabriel Schneider <[email protected]>2026-11-05 01:00:58 -0300
commitcb81dc5bc2ab3ea5cf7475871a97710d2f876e8b (patch)
tree77cb1eb2475d9a9b32898ae477701d6fe03b3034 /src/ninep
parent79311cd89746738a20be359c054dc2a7c84577db (diff)
downloadpardes-cb81dc5bc2ab3ea5cf7475871a97710d2f876e8b.tar.gz
pardes-cb81dc5bc2ab3ea5cf7475871a97710d2f876e8b.zip
ninep tree: resolveSelf walks the tree with lookup, a name at a time, refusing os and /pane/new itself, where it re-implemented lookup's rules and missed the columns: an editor path col/<n>/tag (Look, /n/self) now names that column's tag, as the wire serves it, the equivalence test checking it
Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_016Y9MNAtZenFv4weoMD3cge
Diffstat (limited to 'src/ninep')
-rw-r--r--src/ninep/tree.zig47
1 files changed, 18 insertions, 29 deletions
diff --git a/src/ninep/tree.zig b/src/ninep/tree.zig
index 3d715c51..b55065fd 100644
--- a/src/ninep/tree.zig
+++ b/src/ninep/tree.zig
@@ -414,40 +414,26 @@ pub fn nextSerialAfter(p: *Pardes, after: u32) ?u32 {
return best;
}
-/// An editor path below the root (`pane/3/body`, `index`, `src/...`) to its node.
+/// An editor path below the root (`pane/3/body`, `index`, `col/2/tag`,
+/// `src/...`) to its node: the walk a client's would be, a lookup a name,
+/// but for `os` (the disk is /n/os's) and /pane/new, served on the wire but
+/// unreachable from an editor path: this resolves Look targets and hover
+/// previews, and a preview that opened `new` to see what was there would
+/// make a pane per hover.
pub fn resolveSelf(p: *Pardes, path: []const u8) ?u64 {
var path_buf: [4096]u8 = undefined;
const normalized = fs.normalizeVirtualPath(path, &path_buf) orelse return null;
+ var node = root;
var parts = std.mem.tokenizeScalar(u8, normalized, '/');
- const first = parts.next() orelse return root;
- if (!std.mem.eql(u8, first, "pane")) {
- // `new` is reached in /pane, where the panes it makes are.
- const top = std.meta.stringToEnum(TopFile, first) orelse return sources.node(normalized);
- if (top == .root or top == .new or top == .pane or parts.next() != null) return null;
- return @backingInt(top);
+ while (parts.next()) |name| {
+ if (node == root and std.mem.eql(u8, name, "os")) return null;
+ if (node == @backingInt(TopFile.pane) and std.mem.eql(u8, name, new_pane)) return null;
+ const req: Req = .{ .tag = 0, .op = .lookup, .node = node, .data = name };
+ const found = if (node & sources.archive_node != 0) sources.handle(p, req) else lookup(p, req, Node.target(node) orelse return null);
+ if (found.status != .ok) return null;
+ node = found.attr.node;
}
- const next = parts.next() orelse return @backingInt(TopFile.pane);
- // `new` is served on the wire but deliberately unreachable from an editor
- // path: this resolves Look targets and hover previews, and a preview that
- // opened `new` to see what was there would make a pane per hover.
- if (std.mem.eql(u8, next, new_pane)) return null;
- // A pane directory is its serial, in decimal digits and never 0.
- if (next.len > 10) return null;
- for (next) |c| if (c < '0' or c > '9') return null;
- const serial = std.fmt.parseInt(u32, next, 10) catch return null;
- if (serial == 0) return null;
- const id = p.paneBySerial(serial) orelse return null;
- // The pty files are reached inside pty/, not beside it.
- const file = std.meta.stringToEnum(PaneFile, parts.next() orelse return Node.of(serial, .dir)) orelse return null;
- if (file == .dir or (file.inPty() and file != .pty)) return null;
- if (file.inPty() and !p.panes[id].?.isTerminal()) return null;
- if (parts.next()) |name| {
- if (file != .pty) return null;
- const child = pty.fileNamed(name) orelse return null;
- if (parts.next() != null) return null;
- return Node.of(serial, child);
- }
- return Node.of(serial, file);
+ return node;
}
// ---- staging ----
@@ -1766,6 +1752,9 @@ test "editor paths resolve to the same nodes the wire serves" {
try testing.expect(resolveSelf(p, "status/ctl") == null);
try testing.expect(resolveSelf(p, "cons") == null);
try testing.expect(resolveSelf(p, "pane/0") == null);
+ // A column's files, as the wire serves them.
+ const col = layout.columnSerial(p, 0);
+ try testing.expectEqual(Node.ofCol(col, .tag), resolveSelf(p, try std.fmt.bufPrint(&path, "col/{d}/tag", .{col})).?);
// The editor resolves its own paths to inspect them, so `new` names
// nothing here; only a client's walk makes a pane.
const before = p.next_serial;