summaryrefslogtreecommitdiff
path: root/src/pardes.zig
diff options
context:
space:
mode:
Diffstat (limited to 'src/pardes.zig')
-rw-r--r--src/pardes.zig42
1 files changed, 37 insertions, 5 deletions
diff --git a/src/pardes.zig b/src/pardes.zig
index aaa9d177..c2a3ba21 100644
--- a/src/pardes.zig
+++ b/src/pardes.zig
@@ -478,6 +478,7 @@ pub const Loc = struct {
};
test {
+ _ = @import("modal.zig");
_ = @import("tagline.zig");
_ = @import("hunks.zig");
_ = @import("builtins_json.zig");
@@ -4645,6 +4646,10 @@ pub const Pardes = struct {
/// The last query asked (Lspwhy explains it): its kind, argument, and
/// the pane and place it was asked at.
lsp_last: ?struct { kind: lsp.Kind, arg: Effect.Buf(128), serial: u32, offset: u32 } = null,
+ /// The Callstack page `+Callstack` shows stopped short: its file's pane,
+ /// the place it was asked at, and the direct caller the next page starts
+ /// at. Callstack run in `+Callstack` asks for it.
+ callstack_more: ?struct { serial: u32, offset: u32, next: Effect.Buf(128) } = null,
lsp_wait: ?struct {
id: u32,
kind: lsp.Kind,
@@ -5168,10 +5173,13 @@ pub const Pardes = struct {
}
fn reapPanes(p: *Pardes) void {
+ var reaped = false;
for (&p.retired_panes.previous) |*slot| if (slot.*) |pane| {
p.teardownPane(pane);
slot.* = null;
+ reaped = true;
};
+ if (reaped) memory.trim();
p.retired_panes.previous = p.retired_panes.current;
p.retired_panes.current = @splat(null);
}
@@ -5544,7 +5552,7 @@ pub const Pardes = struct {
p.invalidate();
look.invalidateLookHover(p, id);
const applied = p.applyWatchedFileChanged(id, bytes);
- _ = p.scratch.reset(.retain_capacity);
+ _ = p.scratch.reset(.{ .retain_with_limit = memory.limits.scratch_kept });
p.sync();
return applied;
}
@@ -6000,7 +6008,7 @@ pub const Pardes = struct {
// A pty streaming into an unwatched session spent most of its time
// drawing what nobody looked at.
if (v.watched) |f| if (!f(h.ctx)) return;
- _ = p.frame_arena.reset(.retain_capacity);
+ _ = p.frame_arena.reset(.{ .retain_with_limit = memory.limits.frame_kept });
const surface = try p.render(p.frame_arena.allocator());
if (v.present) |f| f(h.ctx, surface);
// Settled before post_present: a shell ticks there, and what that
@@ -6202,7 +6210,7 @@ pub const Pardes = struct {
look.advanceLookHover(p);
},
}
- _ = p.scratch.reset(.retain_capacity);
+ _ = p.scratch.reset(.{ .retain_with_limit = memory.limits.scratch_kept });
p.sync();
p.fsReport();
ctlfs.events.announce(p);
@@ -6777,6 +6785,19 @@ pub const Pardes = struct {
pub const SavePath = Effect.Buf(effect_path_cap);
pub fn lspRequest(p: *Pardes, asked: usize, kind: lsp.Kind, arg_in: []const u8) void {
+ p.lspRequestAt(asked, kind, arg_in, null);
+ }
+
+ /// The next page of the Callstack `+Callstack` shows, asked where the
+ /// first was.
+ pub fn callstackMore(p: *Pardes, from: usize) void {
+ const more = p.callstack_more orelse return p.reportFailure(from, "Callstack: this is the last page; run it in a file to start again");
+ const id = p.paneBySerial(more.serial) orelse return p.reportFailure(from, "Callstack: the file it was asked in is closed");
+ p.lspRequestAt(id, .callstack, more.next.slice(), more.offset);
+ }
+
+ /// `lspRequest` at byte `at` of the pane's file rather than its cursor.
+ fn lspRequestAt(p: *Pardes, asked: usize, kind: lsp.Kind, arg_in: []const u8, at_byte: ?u32) void {
var arg = arg_in;
if (!normal.multiOnce(p)) return; // one question per keystroke, from the primary
// Lspwhy narrates the last query where it was asked -- that pane's
@@ -6800,7 +6821,7 @@ pub const Pardes = struct {
(!zig_buf and std.mem.indexOfAny(u8, arg, " \t\r\n\"\\") != null))
return p.reportFailure(id, std.fmt.bufPrint(&said, "Rename: {s} is no name", .{arg}) catch "Rename: no name");
}
- var off = if (pane.file) |f| modal.offsetAt(f.content, .{
+ var off = if (at_byte) |at| @min(at, if (pane.file) |f| f.content.len else 0) else if (pane.file) |f| modal.offsetAt(f.content, .{
.row = @intCast(@max(0, pane.body.cur_row)),
.col = @intCast(@max(0, pane.body.cur_col)),
}) else 0;
@@ -7089,13 +7110,24 @@ pub const Pardes = struct {
}
const dir = if (pane.file) |f| panes.Dir.ofName(f.path) else pane.cwdSlice();
- const content = p.gpa.dupe(u8, rows) catch return;
+ // A Callstack page that stops short ends in its marker: said as a
+ // row naming the word that shows the next page, and kept.
+ if (w.kind == .callstack) p.callstack_more = null;
+ const marker = if (w.kind == .callstack) std.mem.lastIndexOf(u8, rows, lsp.callstack_more) else null;
+ const content = if (marker) |at| more: {
+ var fields = std.mem.tokenizeAny(u8, rows[at + lsp.callstack_more.len ..], " \n");
+ const next = fields.next() orelse "";
+ const shown = fields.next() orelse "?";
+ if (p.lsp_last) |last| p.callstack_more = .{ .serial = w.serial, .offset = last.offset, .next = .from(next) };
+ break :more std.fmt.allocPrint(p.gpa, "{s}… {s} callers on this page, more after them: Callstack here shows the next page\n", .{ rows[0..at], shown }) catch return;
+ } else p.gpa.dupe(u8, rows) catch return;
const serial_before = p.next_serial;
p.fs.refilled = null;
panes.Output.fillResults(p, w.pane, dir, from, w.arg.slice(), content, null) catch |err| {
p.reportError(w.pane, "language response", err);
return;
};
+ if (rows.len >= 1 << 20) memory.trim();
// What a 9P write that asked it answers: the pane the rows are in
// (a multi-file Rename's preview, Lspinfo's +Lsp), made or filled
// again, not the pane it was asked from.