summaryrefslogtreecommitdiff
path: root/src/Output.zig
diff options
context:
space:
mode:
Diffstat (limited to 'src/Output.zig')
-rw-r--r--src/Output.zig84
1 files changed, 0 insertions, 84 deletions
diff --git a/src/Output.zig b/src/Output.zig
index 3bcc3fa5..2e49ceb3 100644
--- a/src/Output.zig
+++ b/src/Output.zig
@@ -14,8 +14,6 @@ const lsp = @import("lsp/lsp.zig");
const look = @import("look.zig");
const locations = @import("locations.zig");
const layout = @import("layout.zig");
-const hunks = @import("hunks.zig");
-const diff = @import("diff.zig");
const Pane = panes.Pane;
const File = panes.File;
@@ -486,88 +484,6 @@ pub fn fillRows(p: *Pardes, id: usize, dir: []const u8, from: Origin, name: ?[]c
return free;
}
-/// Diff: `content`, the diff at `path` (a file, a +Pager), stacked as a
-/// diff viewer shows it (hunks.zig), in a +Diff where its files are found
-/// (hunks.sourceRoot), placed by pane `id`, refilled when it is there. Its
-/// arg names the diff (its base name, or its whole path when the +Diff
-/// stands elsewhere), for Diff to go back to it; a commit's (`git show`, a
-/// mailed patch) is named for it too, `+Diff-<12 hex>`, so each commit
-/// keeps a +Diff of its own. The +Diff's id; 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();
- // 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);
- }
- var has_hunk = false;
- for (result.rows) |row| has_hunk = has_hunk or row.kind == .match;
- if (!has_hunk) return error.NoHunks;
- const arg = if (std.mem.eql(u8, root, dir) or path.len > max_arg) std.Io.Dir.path.basename(path) else path;
- var name_buf: [config.diff_buffer.len + 13]u8 = undefined;
- const name = if (diff.commitHash(content)) |hash|
- std.fmt.bufPrint(&name_buf, "{s}-{s}", .{ config.diff_buffer, hash[0..@min(hash.len, 12)] }) catch unreachable
- else
- null;
- return fillRows(p, id, root, .{ .cmd = .Diff }, name, arg, result.content, result.rows, null);
-}
-
-/// Diff on a +Diff: the diff it stacks, as text. A pane holding it
-/// already (the newest: a +Pager folded under its +Diff unfolds) is
-/// shown; else the file is opened as text.
-pub fn showDiffText(p: *Pardes, id: usize, source: []const u8) void {
- var newest: ?usize = null;
- for (p.panes, 0..) |slot, i| {
- const f = (slot orelse continue).file orelse continue;
- if (!std.mem.eql(u8, f.path, source)) continue;
- if (newest == null or p.panes[newest.?].?.serial < slot.?.serial) newest = i;
- }
- if (newest) |i| {
- if (p.panes[i].?.collapsed) layout.toggleCollapse(p, i);
- p.view().active = i;
- return;
- }
- p.look_text = true;
- defer p.look_text = false;
- look.lookAt(p, id, source);
-}
-
-/// The diff a +Diff stacks (openDiff's arg): its path.
-pub fn diffSource(p: *Pardes, f: *const File.State) ?[]const u8 {
- const o = f.output orelse return null;
- if (!std.meta.eql(o.from, Origin{ .cmd = .Diff })) return null;
- const arg = o.arg();
- if (arg.len > 0 and arg[0] == '/') return arg;
- return std.Io.Dir.path.join(p.scratch.allocator(), &.{ std.Io.Dir.path.dirname(f.path) orelse "", arg }) catch null;
-}
-
pub fn openJumps(p: *Pardes, id: usize) !void {
var out: std.Io.Writer.Allocating = .init(p.gpa);
errdefer out.deinit();