diff options
Diffstat (limited to 'test')
| -rw-r--r-- | test/behaviour/language_servers.zig | 57 | ||||
| -rw-r--r-- | test/daemon.py | 3 | ||||
| -rw-r--r-- | test/fs.py | 2 | ||||
| -rw-r--r-- | test/process.zig | 5 | ||||
| -rw-r--r-- | test/selfmount.py | 2 | ||||
| -rw-r--r-- | test/session.zig | 19 | ||||
| -rw-r--r-- | test/tty.zig | 5 |
7 files changed, 89 insertions, 4 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")); +} diff --git a/test/daemon.py b/test/daemon.py index 3dfb0710..95a4da75 100644 --- a/test/daemon.py +++ b/test/daemon.py @@ -92,6 +92,9 @@ def base_env(): of the user's) or a pager; under `--with-pair`, PARDES_PAIR set in it, as for a user who exported it: every mode run with the variable.""" env = {k: v for k, v in os.environ.items() if not k.startswith('PARDES_') and 'PAGER' not in k} + # No language server starts at a file's open (lsp_client.open): none of + # this machine's. + env['PARDES_LSP_OPEN'] = 'off' if WITH_PAIR: env['PARDES_PAIR'] = '1' return env @@ -32,6 +32,8 @@ def session(binary, root, name, *options, socket_name=None, file=None, tty=False env.update(inherited or {}) for language in ['RS', 'C', 'GO', 'TS', 'PY']: env['PARDES_LSP_' + language] = '' + # No server starts at a file's open (lsp_client.open): none of this machine's. + env['PARDES_LSP_OPEN'] = 'off' fixture = root / (name + '.txt') fixture.write_bytes(b'initial\n') address = root / ('pardes-9p-' + (socket_name or name) + '.sock') diff --git a/test/process.zig b/test/process.zig index 791a5b8e..fe5d97f0 100644 --- a/test/process.zig +++ b/test/process.zig @@ -960,9 +960,12 @@ pub const Child = struct { // never the user's: the dumps a test makes there would push the // user's out. if (root_z != null) _ = unsetenv("XDG_DATA_HOME"); + // No language server starts at a file's open (lsp_client.open): + // the `lsp` cases' zls is this machine's, started by their + // first query as before. for ([_][2][*:0]const u8{ .{ "PARDES_DAEMON", "off" }, .{ "PARDES_LSP_RS", "" }, .{ "PARDES_LSP_C", "" }, .{ "PARDES_LSP_GO", "" }, - .{ "PARDES_LSP_TS", "" }, .{ "PARDES_LSP_PY", "" }, + .{ "PARDES_LSP_TS", "" }, .{ "PARDES_LSP_PY", "" }, .{ "PARDES_LSP_OPEN", "off" }, }) |kv| if (setenv(kv[0], kv[1], 1) != 0) _exit(126); if (opts.pty != null and setenv("TERM", "xterm-256color", 1) != 0) _exit(126); // No test reaches the user's display: a window any of them diff --git a/test/selfmount.py b/test/selfmount.py index 61d32523..aa4540b0 100644 --- a/test/selfmount.py +++ b/test/selfmount.py @@ -81,6 +81,8 @@ def run(binary): env.update(PARDES_NOTIME='1', TERM='xterm-256color', PARDES_DUMP=f'/tmp/{name}.dump.zon') for language in ['RS', 'C', 'GO', 'TS', 'PY']: env['PARDES_LSP_' + language] = '' + # No server starts at a file's open (lsp_client.open): none of this machine's. + env['PARDES_LSP_OPEN'] = 'off' pid, master = pty.fork() if pid == 0: os.execve(ns, ['9ns', '--mntgen', '--', binary, '--tty', '--9p=' + name, str(fixture)], env) diff --git a/test/session.zig b/test/session.zig index 13798753..9285c13b 100644 --- a/test/session.zig +++ b/test/session.zig @@ -38,6 +38,8 @@ pub const Session = struct { /// What the language words' questions are asked of their servers /// through (initLanguage); none, and they go unanswered. languages: ?std.Io = null, + /// The server start a file's opening asks for (`languages`'s). + opener: pardes.host_io.Lsp.Opener = .{}, /// Kinds' jobs taken as a host's worker takes them and held, not run, /// until `releaseJobs`: a job under way across what a test does /// meanwhile (a reload). @@ -62,12 +64,19 @@ pub const Session = struct { } /// 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). + /// host does, a `.rs` and a `.zig` file's the scripted one + /// (test/lspmock.zig, which answers over a main.rs and the lib.rs beside + /// it), every other language's none: no test starts a server of this + /// machine's. 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); + _ = setenv("PARDES_LSP_ZIG", mock, 1); + for ([_][*:0]const u8{ "PARDES_LSP_C", "PARDES_LSP_GO", "PARDES_LSP_TS", "PARDES_LSP_PY" }) |v| _ = setenv(v, "", 1); + // A test binary's opened files start their servers where it says + // so (lsp_client.open): here, the mock. + _ = setenv("PARDES_LSP_OPEN", "on", 1); s.languages = std.testing.io; return s; } @@ -295,6 +304,12 @@ pub const Session = struct { // held while a test holds them (`hold_jobs`). .job => |j| if (!s.hold_jobs) pardesOf(s).perform(e) else if (pardes.host_io.KindJob.take(pardesOf(s), j.pane.index(), j.serial, j.token)) |taken| s.held.append(pardesOf(s).gpa, taken) catch taken.drop(), .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() }), + // A file's server started as a host starts it, and waited for. + .lsp_open => |o| if (s.languages) |io| { + pardes.host_io.Lsp.open(io, pardesOf(s).gpa, pardesOf(s), &s.opener, o.pane); + if (s.opener.future) |*f| f.await(io); + s.opener.future = null; + }, .watch => |w| { if (s.watch_fd < 0) s.watch_fd = pardes.file_watch.init(true); if (s.watch_fd >= 0) _ = pardes.file_watch.applyEffect(pardesOf(s), std.Io.Threaded.global_single_threaded.io(), s.watch_fd, &s.watches, w.pane.index(), w.on, w.mode); diff --git a/test/tty.zig b/test/tty.zig index 97b64b7c..cbb4e446 100644 --- a/test/tty.zig +++ b/test/tty.zig @@ -128,9 +128,12 @@ pub const Tty = struct { _ = setenv("PARDES_NOTIME", "1", 1); _ = setenv("PARDES_TEST_CLOCK", "1", 1); // Hermetic language clients: `.rs` speaks to the mock, every other - // spec is off, so a stray `.c` never spawns this machine's clangd. + // spec but zls is off, so a stray `.c` never spawns this machine's + // clangd, and no server starts at a file's open (lsp_client.open): + // the `lsp` cases' zls is started by their first query. _ = setenv("PARDES_LSP_RS", try arena.dupeSentinel(u8, lspmock, 0), 1); for ([_][*:0]const u8{ "PARDES_LSP_C", "PARDES_LSP_GO", "PARDES_LSP_TS", "PARDES_LSP_PY" }) |v| _ = setenv(v, "", 1); + _ = setenv("PARDES_LSP_OPEN", "off", 1); const dump = try std.fmt.allocPrintSentinel(arena, "{s}/dump.zon", .{base}, 0); _ = setenv("PARDES_DUMP", dump, 1); if (replay) { |
