From fc02325789b5a6622f9e577c9a45e65806c516b6 Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Thu, 5 Nov 2026 10:48:36 -0300 Subject: Callstack a plain tree with a depth: CallstackLayout and CallstackCorners go with the inline layout and the square corners (each snippet below its location, the corners rounded, as both defaulted to), and the 100,000-row paging goes: a tree bigger than one answer holds stops there, its last row saying so as at the memory limit, and Callstack run in +Callstack asks nothing (only a file's pane asks a language server) where it showed the next page (lsp.callstack_more, the core's callstack_more, callstackMore and lspRequestAt, the walk's start and cut paths); CallstackDepth stays, as the reference documents it and the user's init sets it; treePrefix reads only the glyphs the tree draws, and the tests that fed it others take the drawn ones; callstack-inline.snap goes with its layout and callstack.snap snaps its style in its stead (its golden gains that section, the text byte-identical); the reference, the guide, the changelog's entry and both builtins lists say so Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_016Y9MNAtZenFv4weoMD3cge --- src/CHANGELOG.md | 6 ++-- src/Output.zig | 4 +-- src/builtins.zig | 3 -- src/config.zig | 25 +++++----------- src/host_io.zig | 6 ---- src/locations.zig | 45 ++++++++++------------------ src/lsp/lsp.zig | 6 ---- src/lsp/lsp_client.zig | 81 ++++++++++++-------------------------------------- src/pardes.zig | 33 ++------------------ 9 files changed, 50 insertions(+), 159 deletions(-) (limited to 'src') diff --git a/src/CHANGELOG.md b/src/CHANGELOG.md index a3ee88c3..7a3f41b3 100644 --- a/src/CHANGELOG.md +++ b/src/CHANGELOG.md @@ -119,10 +119,8 @@ outermost callers first, tree-sitter signatures, depth guides and clickable call sites. `gc` replaces the old move-to-viewport-center binding. CallstackDepth sets the caller depth at runtime (1–64, default 8). - CallstackLayout stacked is the default, aligning snippets below their - locations with rounded tree corners; inline - keeps them beside the locations. CallstackCorners square restores sharp - tree corners; rounded remains the default. + Snippets sit below their locations, the tree's corners rounded; a tree + bigger than one answer holds (about 100,000 rows) stops there and says so. Signatures use syntax colors; only calls to the queried function get background emphasis, and tree guides continue through multiline signatures and wrapped rows. Cross-directory call locations use shorter relative paths. diff --git a/src/Output.zig b/src/Output.zig index bc61dc11..abdf2664 100644 --- a/src/Output.zig +++ b/src/Output.zig @@ -145,8 +145,8 @@ pub fn decorateRow(output: ?State, line: []const u8, metadata: ?locations.Row) R test "callstack guides and Look locations share result decoration" { const from: State = .{ .from = .{ .query = .callstack } }; - const loc = decorateRow(from, "└──┬ lib.rs:2:8-10 fn add() {", null); - try std.testing.expectEqual(@as(usize, "└──┬ lib.rs:2:8-10".len), loc.location_end); + const loc = decorateRow(from, "╰──┬ lib.rs:2:8-10 fn add() {", null); + try std.testing.expectEqual(@as(usize, "╰──┬ lib.rs:2:8-10".len), loc.location_end); try std.testing.expect(!loc.declaration); try std.testing.expect(!usesLocationsConfig(from.from)); try std.testing.expect(!traits(from.from).jumps); diff --git a/src/builtins.zig b/src/builtins.zig index 750000ba..c2be41a8 100644 --- a/src/builtins.zig +++ b/src/builtins.zig @@ -1973,9 +1973,6 @@ pub const WsDiagnostics = struct { /// Show outermost callers first, with signatures and call sites (gc). pub const Callstack = struct { pub fn run(c: Ctx) void { - // In +Callstack itself: the next page of what it shows. - if (c.pane.file) |f| if (f.output) |o| if (std.meta.eql(o.from, panes.Output.Origin{ .query = .callstack })) - return c.p.callstackMore(c.id); c.p.lspRequest(c.id, .callstack, ""); } }; diff --git a/src/config.zig b/src/config.zig index 2542f99d..641ff463 100644 --- a/src/config.zig +++ b/src/config.zig @@ -90,8 +90,6 @@ pub const leader_path = paths: { .Incl = null, .Tab = null, .CallstackDepth = null, - .CallstackLayout = null, - .CallstackCorners = null, .Zerox = null, .ClipYank = "y", .ClipYankMain = "Y", @@ -861,8 +859,6 @@ pub const Runtime = struct { /// acme's Tab: a tab's width in cells, in every pane (config.tab_now /// is what the drawing and the column arithmetic read). tab: u16 = tab_width, - callstack_layout: CallstackLayout = .stacked, - callstack_corners: CallstackCorners = .rounded, callstack_depth: u8 = @import("lsp/lsp.zig").callstack_default_depth, /// Where a query pane goes (Query.zig): `attached`, under the pane that /// asked, out of its rows alone; `column`, in the finder column. @@ -878,12 +874,10 @@ pub const Runtime = struct { pub const Pager = enum { pardes, off }; pub const TermImages = enum { real, petscii }; pub const JumpScope = enum { file, all }; - pub const CallstackLayout = enum { @"inline", stacked }; - pub const CallstackCorners = @import("lsp/lsp.zig").CallstackCorners; pub const SearchPlace = enum { attached, column }; pub const SearchPane = enum { reuse, new }; /// A setting that is one of a few words, each an enum field of Runtime. - pub const Choice = enum { pager, term_images, jump_scope, callstack_layout, callstack_corners, search_place, search_pane }; + pub const Choice = enum { pager, term_images, jump_scope, search_place, search_pane }; /// shadow: a soft drop shadow. rim: a light hairline along the top of /// the focused pane's tag rows. auto: a shadow on a light page; on a @@ -1167,8 +1161,6 @@ pub const Runtime = struct { .{ .word = "PagerColor", .action = .{ .toggle = .pager_color }, .doc = "A +Pager keeps its program's colours, on or off; for the next text paged." }, .{ .word = "TermImages", .action = .{ .choice = .term_images }, .doc = "How a new terminal draws its program's kitty graphics: real, as pixels where it can, or petscii, as glyph art." }, .{ .word = "JumpScope", .action = .{ .choice = .jump_scope }, .doc = "What Back and Forward keep to: file, the focused pane's file until it runs out that way, or all, every place in order." }, - .{ .word = "CallstackLayout", .action = .{ .choice = .callstack_layout }, .doc = "Callstack snippets below their locations (stacked, the default) or beside them (inline); bare, it switches layouts. Applies to the next Callstack query." }, - .{ .word = "CallstackCorners", .action = .{ .choice = .callstack_corners }, .doc = "Callstack tree corners: rounded (the default) or square; bare, it switches styles. Applies to the next Callstack query." }, .{ .word = "CallstackDepth", .action = .callstack_depth, .doc = "Caller levels collected by Callstack, 1 through 64; default 8. Bare, it says the current limit." }, .{ .word = "Tab", .action = .tab, .doc = "A tab's width in cells, 1 through 16, in every pane; bare, it says the width." }, .{ .word = "SearchPlace", .action = .{ .choice = .search_place }, .doc = "Where a query pane goes: attached, under the pane that asked, out of its rows alone, or column, in the finder column." }, @@ -1762,14 +1754,13 @@ pub const Runtime = struct { .state = &state, }; const values = [_][2][]const u8{ - .{ "TaglineSize", "73" }, .{ "WindowOpacity", "85" }, .{ "WindowBlur", "40" }, - .{ "MessageLinger", "1500" }, .{ "MessageFall", "1500" }, .{ "MessageDissolve", "1500" }, - .{ "DumpDir", "~/dumps" }, .{ "Crt", "3" }, .{ "Shader", "~/crt.glsl" }, - .{ "ShaderAnimation", "always" }, .{ "TermImages", "petscii" }, .{ "JumpScope", "all" }, - .{ "CallstackLayout", "inline" }, .{ "CallstackCorners", "square" }, .{ "SearchPlace", "column" }, - .{ "SearchPane", "new" }, .{ "Lift", "rim" }, .{ "Motion", "playful" }, - .{ "InactiveDim", "35" }, .{ "GripWidth", "200" }, .{ "CallstackDepth", "16" }, - .{ "Tab", "8" }, .{ "SearchRows", "12" }, + .{ "TaglineSize", "73" }, .{ "WindowOpacity", "85" }, .{ "WindowBlur", "40" }, + .{ "MessageLinger", "1500" }, .{ "MessageFall", "1500" }, .{ "MessageDissolve", "1500" }, + .{ "DumpDir", "~/dumps" }, .{ "Crt", "3" }, .{ "Shader", "~/crt.glsl" }, + .{ "ShaderAnimation", "always" }, .{ "TermImages", "petscii" }, .{ "JumpScope", "all" }, + .{ "SearchPlace", "column" }, .{ "SearchPane", "new" }, .{ "Lift", "rim" }, + .{ "Motion", "playful" }, .{ "InactiveDim", "35" }, .{ "GripWidth", "200" }, + .{ "CallstackDepth", "16" }, .{ "Tab", "8" }, .{ "SearchRows", "12" }, }; for (values) |v| try std.testing.expect(apply(&state, find(v[0]).?, v[1])); try std.testing.expect(state.font.requested_name.set("Wanted Mono")); diff --git a/src/host_io.zig b/src/host_io.zig index ad7c77dd..a04bf7ce 100644 --- a/src/host_io.zig +++ b/src/host_io.zig @@ -617,7 +617,6 @@ pub const Lsp = struct { /// One language query, owned by the worker that runs it. pub const Job = struct { callstack_depth: u8 = pardes.lsp.callstack_default_depth, - callstack_corners: pardes.lsp.CallstackCorners = .rounded, id: u32, kind: pardes.lsp.Kind, offset: u32, @@ -661,7 +660,6 @@ pub const Lsp = struct { errdefer gpa.free(root); job.* = .{ .callstack_depth = core.settings.callstack_depth, - .callstack_corners = core.settings.callstack_corners, .id = req.id, .kind = req.kind, .offset = req.offset, @@ -748,7 +746,6 @@ pub const Lsp = struct { .root = job.root, .others = job.others, .callstack_depth = job.callstack_depth, - .callstack_corners = job.callstack_corners, .budget = &arena, }, &out.writer) catch { deliver(ctx, job.id, null); @@ -767,7 +764,6 @@ pub const Lsp = struct { defer core.deinit(); core.settings.callstack_depth = 16; - core.settings.callstack_corners = .square; var needle: [6]u8 = "needle".*; const job = try snapshot(gpa, core, .{ .id = 7, @@ -779,8 +775,6 @@ pub const Lsp = struct { defer job.free(gpa); core.settings.callstack_depth = 2; - core.settings.callstack_corners = .rounded; - try std.testing.expectEqual(pardes.lsp.CallstackCorners.square, job.callstack_corners); try std.testing.expectEqual(@as(u8, 16), job.callstack_depth); try std.testing.expectEqual(@as(u32, 7), job.id); try std.testing.expectEqual(pardes.lsp.Kind.status, job.kind); diff --git a/src/locations.zig b/src/locations.zig index 889a45a0..e8c31bf0 100644 --- a/src/locations.zig +++ b/src/locations.zig @@ -243,11 +243,11 @@ pub fn sourceText(p: *pardes.Pardes, arena: std.mem.Allocator, dir: []const u8, pub fn treePrefix(line: []const u8) struct { end: usize, branch: bool } { var at: usize = 0; while (at < line.len) { - for ([_][]const u8{ "╰──┬ ", "├──╮ ", "╰──╮ ", "├─── ", "╰─── ", "├──┬ ", "└──┬ ", "└─── " }) |branch| { + for ([_][]const u8{ "├──┬ ", "╰──┬ ", "├─── ", "╰─── " }) |branch| { if (std.mem.startsWith(u8, line[at..], branch)) return .{ .end = at + branch.len, .branch = true }; } - if (std.mem.startsWith(u8, line[at..], "├─ ") or std.mem.startsWith(u8, line[at..], "└─ ") or std.mem.startsWith(u8, line[at..], "╰─ ")) - return .{ .end = at + "└─ ".len, .branch = false }; + if (std.mem.startsWith(u8, line[at..], "├─ ") or std.mem.startsWith(u8, line[at..], "╰─ ")) + return .{ .end = at + "╰─ ".len, .branch = false }; if (std.mem.startsWith(u8, line[at..], "│")) { at += "│".len; } else if (line[at] == ' ') { @@ -267,7 +267,7 @@ pub fn treeContinuation(line: []const u8, buffer: []u8, max_cells: usize) []cons var end: usize = 0; while (it.nextCodepoint()) |cp| { if (cells >= max_cells) break; - out.writeAll(if (cp == '│' or cp == '├' or cp == '┬' or cp == '╮') "│" else " ") catch break; + out.writeAll(if (cp == '│' or cp == '├' or cp == '┬') "│" else " ") catch break; cells += 1; if (cp != ' ') end = out.buffered().len; } @@ -280,7 +280,7 @@ pub fn treeContinuation(line: []const u8, buffer: []u8, max_cells: usize) []cons const Resolved = struct { code: []const u8 = "", colors: []const u8 = &.{}, source_row: usize = 0 }; /// Each Callstack row's code (its call site's line, or a caller's header) and -/// colors, by input line. A page spans thousands of files, so they are taken +/// colors, by input line. A tree spans thousands of files, so they are taken /// a file at a time: grouped by path, each file read, line-indexed and /// analyzed once, its rows' code and colors copied out, and the file let go /// before the next. Row by row, the cache compared the whole source each @@ -377,7 +377,6 @@ pub fn formatCallstack(p: *pardes.Pardes, dir: []const u8, input: []const u8) !R errdefer out.deinit(); var rows: std.ArrayList(Row) = .empty; errdefer freeRowList(p.gpa, &rows); - const stacked = p.settings.callstack_layout == .stacked; const resolved = try resolveCallstack(p, arena, dir, input); var lines = std.mem.splitScalar(u8, std.mem.trimEnd(u8, input, "\n"), '\n'); var index: usize = 0; @@ -397,33 +396,21 @@ pub fn formatCallstack(p: *pardes.Pardes, dir: []const u8, input: []const u8) !R var source_row = resolved[index].source_row; const recursion = prefix.branch and std.mem.endsWith(u8, line, " ↻ recursion"); const first_line = code[0 .. std.mem.indexOfScalar(u8, code, '\n') orelse code.len]; - const source_indent = if (stacked) first_line.len - std.mem.trimStart(u8, first_line, " \t").len else 0; - if (stacked) { - const end = prefix.end + target.end; - try out.writer.print("{s}\n", .{line[0..end]}); - try appendMetadata(p.gpa, &rows, .{ .path = target.path, .at = target.at, .label = "", .code = "", .original = null, .mark_occurrence = false }, .match, end, end, false); - } + const source_indent = first_line.len - std.mem.trimStart(u8, first_line, " \t").len; + // The location on a row of its own, its code below it, aligned with it. + const end = prefix.end + target.end; + try out.writer.print("{s}\n", .{line[0..end]}); + try appendMetadata(p.gpa, &rows, .{ .path = target.path, .at = target.at, .label = "", .code = "", .original = null, .mark_occurrence = false }, .match, end, end, false); var header_lines = std.mem.splitScalar(u8, code, '\n'); var first = true; var color_offset: usize = 0; while (header_lines.next()) |code_line| { const start = out.written().len; - if (stacked) { - var guide_buf: [1024]u8 = undefined; - const guide = treeContinuation(line, &guide_buf, std.math.maxInt(usize)); - try out.writer.writeAll(guide); - const width = pardes.panes.File.displayWidth(line[0..prefix.end]); - try out.writer.splatByteAll(' ', width -| pardes.panes.File.displayWidth(guide)); - } else if (first) { - try out.writer.writeAll(line[0 .. prefix.end + target.end]); - try out.writer.writeByte(' '); - } else { - const branch_start = prefix.end - "└──┬ ".len; - try out.writer.writeAll(line[0..branch_start]); - try out.writer.writeAll(if (std.mem.startsWith(u8, line[branch_start..], "├")) "│ " else " "); - try out.writer.writeAll(if (std.mem.endsWith(u8, line[0..prefix.end], "┬ ") or std.mem.endsWith(u8, line[0..prefix.end], "╮ ")) "│ " else " "); - try out.writer.splatByteAll(' ', pardes.panes.File.displayWidth(line[prefix.end..][0..target.end]) + 1); - } + var guide_buf: [1024]u8 = undefined; + const guide = treeContinuation(line, &guide_buf, std.math.maxInt(usize)); + try out.writer.writeAll(guide); + const width = pardes.panes.File.displayWidth(line[0..prefix.end]); + try out.writer.splatByteAll(' ', width -| pardes.panes.File.displayWidth(guide)); const code_start = out.written().len - start; const trim = @min(source_indent, code_line.len - std.mem.trimStart(u8, code_line, " \t").len); try out.writer.writeAll(code_line[trim..]); @@ -439,7 +426,7 @@ pub fn formatCallstack(p: *pardes.Pardes, dir: []const u8, input: []const u8) !R .original = null, .mark_occurrence = focus and !prefix.branch, .colors = if (colors.len >= color_offset + code_line.len) colors[color_offset + trim ..][0 .. code_line.len - trim] else &.{}, - }, if (first) (if (stacked) .preview else .match) else .context, if (first and !stacked) prefix.end + target.end else 0, code_start, true); + }, if (first) .preview else .context, 0, code_start, true); // Recursion notes are prose, outside the source snapshot. if (recursion_note) { const added = " ↻ recursion".len; diff --git a/src/lsp/lsp.zig b/src/lsp/lsp.zig index 2781077a..190c05f8 100644 --- a/src/lsp/lsp.zig +++ b/src/lsp/lsp.zig @@ -26,17 +26,11 @@ pub const Kind = enum { }; pub const callstack_match = "@callstack-match "; -/// The last row of a Callstack page that stopped full: ` `, -/// the entry indices from the top the next page starts at (`3.0.17`), and -/// how many callers this page holds. -pub const callstack_more = "@callstack-more "; -pub const CallstackCorners = enum { rounded, square }; pub const callstack_default_depth: u8 = 8; pub const callstack_max_depth: u8 = 64; pub const Req = struct { callstack_depth: u8 = callstack_default_depth, - callstack_corners: CallstackCorners = .rounded, kind: Kind, path: []const u8, source: [:0]const u8, diff --git a/src/lsp/lsp_client.zig b/src/lsp/lsp_client.zig index f2c186a8..40c287b0 100644 --- a/src/lsp/lsp_client.zig +++ b/src/lsp/lsp_client.zig @@ -545,7 +545,7 @@ fn run(c: *Conn, io: std.Io, si: usize, arena: std.mem.Allocator, req: lsp.Req, }; const pos = posOf(req.source, req.offset, c.caps.enc); - var cx: Cx = .{ .arena = arena, .base = req.root, .cur_path = req.path, .cur_src = req.source, .out = out, .fixed_out = true, .relative_parents = req.kind == .callstack, .callstack_corners = req.callstack_corners }; + var cx: Cx = .{ .arena = arena, .base = req.root, .cur_path = req.path, .cur_src = req.source, .out = out, .fixed_out = true, .relative_parents = req.kind == .callstack }; for (req.others) |doc| try cx.files.append(arena, .{ .path = doc.path, .text = doc.source }); tr.note("server {s} (pid {d}), root {s}, {s} columns", .{ @tagName(c.state), c.pid, c.root, @tagName(c.caps.enc), @@ -659,7 +659,7 @@ fn run(c: *Conn, io: std.Io, si: usize, arena: std.mem.Allocator, req: lsp.Req, n += 1; } }, - .callstack => try callstack(c, io, si, arena, &cx, uri.items, pos, deadline, tr, req.callstack_depth, req.budget, req.arg), + .callstack => try callstack(c, io, si, arena, &cx, uri.items, pos, deadline, tr, req.callstack_depth, req.budget), .incoming_calls => try hierarchy(c, io, si, arena, &cx, uri.items, pos, deadline, .incoming, tr), .outgoing_calls => try hierarchy(c, io, si, arena, &cx, uri.items, pos, deadline, .outgoing, tr), .supertypes => try hierarchy(c, io, si, arena, &cx, uri.items, pos, deadline, .supers, tr), @@ -914,17 +914,8 @@ const CallTree = struct { narrated: bool = false, siblings: [lsp.callstack_max_depth]bool = @splat(false), rendered: usize = 0, - /// Paging. A page starts at `start`, a path of entry indices from the - /// top (empty: the start), skipping what is before it at each level; - /// `rows` and `bytes` count what rendering takes, and the walk stops - /// before their caps at `cut`, which the next page starts at (`more`). - /// The ancestors on the path are shown again on it, as context. - start: [lsp.callstack_max_depth]u32 = undefined, - start_len: usize = 0, - at: [lsp.callstack_max_depth]u32 = undefined, - cut: [lsp.callstack_max_depth]u32 = undefined, - cut_len: usize = 0, - more: bool = false, + /// The rows rendering the tree takes: the walk stops before `row_cap`, + /// as at the memory limit (`out_of_memory`). rows: usize = 0, row_cap: usize = max_rows - 16, /// The bytes those rows take, over-estimated (the uri for the path it @@ -1013,7 +1004,7 @@ fn validCaller(entry: std.json.Value) bool { rangeOf(get(from, "selectionRange") orelse get(from, "range")) != null; } -fn callstack(c: *Conn, io: std.Io, si: usize, arena: std.mem.Allocator, cx: *Cx, uri: []const u8, pos: Pos, deadline: i64, tr: *Trace, max_depth: u8, budget: ?*const std.heap.FixedBufferAllocator, arg: []const u8) Err!void { +fn callstack(c: *Conn, io: std.Io, si: usize, arena: std.mem.Allocator, cx: *Cx, uri: []const u8, pos: Pos, deadline: i64, tr: *Trace, max_depth: u8, budget: ?*const std.heap.FixedBufferAllocator) Err!void { if (!c.caps.call_hier) return lsp.none(cx.out, "{s} does not answer call hierarchy (no callHierarchyProvider)", .{specs[si].name}); const b = try atPos(arena, uri, pos); const prepared = (try call(c, io, arena, "textDocument/prepareCallHierarchy", b.items, deadline)) orelse return; @@ -1035,25 +1026,15 @@ fn callstack(c: *Conn, io: std.Io, si: usize, arena: std.mem.Allocator, cx: *Cx, .si = si, .started_ms = nowMs(), .budget = budget, - // The page ends while the answer's writer has room for the rest. + // The walk stops while the answer's writer has room for the rest. .byte_cap = if (cx.fixed_out) (cx.out.buffer.len - cx.out.end) -| (1 << 20) else std.math.maxInt(usize), }; - var steps = std.mem.tokenizeScalar(u8, std.mem.trim(u8, arg, " \n"), '.'); - while (steps.next()) |step| { - if (tree.start_len == tree.start.len) break; - tree.start[tree.start_len] = std.fmt.parseInt(u32, step, 10) catch break; - tree.start_len += 1; - } const incoming = try hierarchyResult(c, io, parse, item, "callHierarchy/incomingCalls", deadline); - const count = try collectCallers(c, io, arena, if (budget != null) &parse_fba else null, item, incoming, &tree, 0, tree.start_len > 0); + const count = try collectCallers(c, io, arena, if (budget != null) &parse_fba else null, item, incoming, &tree, 0); if (tree.narrated) post(si, .always, "Callstack: {d} callers", .{tree.collected}); - if (count == 0 and tree.start_len == 0) try cx.out.writeAll("No callers reported\n"); + if (count == 0) try cx.out.writeAll("No callers reported\n"); try renderCallers(cx, c.caps.enc, &tree, tree.roots.items, 0); - if (tree.more) { - try cx.out.writeAll(lsp.callstack_more); - for (tree.cut[0..tree.cut_len], 0..) |index, level| try cx.out.print("{s}{d}", .{ if (level == 0) "" else ".", index }); - try cx.out.print(" {d}\n", .{tree.collected}); - } else if (tree.out_of_time) { + if (tree.out_of_time) { try cx.out.writeAll("… the language server ran out of time; continue from a function above with Callstack\n"); } else if (tree.out_of_memory) { try cx.out.writeAll("… stopped at the query's memory limit; continue from a function above with Callstack\n"); @@ -1064,28 +1045,16 @@ fn callstack(c: *Conn, io: std.Io, si: usize, arena: std.mem.Allocator, cx: *Cx, /// No caller count and no overall deadline: the walk narrates itself on the /// message row after a second, and it stops when a request goes unanswered -/// (what was collected is shown), when the page is full (the rest is the -/// next page), or when the shell cancels it for a newer query. -fn collectCallers(c: *Conn, io: std.Io, arena: std.mem.Allocator, parse: ?*std.heap.FixedBufferAllocator, focus: std.json.Value, incoming: ?std.json.Value, tree: *CallTree, depth: usize, on_path: bool) Err!usize { +/// or the answer is full (what was collected is shown, its last row saying +/// so), or when the shell cancels it for a newer query. +fn collectCallers(c: *Conn, io: std.Io, arena: std.mem.Allocator, parse: ?*std.heap.FixedBufferAllocator, focus: std.json.Value, incoming: ?std.json.Value, tree: *CallTree, depth: usize) Err!usize { var count: usize = 0; - for (items(incoming), 0..) |entry, index| { - // A later page skips what the pages before it walked. - const resuming = on_path and depth < tree.start_len; - if (resuming and index < tree.start[depth]) continue; - tree.at[depth] = @intCast(index); + for (items(incoming)) |entry| { if (tree.budget) |b| if (b.buffer.len - b.end_index < callstack_reserve) { tree.out_of_memory = true; }; - if (!tree.more and (tree.rows >= tree.row_cap or tree.bytes >= tree.byte_cap or tree.out_of_memory)) { - // The page is full: the next goes on here. Never where this - // one began, which would page in place: past that entry. - tree.more = true; - tree.cut_len = depth + 1; - @memcpy(tree.cut[0..tree.cut_len], tree.at[0..tree.cut_len]); - if (tree.cut_len == tree.start_len and std.mem.eql(u32, tree.cut[0..tree.cut_len], tree.start[0..tree.start_len])) - tree.cut[depth] += 1; - } - if (tree.out_of_time or tree.more) break; + if (tree.rows >= tree.row_cap or tree.bytes >= tree.byte_cap) tree.out_of_memory = true; + if (tree.out_of_time or tree.out_of_memory) break; if (!validCaller(entry)) continue; const from = get(entry, "from").?; const cycle = sameItem(focus, from) or for (tree.path[0..depth]) |ancestor| { @@ -1113,15 +1082,14 @@ fn collectCallers(c: *Conn, io: std.Io, arena: std.mem.Allocator, parse: ?*std.h break :blk null; }, // A response bigger than the parse region: this caller - // stops here, the page with it. + // stops here, the walk with it. error.OutOfMemory => blk: { tree.out_of_memory = true; break :blk null; }, else => return e, }; - const deeper = resuming and index == tree.start[depth] and depth + 1 < tree.start_len; - if (!tree.out_of_time and !tree.out_of_memory) children = try collectCallers(c, io, arena, parse, focus, ancestors, tree, depth + 1, deeper); + if (!tree.out_of_time and !tree.out_of_memory) children = try collectCallers(c, io, arena, parse, focus, ancestors, tree, depth + 1); } } if (children == 0) try tree.addPath(arena, tree.path[0 .. depth + 1], cycle); @@ -1162,8 +1130,7 @@ fn renderCallers(cx: *Cx, enc: Enc, tree: *CallTree, children: []usize, depth: u const more = index + 1 < children.len; try callPrefix(cx.out, tree, depth); const has_children = node.children.items.len > 0 or node.ranges.items.len > 0; - const rounded = cx.callstack_corners == .rounded; - try cx.out.writeAll(if (more) "├" else if (rounded) "╰" else "└"); + try cx.out.writeAll(if (more) "├" else "╰"); try cx.out.writeAll(if (has_children) "──┬ " else "─── "); const name = flat(cx.arena, node.call.name); const label = if (node.cycle) try std.fmt.allocPrint(cx.arena, "{s} ↻ recursion", .{name}) else name; @@ -1182,7 +1149,7 @@ fn renderCallers(cx: *Cx, enc: Enc, tree: *CallTree, children: []usize, depth: u } if (site.focus) try cx.out.writeAll(lsp.callstack_match); try callPrefix(cx.out, tree, depth + 1); - try cx.out.writeAll(if (node.children.items.len > 0 or site_index + 1 < node.ranges.items.len) "├─ " else if (rounded) "╰─ " else "└─ "); + try cx.out.writeAll(if (node.children.items.len > 0 or site_index + 1 < node.ranges.items.len) "├─ " else "╰─ "); try emitAt(cx, enc, node.call.uri, site.range, ""); } try renderCallers(cx, enc, tree, node.children.items, depth + 1); @@ -1280,7 +1247,6 @@ const Cx = struct { no_text: bool = false, rows: usize = 0, relative_parents: bool = false, - callstack_corners: lsp.CallstackCorners = .rounded, files: std.ArrayList(struct { path: []const u8, text: []const u8 }) = .empty, fn text(cx: *Cx, path: []const u8) ?[]const u8 { @@ -2576,15 +2542,6 @@ test "caller trees reverse incoming paths and merge shared callers and sites" { try std.testing.expect(std.mem.indexOf(u8, text, "page_left();").? < std.mem.indexOf(u8, text, "page_right();").?); try std.testing.expect(std.mem.indexOf(u8, text, "├──┬ test.c:4:") != null); try std.testing.expect(std.mem.indexOf(u8, text, "╰──┬ test.c:1:") != null); - cx.callstack_corners = .square; - tree.rendered = 0; - const square_start = out.written().len; - try renderCallers(&cx, .utf8, &tree, tree.roots.items, 0); - const square = out.written()[square_start..]; - try std.testing.expect(std.mem.indexOf(u8, square, "├──┬ test.c:4:") != null); - try std.testing.expect(std.mem.indexOf(u8, square, "└──┬ test.c:1:") != null); - try std.testing.expect(std.mem.indexOf(u8, square, "╰") == null); - try std.testing.expect(std.mem.indexOf(u8, square, "╮") == null); var recursive: CallTree = .{}; try recursive.addPath(arena, &.{ entries[0], entries[0] }, true); try std.testing.expect(!recursive.nodes.items[recursive.roots.items[0]].cycle); diff --git a/src/pardes.zig b/src/pardes.zig index 334d66e2..88045147 100644 --- a/src/pardes.zig +++ b/src/pardes.zig @@ -3989,10 +3989,6 @@ 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, @@ -6408,19 +6404,6 @@ 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 @@ -6444,7 +6427,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 (at_byte) |at| @min(at, if (pane.file) |f| f.content.len else 0) else if (pane.file) |f| modal.offsetAt(f.content, .{ + var off = 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; @@ -6760,17 +6743,7 @@ pub const Pardes = struct { return; }; const dir = if (pane.file) |f| panes.Dir.ofName(f.path) else pane.cwdSlice(); - // 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 content = 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| { @@ -8167,7 +8140,7 @@ test "Callstack always opens and focuses its own pane, reusing it for another sy const source = p.panes[0].?; p.lspRequest(0, .callstack, ""); const first = p.lsp_wait orelse return error.NoRequest; - p.lspResponse(first.id, "└──┬ /test.txt:1:4-7 work\n@callstack-match └─ /test.txt:1:4-7 fn work() {}\n"); + p.lspResponse(first.id, "╰──┬ /test.txt:1:4-7 work\n@callstack-match ╰─ /test.txt:1:4-7 fn work() {}\n"); const report = p.panes[p.active].?; try std.testing.expect(report != source); try std.testing.expect(std.mem.endsWith(u8, report.file.?.path, "/+Callstack")); -- cgit v1.3