summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-11-05 10:40:00 -0300
committerGabriel Schneider <[email protected]>2026-11-05 10:57:08 -0300
commite6a9e2a3bbc5954d2c562019b3ce2983bb98b9cc (patch)
tree84b50c6a5103acdba0a55f919f1f466393559d51
parent9941d55222a913ab353fedb4451092be0d958206 (diff)
downloadpardes-e6a9e2a3bbc5954d2c562019b3ce2983bb98b9cc.tar.gz
pardes-e6a9e2a3bbc5954d2c562019b3ce2983bb98b9cc.zip
test: T1 asks the language words' servers, the suite next-tests.md said was missing: a Session made by initLanguage performs each lsp effect as a host does (host_io.Lsp, on the session's thread and at once; host_io is pub in the core for it), a .rs file's server the scripted one (test/lspmock.zig, built for the session's module as for the snapshot scripts), and test/behaviour/callstack.zig pins the guide's Call hierarchy through it: the tree +Callstack shows, and CallstackDepth bounding the walk
Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_016Y9MNAtZenFv4weoMD3cge
-rw-r--r--build.zig13
-rw-r--r--src/pardes.zig2
-rw-r--r--test/behaviour.zig1
-rw-r--r--test/behaviour/callstack.zig61
-rw-r--r--test/session.zig34
5 files changed, 110 insertions, 1 deletions
diff --git a/build.zig b/build.zig
index d3b82d68..096779a9 100644
--- a/build.zig
+++ b/build.zig
@@ -1642,6 +1642,19 @@ pub fn build(b: *std.Build) void {
.link_libc = true,
});
session_module.addImport("pardes", core_module);
+ // The scripted language server its language words ask
+ // (Session.initLanguage), as the snapshot scripts' do.
+ const session_options = b.addOptions();
+ session_options.addOptionPath("lspmock", b.addExecutable(.{
+ .name = "pardes-lspmock",
+ .root_module = b.createModule(.{
+ .target = target,
+ .optimize = optimize,
+ .root_source_file = b.path("test/lspmock.zig"),
+ .link_libc = true,
+ }),
+ }).getEmittedBin());
+ session_module.addOptions("session_options", session_options);
const behaviour_module = b.createModule(.{
.target = target,
.optimize = optimize,
diff --git a/src/pardes.zig b/src/pardes.zig
index 1b09f8ee..334d66e2 100644
--- a/src/pardes.zig
+++ b/src/pardes.zig
@@ -66,7 +66,7 @@ pub const echo = @import("echo.zig");
pub const image = @import("image.zig");
pub const dump = @import("dump.zig");
pub const lsp = @import("lsp/lsp.zig");
-const host_io = @import("host_io.zig");
+pub const host_io = @import("host_io.zig");
pub const Host = host_io.Host;
pub const frameMark = tracy.frameMark;
diff --git a/test/behaviour.zig b/test/behaviour.zig
index e19a847f..8f412df6 100644
--- a/test/behaviour.zig
+++ b/test/behaviour.zig
@@ -5,6 +5,7 @@
test {
_ = @import("behaviour/addresses.zig");
_ = @import("behaviour/builtins.zig");
+ _ = @import("behaviour/callstack.zig");
_ = @import("behaviour/columns_and_tags.zig");
_ = @import("behaviour/edit.zig");
_ = @import("behaviour/event.zig");
diff --git a/test/behaviour/callstack.zig b/test/behaviour/callstack.zig
new file mode 100644
index 00000000..42448031
--- /dev/null
+++ b/test/behaviour/callstack.zig
@@ -0,0 +1,61 @@
+//! docs/typ/guide.typ, Call hierarchy <callstack>, asked of the scripted
+//! language server (test/lspmock.zig): `add` in lib.rs is called twice by
+//! `main` in main.rs, and `main` by itself.
+const std = @import("std");
+const Session = @import("session").Session;
+
+/// main.rs and lib.rs in a directory of their own, main.rs shown with its
+/// cursor on the first call of `add`; its pane's serial.
+fn openMain(s: *Session, tmp: *std.testing.TmpDir) !u32 {
+ try tmp.dir.writeFile(std.testing.io, .{ .sub_path = "main.rs", .data = "mod lib;\n\nfn main() {\n let x = add(1, 2);\n let y = add(3, 4);\n let _ = x + y;\n}\n" });
+ try tmp.dir.writeFile(std.testing.io, .{ .sub_path = "lib.rs", .data = "// mock fixture\npub fn add(a: i32, b: i32) -> i32 {\n a + b\n}\n" });
+ var buf: [4096]u8 = undefined;
+ const dir = buf[0..try tmp.dir.realPath(std.testing.io, &buf)];
+ return s.lookFile(s.at("{s}/main.rs:4:13", .{dir}));
+}
+
+test "callstack: Callstack opens +Callstack, the outermost callers first, each with its signature and its call sites, a recursion marked" {
+ var tmp = std.testing.tmpDir(.{});
+ defer tmp.cleanup();
+ var s = try Session.initLanguage(std.testing.allocator);
+ defer s.deinit();
+ const main = try openMain(&s, &tmp);
+ try s.write(s.at("/pane/{d}/ctl", .{main}), "Callstack\n");
+ const tree = try s.focused();
+ try std.testing.expect(std.mem.endsWith(u8, try s.read(s.at("/pane/{d}/name", .{tree})), "/+Callstack\n"));
+ try s.expect(s.at("/pane/{d}/body", .{tree}),
+ \\╰──┬ main.rs:3:4-7
+ \\ │ fn main() {
+ \\ ├─ main.rs:4:13-15
+ \\ │ let x = add(1, 2);
+ \\ ├─ main.rs:5:13-15
+ \\ │ let y = add(3, 4);
+ \\ ╰──┬ main.rs:3:4-7
+ \\ │ fn main() { ↻ recursion
+ \\ ├─ main.rs:4:13-15
+ \\ │ let x = add(1, 2);
+ \\ ╰─ main.rs:5:13-15
+ \\ let y = add(3, 4);
+ \\
+ );
+}
+
+test "callstack: CallstackDepth bounds the walk, its last row inviting a Callstack from a function above" {
+ var tmp = std.testing.tmpDir(.{});
+ defer tmp.cleanup();
+ var s = try Session.initLanguage(std.testing.allocator);
+ defer s.deinit();
+ const main = try openMain(&s, &tmp);
+ try s.write("/ctl", "CallstackDepth 1\n");
+ try s.write(s.at("/pane/{d}/ctl", .{main}), "Callstack\n");
+ try s.expect(s.at("/pane/{d}/body", .{try s.focused()}),
+ \\╰──┬ main.rs:3:4-7
+ \\ │ fn main() {
+ \\ ├─ main.rs:4:13-15
+ \\ │ let x = add(1, 2);
+ \\ ╰─ main.rs:5:13-15
+ \\ let y = add(3, 4);
+ \\… continue from a function above with Callstack
+ \\
+ );
+}
diff --git a/test/session.zig b/test/session.zig
index 41f2c376..c28c2892 100644
--- a/test/session.zig
+++ b/test/session.zig
@@ -10,6 +10,8 @@ const Pardes = pardes.Pardes;
const Req = pardes.ctlfs.Req;
const Reply = pardes.ctlfs.Reply;
+extern "c" fn setenv(name: [*:0]const u8, value: [*:0]const u8, overwrite: c_int) c_int;
+
pub const Session = struct {
core: *anyopaque,
/// What the calls answered, kept until deinit.
@@ -19,6 +21,9 @@ pub const Session = struct {
/// The words of the last refusal `refused` answered.
said: []const u8 = "",
tag: u64 = 0,
+ /// What the language words' questions are asked of their servers
+ /// through (initLanguage); none, and they go unanswered.
+ languages: ?std.Io = null,
/// A session showing one file pane holding `text`.
pub fn initFile(gpa: std.mem.Allocator, text: []const u8) !Session {
@@ -30,6 +35,17 @@ pub const Session = struct {
return s;
}
+ /// A session showing one scratch pane that asks language servers as a
+ /// host does, a `.rs` file's the scripted one (test/lspmock.zig, which
+ /// answers over a main.rs and the lib.rs beside it).
+ pub fn initLanguage(gpa: std.mem.Allocator) !Session {
+ var s = try initFile(gpa, "x\n");
+ const mock = try std.Io.Dir.cwd().realPathFileAlloc(std.testing.io, @import("session_options").lspmock, s.arena.allocator());
+ _ = setenv("PARDES_LSP_RS", mock, 1);
+ s.languages = std.testing.io;
+ return s;
+ }
+
/// A session showing its terminal pane, as `pardes` starts.
pub fn initTerm(gpa: std.mem.Allocator) !Session {
const p = try Pardes.init(gpa, .{ .tty_only = true, .cols = 80, .rows = 24 });
@@ -175,10 +191,28 @@ pub const Session = struct {
fn drain(s: *Session) void {
while (pardesOf(s).nextEffect()) |e| switch (e) {
.save_file, .save_text => s.saved += 1,
+ .lsp => |q| if (s.languages) |io| s.askServer(io, .{ .id = q.id, .kind = q.kind, .pane = q.pane, .offset = q.offset, .arg = q.arg.slice() }),
else => {},
};
}
+ /// A language word's question asked of its server as a host asks it
+ /// (host_io.Lsp), here and at once: its answer the core's next event.
+ fn askServer(s: *Session, io: std.Io, req: pardes.host_io.Lsp.Request) void {
+ const p = pardesOf(s);
+ const Lsp = pardes.host_io.Lsp;
+ const job = Lsp.snapshot(p.gpa, p, req) catch return p.update(.{ .lsp_resp = .{ .id = req.id, .rows = null } });
+ var rows: ?[]u8 = null;
+ Lsp.work(io, p.gpa, job, &rows, struct {
+ fn keep(ctx: ?*anyopaque, _: u32, answer: ?[]u8) void {
+ const into: *?[]u8 = @ptrCast(@alignCast(ctx.?));
+ into.* = answer;
+ }
+ }.keep);
+ defer if (rows) |owned| p.gpa.free(owned);
+ p.update(.{ .lsp_resp = .{ .id = req.id, .rows = rows } });
+ }
+
fn pardesOf(s: *Session) *Pardes {
return @ptrCast(@alignCast(s.core));
}