summaryrefslogtreecommitdiff
path: root/test/session.zig
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 /test/session.zig
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
Diffstat (limited to 'test/session.zig')
-rw-r--r--test/session.zig34
1 files changed, 34 insertions, 0 deletions
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));
}