1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
|
//! docs/typ/reference.typ, Builtins <builtins> a real session runs, detached
//! and in a pty.
const std = @import("std");
const process = @import("../process.zig");
const Conn = process.Conn;
const has = process.has;
const check = process.check;
pub const cases = .{
.{ "builtins: Lspinfo opens one +Lsp pane saying its index and its language servers, detached and in a pty", lspinfo },
};
fn lspinfo(gpa: std.mem.Allocator, exe: [:0]const u8) !void {
for ([_]bool{ false, true }) |tty| {
var arena = std.heap.ArenaAllocator.init(gpa);
defer arena.deinit();
const a = arena.allocator();
const name = if (tty) "lsp-tty" else "lsp-detached";
var d = try process.Detached.start(gpa, exe, if (tty) "lsp-root" else name, .{});
defer d.deinit();
var term: ?process.Child = null;
defer if (term) |*t| t.deinit();
if (tty) term = try d.startTty(exe, name, &.{});
const address = d.abs(try std.fmt.allocPrint(a, "pardes-9p-{s}.sock", .{name}));
const c = try Conn.dial(gpa, address);
defer c.deinit(gpa);
const control = try c.newPane();
try c.exec(control, "Lspinfo\n");
const deadline = process.nowMs() + 3_000;
const lsp = while (true) {
var found: ?u32 = null;
var count: usize = 0;
var rows = std.mem.tokenizeScalar(u8, try c.read(a, "/index"), '\n');
while (rows.next()) |row| if (has(row, "+Lsp")) {
count += 1;
found = try std.fmt.parseInt(u32, row[0..std.mem.indexOfScalar(u8, row, ' ').?], 10);
};
if (found) |n| {
try check(count == 1, "{s}: {d} +Lsp panes", .{ name, count });
break n;
}
if (process.nowMs() > deadline) return error.LspinfoNeverDone;
process.nap(5);
};
const body = try c.pane(a, lsp, "body");
try check(std.mem.startsWith(u8, body, "scip: no index.scip above ") and has(body, "\nlanguage servers:\n") and has(body, " zls "), "{s}", .{body});
try std.testing.expectEqualStrings("initial\n", try c.read(a, "/pane/1/body"));
var f: process.Files = .init(gpa, address);
defer f.deinit();
try check(has(try f.screen(), "+Lsp"), "+Lsp not drawn", .{});
}
}
|