summaryrefslogtreecommitdiff
path: root/src/Output.zig
diff options
context:
space:
mode:
Diffstat (limited to 'src/Output.zig')
-rw-r--r--src/Output.zig29
1 files changed, 27 insertions, 2 deletions
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);