summaryrefslogtreecommitdiff
path: root/test/behaviour/language_servers.zig
diff options
context:
space:
mode:
Diffstat (limited to 'test/behaviour/language_servers.zig')
-rw-r--r--test/behaviour/language_servers.zig57
1 files changed, 57 insertions, 0 deletions
diff --git a/test/behaviour/language_servers.zig b/test/behaviour/language_servers.zig
index 13e42fa6..79b556f4 100644
--- a/test/behaviour/language_servers.zig
+++ b/test/behaviour/language_servers.zig
@@ -323,3 +323,60 @@ test "language-servers: SPC l a lists the server's code actions in the pane's ta
try s.keys("u");
try s.expect(body, before);
}
+
+extern "c" fn setenv(name: [*:0]const u8, value: [*:0]const u8, overwrite: c_int) c_int;
+
+/// The row of Lspinfo's report on the server `name` (`zls`), asked of the
+/// pane with the keyboard, and how many queries its client has answered.
+fn serverRow(s: *Session, name: []const u8) !struct { []const u8, []const u8 } {
+ try s.write(s.at("/pane/{d}/ctl", .{try s.focused()}), "Lspinfo\n");
+ const info = try bodyOf(s, "+Lsp");
+ const at = (std.mem.indexOf(u8, info, s.at("\n {s} ", .{name})) orelse return error.NoSuchServer) + 1;
+ const row = info[at .. std.mem.indexOfScalarPos(u8, info, at, '\n') orelse info.len];
+ const log = std.mem.indexOf(u8, info, "client queries (") orelse return error.NoQueryLog;
+ return .{ row, info[log .. std.mem.indexOfPos(u8, info, log, " total") orelse return error.NoQueryLog] };
+}
+
+test "language-servers: a file of a server's language opened in a pane starts that server and tells it of the file, with no query asked; a picker's preview of one starts none, a second file no second server, and a server not installed is found silently" {
+ const io = std.testing.io;
+ var tmp = std.testing.tmpDir(.{});
+ defer tmp.cleanup();
+ // A work tree of its own: Find searches it, not the one the test runs in.
+ try tmp.dir.createDir(io, ".git", .default_dir);
+ try tmp.dir.writeFile(io, .{ .sub_path = "a.zig", .data = "const a = 1;\n" });
+ try tmp.dir.writeFile(io, .{ .sub_path = "b.zig", .data = "const b = 2;\n" });
+ try tmp.dir.writeFile(io, .{ .sub_path = "c.py", .data = "c = 3\n" });
+ try tmp.dir.writeFile(io, .{ .sub_path = "d.py", .data = "d = 4\n" });
+ try tmp.dir.writeFile(io, .{ .sub_path = "notes.txt", .data = "the notes\n" });
+ var buf: [4096]u8 = undefined;
+ const dir = buf[0..try tmp.dir.realPath(io, &buf)];
+ var s = try Session.initLanguage(std.testing.allocator);
+ defer s.deinit();
+ _ = try s.lookFile(s.at("{s}/notes.txt", .{dir}));
+ // a.zig previewed by Find's picker (the session's jumps walk): its text
+ // shown, its server (the scripted one, the session's zls) not started.
+ try s.keys(" ffa.zig");
+ s.tick();
+ try std.testing.expect(has(try s.screen(), "const a = 1;"));
+ try s.keys("\x1b");
+ const before, const asked = try serverRow(&s, "zls");
+ try std.testing.expect(has(before, "not started yet"));
+ // Opened: started and told of a.zig, no query asked of it.
+ _ = try s.lookFile(s.at("{s}/a.zig", .{dir}));
+ const opened, const asked_open = try serverRow(&s, "zls");
+ try std.testing.expect(has(opened, "ready") and has(opened, "docs 1"));
+ try std.testing.expectEqualStrings(asked, asked_open);
+ // A second file: the same server told of it too (a second would know one).
+ _ = try s.lookFile(s.at("{s}/b.zig", .{dir}));
+ const second, _ = try serverRow(&s, "zls");
+ try std.testing.expect(has(second, "ready") and has(second, "docs 2"));
+ // Not installed: the language's server disabled at the first file's
+ // open, with no word at either (its first query says it is not found).
+ _ = setenv("PARDES_LSP_PY", "/nonexistent/pyright-langserver", 1);
+ _ = try s.lookFile(s.at("{s}/c.py", .{dir}));
+ _ = try s.lookFile(s.at("{s}/d.py", .{dir}));
+ const missing, const asked_missing = try serverRow(&s, "pyright");
+ try std.testing.expect(has(missing, "disabled"));
+ try std.testing.expectEqualStrings(asked, asked_missing);
+ try std.testing.expect(!has(try s.screen(), "not found"));
+}