summaryrefslogtreecommitdiff
path: root/src/Output.zig
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-10-08 12:03:46 -0300
committerGabriel Schneider <[email protected]>2026-10-22 10:03:15 -0300
commit1ecb9b720840ea8e4753823fa8cddcf5d6a3a4d2 (patch)
tree973976c63f560201638d453b4b8b277d9cb40040 /src/Output.zig
parent13d5613b77c62c425c3a124a34c0c2528cc6251f (diff)
downloadpardes-1ecb9b720840ea8e4753823fa8cddcf5d6a3a4d2.tar.gz
pardes-1ecb9b720840ea8e4753823fa8cddcf5d6a3a4d2.zip
Add a readable static Callstack pane and align tagline text
Diffstat (limited to 'src/Output.zig')
-rw-r--r--src/Output.zig79
1 files changed, 62 insertions, 17 deletions
diff --git a/src/Output.zig b/src/Output.zig
index 9e194615..9ed33ebe 100644
--- a/src/Output.zig
+++ b/src/Output.zig
@@ -53,13 +53,14 @@ const RowDecoration = struct {
location_end: usize = 0,
prefix_end: usize = 0,
declaration: bool = false,
+ guide_end: usize = 0,
mark_start: usize = 0,
mark_end: usize = 0,
severity: enum { none, err, warning, info, hint } = .none,
/// Nothing in the row is decorated: most rows of most files.
pub fn plain(row: RowDecoration) bool {
- return !row.declaration and row.location_end == 0 and row.prefix_end == 0 and row.mark_end <= row.mark_start;
+ return row.guide_end == 0 and !row.declaration and row.location_end == 0 and row.prefix_end == 0 and row.mark_end <= row.mark_start;
}
/// `chrome` is the theme's own (Pardes.bodyChrome): body paper changes
@@ -68,6 +69,7 @@ const RowDecoration = struct {
/// working it out takes the contrast searches' pow calls.
pub fn styleAt(row: RowDecoration, chrome: *const pardes.ChromeTheme, byte: usize) ?pardes.CellStyle {
if (row.plain()) return null;
+ if (byte < row.guide_end) return .{ .fg = .{ .rgb = chrome.diagnostic_info } };
if (row.declaration or byte < @max(row.location_end, row.prefix_end))
return .{ .fg = .{ .rgb = chrome.lineno } };
if (byte < row.mark_start or byte >= row.mark_end) return null;
@@ -91,32 +93,38 @@ fn rowDecoration(output: ?State, line: []const u8) RowDecoration {
pub fn decorateRow(output: ?State, line: []const u8, metadata: ?locations.Row) RowDecoration {
const origin = (output orelse return .{}).from;
+ const callstack = std.meta.eql(origin, Origin{ .query = .callstack });
+ const prefix = locations.treePrefix(if (callstack) line else "");
+ const trimmed = line[prefix.end..];
+ const indent = prefix.end;
if (!traits(origin).locations) return .{};
- const target = locations.parse(line);
+ const target = if (callstack) locations.parseRaw(trimmed) else locations.parse(trimmed);
const spot = if (metadata) |m| m.at else target.at;
if (spot.line == 0) return .{};
var row: RowDecoration = .{
- .location_end = if (metadata) |m| m.location_end else target.end,
- .prefix_end = if (metadata) |m| m.code_start else target.end,
+ .guide_end = indent,
+ .location_end = if (metadata) |m| m.location_end else indent + target.end,
+ .prefix_end = if (metadata) |m| m.code_start else indent + target.end,
.declaration = if (metadata) |m| m.declaration else false,
};
- const source_start = if (metadata) |m| m.code_start else target.code_start;
+ const source_start = if (metadata) |m| m.code_start else indent + target.code_start;
if (source_start >= line.len) return row;
if (metadata) |m| if (m.kind == .context) return row;
const mark_occurrence = switch (origin) {
.search => true,
.cmd => |cmd| cmd == .Grep,
.query => |kind| switch (kind) {
- .definition, .declaration, .type_definition, .implementation, .references => true,
+ .definition, .declaration, .type_definition, .implementation, .references, .callstack => true,
else => false,
},
else => false,
};
- if (mark_occurrence and spot.col > 0 and spot.end_line == spot.line and
+ if (mark_occurrence and (if (metadata) |m| m.mark_occurrence else !prefix.branch) and spot.col > 0 and spot.end_line == spot.line and
spot.end_col >= spot.col)
{
- row.mark_start = source_start +| (spot.col - 1);
- row.mark_end = @min(line.len, source_start +| spot.end_col);
+ const source_column = if (metadata) |m| m.source_column else 0;
+ row.mark_start = source_start +| ((spot.col - 1) -| source_column);
+ row.mark_end = @min(line.len, source_start +| (spot.end_col -| source_column));
}
const is_diagnostic = switch (origin) {
.query => |kind| kind == .diagnostics or kind == .workspace_diagnostics,
@@ -135,6 +143,25 @@ pub fn decorateRow(output: ?State, line: []const u8, metadata: ?locations.Row) R
return row;
}
+test "callstack guides and Look locations share result decoration" {
+ const from: State = .{ .from = .{ .query = .callstack } };
+ const loc = rowDecoration(from, "└──┬ lib.rs:2:8-10 fn add() {");
+ 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);
+ const call_line = " lib.rs:12:12-20 return calculate(value);";
+ const call = rowDecoration(from, call_line);
+ try std.testing.expectEqualStrings("calculate", call_line[call.mark_start..call.mark_end]);
+ const reference = rowDecoration(.{ .from = .{ .query = .references } }, call_line[4..]);
+ try std.testing.expectEqual(reference.mark_start + 4, call.mark_start);
+ try std.testing.expectEqual(reference.mark_end + 4, call.mark_end);
+ try std.testing.expectEqual(reference.location_end + 4, call.location_end);
+ const tab_line = " tab.zig:4:9-11 \treturn run();";
+ const tab_call = rowDecoration(from, tab_line);
+ try std.testing.expectEqualStrings("run", tab_line[tab_call.mark_start..tab_call.mark_end]);
+}
+
test "result decoration follows source byte ranges and diagnostic provenance" {
const row = rowDecoration(.{ .from = .search }, "src/a.rs:3:5-7 let abc = 1;");
try std.testing.expectEqualStrings("abc", "src/a.rs:3:5-7 let abc = 1;"[row.mark_start..row.mark_end]);
@@ -237,6 +264,7 @@ pub fn traits(o: Origin) Traits {
.cmd => |b| builtins.registry.outputTraits(b) orelse unreachable,
.query => |k| switch (k) {
.hover => .{ .name = config.hover_buffer },
+ .callstack => .{ .name = "+Callstack", .steps = true, .locations = true },
// prose: an action list, a diff, a report about the backend
.code_action, .format, .status, .explain => .{ .name = config.lsp_buffer },
.rename => .{ .name = config.search_buffer, .steps = true, .locations = true },
@@ -267,7 +295,8 @@ pub fn usesLocationsConfig(from: Origin) bool {
const tr = traits(from);
return tr.steps and !tr.commands and from != .pdf_links and
!std.meta.eql(from, Origin{ .cmd = .Find }) and
- !std.meta.eql(from, Origin{ .query = .completion });
+ !std.meta.eql(from, Origin{ .query = .completion }) and
+ !std.meta.eql(from, Origin{ .query = .callstack });
}
pub fn fileTraits(out: ?State) Traits {
@@ -533,8 +562,11 @@ pub fn fillResults(p: *Pardes, id: usize, dir: []const u8, from: Origin, arg: []
return;
}
}
- if (usesLocationsConfig(from)) {
- const formatted = try locations.format(p, dir, content, anchor, true);
+ if (usesLocationsConfig(from) or std.meta.eql(from, Origin{ .query = .callstack })) {
+ const formatted = if (std.meta.eql(from, Origin{ .query = .callstack }))
+ try locations.formatCallstack(p, dir, content)
+ else
+ try locations.format(p, dir, content, anchor, true);
p.gpa.free(result_content);
result_content = formatted.content;
result_rows = formatted.rows;
@@ -863,7 +895,7 @@ pub fn openThemes(p: *Pardes, id: usize) !void {
pub fn isWalkRow(file: *const File.State, row: usize, line: []const u8) bool {
const state = file.output orelse return true;
- if (usesLocationsConfig(state.from)) return isResultRow(file, row);
+ if (usesLocationsConfig(state.from) or std.meta.eql(state.from, Origin{ .query = .callstack })) return isResultRow(file, row);
if (!std.meta.eql(state.from, Origin{ .cmd = .Themes })) return true;
// Section labels are for reading, not stops in the command walk.
return std.mem.startsWith(u8, std.mem.trimStart(u8, line, " \t"), comptime config.Runtime.findAction(.theme).?.word ++ " ");
@@ -901,11 +933,14 @@ fn openStepped(p: *Pardes, id: usize, from: Origin, content: []u8) !void {
fn helpContent(gpa: std.mem.Allocator, prefix: []const u8) ![]u8 {
const full_header = "pardes builtins, and how to run each:\nSPC and its keys, a chord, a button, the\ntopbar - or the name, executed anywhere.\n\n";
const group_header = "pardes builtins under SPC";
+ const calls_help = "\nCallstack: static caller chains,\nwith signatures and clickable call sites.\nCallers / Callees: one direction at a time.\n";
+ const show_calls_help = prefix.len == 0 or std.mem.eql(u8, prefix, "l");
const language_footer =
"\nlanguage keys (motions, not words):\n" ++
"gd gD gy gi gr goto: definition,\n" ++
" declaration, type-def,\n" ++
" implementation, refs\n" ++
+ "gc Callstack\n" ++
"]d [d ]D [D diagnostics: next,\n" ++
" prev, last, first\n" ++
"= format (applies, one\n" ++
@@ -918,6 +953,7 @@ fn helpContent(gpa: std.mem.Allocator, prefix: []const u8) ![]u8 {
full_header.len + language_footer.len
else
group_header.len + prefix.len * 2 + 2;
+ if (show_calls_help) len += calls_help.len;
for (pardes.builtin_rows) |row| {
// a path-less builtin filters as the empty path: in the full listing
// (which starts with nothing) and out of every group
@@ -948,6 +984,10 @@ fn helpContent(gpa: std.mem.Allocator, prefix: []const u8) ![]u8 {
content[at] = '\n';
at += 1;
}
+ if (show_calls_help) {
+ @memcpy(content[at..][0..calls_help.len], calls_help);
+ at += calls_help.len;
+ }
if (prefix.len == 0) {
@memcpy(content[at..][0..language_footer.len], language_footer);
at += language_footer.len;
@@ -963,7 +1003,7 @@ pub fn openHelp(p: *Pardes, id: usize, prefix: []const u8) !void {
return openRead(p, id, .{ .cmd = .Help }, prefix, content);
}
-test "full Help renders every builtin row, then the language keys" {
+test "full Help renders builtin rows, a call hierarchy guide, then language keys" {
const content = try helpContent(std.testing.allocator, "");
defer std.testing.allocator.free(content);
@@ -974,17 +1014,22 @@ test "full Help renders every builtin row, then the language keys" {
for (pardes.builtin_rows) |row|
try std.testing.expectEqualStrings(row.line, lines.next() orelse
return error.MissingBuiltinHelpRow);
- // ...and after the last row, the language-keys section: the one part of
- // the keymap no builtin row can carry, closing the page.
+ // The short call guide disambiguates the three related commands.
+ try std.testing.expectEqualStrings("", lines.next() orelse return error.MissingCallHelp);
+ try std.testing.expectEqualStrings("Callstack: static caller chains,", lines.next() orelse return error.MissingCallHelp);
+ try std.testing.expectEqualStrings("with signatures and clickable call sites.", lines.next() orelse return error.MissingCallHelp);
+ try std.testing.expectEqualStrings("Callers / Callees: one direction at a time.", lines.next() orelse return error.MissingCallHelp);
+ // The language keys close the page.
try std.testing.expectEqualStrings("", lines.next() orelse
return error.MissingLanguageKeys);
try std.testing.expectEqualStrings("language keys (motions, not words):", lines.next() orelse
return error.MissingLanguageKeys);
try std.testing.expect(std.mem.indexOf(u8, body, "\ngd gD gy gi gr goto: definition,\n") != null);
- // the group view stays a pure filter: no footer under a prefix
+ // The language group also explains call commands, without the motion footer.
const group = try helpContent(std.testing.allocator, "l");
defer std.testing.allocator.free(group);
try std.testing.expect(std.mem.indexOf(u8, group, "language keys") == null);
+ try std.testing.expect(std.mem.indexOf(u8, group, "Callstack: static caller chains") != null);
}
pub fn openConfig(p: *Pardes, id: usize) !void {