diff options
| author | Gabriel Schneider <[email protected]> | 2026-11-05 10:48:36 -0300 |
|---|---|---|
| committer | Gabriel Schneider <[email protected]> | 2026-11-05 10:57:08 -0300 |
| commit | fc02325789b5a6622f9e577c9a45e65806c516b6 (patch) | |
| tree | 65fdeed6959aef6afe0db5d18df3649aef0d2a34 /src/locations.zig | |
| parent | 856bf4a8ed36cc6ec38dc9001f753a8838106da2 (diff) | |
| download | pardes-fc02325789b5a6622f9e577c9a45e65806c516b6.tar.gz pardes-fc02325789b5a6622f9e577c9a45e65806c516b6.zip | |
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 <[email protected]>
Claude-Session: https://claude.ai/code/session_016Y9MNAtZenFv4weoMD3cge
Diffstat (limited to 'src/locations.zig')
| -rw-r--r-- | src/locations.zig | 45 |
1 files changed, 16 insertions, 29 deletions
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; |
