From 5caef6d571f51e98eab3a48c063678ad35e09cce Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Tue, 17 Nov 2026 00:25:19 -0300 Subject: hunks: format stacks for a narrow Ctx, not a *Pardes: its two allocators, `source(dir, path)` (a file as a look from dir finds it), `declarations(path, bytes)` and the one setting, tslocations; Output.openDiff gives the editor's, its reads the same taped sites as before (locations.sourceText: an open pane's text, else fs.read) and its declarations the locations cache's, so a replica still replays the authority's bytes; displayWidth from File.zig itself; the four format tests read the disk through a Ctx of their own and stop booting a whole Pardes (the look and refill tests still drive the editor); goldens unchanged Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_016Y9MNBECMWcJD5pdS4SR6T --- src/Output.zig | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) (limited to 'src/Output.zig') diff --git a/src/Output.zig b/src/Output.zig index 0c6fdfc2..d4be640c 100644 --- a/src/Output.zig +++ b/src/Output.zig @@ -490,8 +490,33 @@ pub fn fillRows(p: *Pardes, id: usize, dir: []const u8, from: Origin, arg: []con /// NoHunks when there is none in it. pub fn openDiff(p: *Pardes, id: usize, path: []const u8, content: []const u8) !usize { const dir = std.Io.Dir.path.dirname(path) orelse p.sessionDir(); - const root = hunks.sourceRoot(p, dir, content); - const result = try hunks.format(p, root, content); + // Each file read is a site of the step's tape (fs.zig): a replica + // replays the authority's bytes and reads no disk of its own. + const Read = struct { + fn source(ctx: *const hunks.Ctx, from: []const u8, name: []const u8) ?hunks.Source { + const pp: *Pardes = @ptrCast(@alignCast(ctx.host)); + const text = locations.sourceText(pp, ctx.arena, from, name) orelse return null; + return .{ .path = text.path, .bytes = text.bytes }; + } + fn declarations(ctx: *const hunks.Ctx, name: []const u8, bytes: []const u8) error{OutOfMemory}![]const @import("syntax.zig").ContextDeclaration { + const pp: *Pardes = @ptrCast(@alignCast(ctx.host)); + var hit = pp.locations_cache.get(pp.tree_sitter_gpa, name, bytes, true, false) catch + locations.Cache.Hit{ .analysis = @import("syntax.zig").analyzeSource(ctx.arena, name, bytes, true, false) catch .{} }; + defer hit.deinit(pp.tree_sitter_gpa); + // The cache's may go at its next use: kept for the call. + return ctx.arena.dupe(@import("syntax.zig").ContextDeclaration, hit.analysis.declarations); + } + }; + const ctx: hunks.Ctx = .{ + .gpa = p.gpa, + .arena = p.scratch.allocator(), + .source = Read.source, + .declarations = Read.declarations, + .host = p, + .tslocations = p.locations_config.tslocations, + }; + const root = hunks.sourceRoot(&ctx, dir, content); + const result = try hunks.format(&ctx, root, content); errdefer { p.gpa.free(result.content); locations.freeRows(p.gpa, result.rows); -- cgit v1.3