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.zig82
1 files changed, 81 insertions, 1 deletions
diff --git a/test/behaviour/language_servers.zig b/test/behaviour/language_servers.zig
index 13e42fa6..d1b160ee 100644
--- a/test/behaviour/language_servers.zig
+++ b/test/behaviour/language_servers.zig
@@ -206,7 +206,7 @@ test "language-servers: Symbols lists the file's definitions by name, a local's
try s.write(s.at("/pane/{d}/look", .{main}), s.at("{s}/lib.rs\n", .{std.fs.path.dirname(std.mem.trimEnd(u8, try s.read(s.at("/pane/{d}/name", .{main})), "\n")).?}));
try s.write(s.at("/pane/{d}/ctl", .{try s.focused()}), "Symbols\n");
const rows = try bodyOf(&s, "+Search");
- for ([_][]const u8{ "lib.rs:1:11-15\nShape\n", "lib.rs:2:8-11\narea\n", "lib.rs:5:8-10\nadd\n", "lib.rs:8:12-17\nSquare\n", "lib.rs:10:8-11\narea\n" }) |row|
+ for ([_][]const u8{ "lib.rs:1:11-15 Shape\n", "lib.rs:2:8-11 area\n", "lib.rs:5:8-10 add\n", "lib.rs:8:12-17 Square\n", "lib.rs:10:8-11 area\n" }) |row|
try std.testing.expect(has(rows, row));
try std.testing.expect(!has(rows, "lib.rs:5:12"));
}
@@ -323,3 +323,83 @@ 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);
}
+
+test "language-servers: a server's Symbols are the Symbols picker's rows: types, functions, fields, then the rest, each its kind's mark and its name in the ones it is in (UX DESIGN N)" {
+ var tmp = std.testing.tmpDir(.{});
+ defer tmp.cleanup();
+ var s = try Session.initLanguage(std.testing.allocator);
+ defer s.deinit();
+ try s.write("/ctl", "Jumps new-pane\n");
+ // No index: the server is asked.
+ try tmp.dir.writeFile(std.testing.io, .{ .sub_path = "shapes.rs", .data = "const LIMIT: u32 = 4;\n\nfn main() {}\npub struct Shape {\n side: u32,\n fn area() {}\n}\nenum Kind {\n Round,\n}\nmod lib;\n" });
+ var buf: [4096]u8 = undefined;
+ const dir = buf[0..try tmp.dir.realPath(std.testing.io, &buf)];
+ const shapes = try s.lookFile(s.at("{s}/shapes.rs:1:1", .{dir}));
+ try s.write(s.at("/pane/{d}/ctl", .{shapes}), "Symbols\n");
+ const rows = try bodyOf(&s, "+Search");
+ var at: usize = 0;
+ for ([_][]const u8{ "shapes.rs:4:12-16 t Shape\n", "shapes.rs:8:6-9 t Kind\n", "shapes.rs:3:4-7 f main\n", "shapes.rs:6:8-11 f Shape.area\n", "shapes.rs:5:5-8 m Shape.side\n", "shapes.rs:9:5-9 m Kind.Round\n", "shapes.rs:1:7-11 c LIMIT\n", "shapes.rs:11:5-7 n lib\n" }) |row| {
+ const found = std.mem.indexOfPos(u8, rows, at, row) orelse {
+ std.debug.print("{s} not after {d} in\n{s}\n", .{ row, at, rows });
+ return error.TestUnexpectedResult;
+ };
+ at = found + row.len;
+ }
+}
+
+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"));
+}