Add LSP-assisted terminal E2E coverage
This commit is contained in:
+24
-4
@@ -127,7 +127,18 @@ pub fn main(init: std.process.Init) !u8 {
|
||||
}
|
||||
}
|
||||
|
||||
const command = if (first_arg) |arg|
|
||||
var e2e_prelude_path: ?[]const u8 = null;
|
||||
var open_arg = first_arg;
|
||||
if (first_arg) |arg| {
|
||||
if (std.mem.eql(u8, arg, "--e2e-prelude-file")) {
|
||||
e2e_prelude_path = args.next() orelse {
|
||||
try stderr.writeStreamingAll(init.io, "mim: --e2e-prelude-file requires a path\n");
|
||||
return 64;
|
||||
};
|
||||
open_arg = args.next();
|
||||
}
|
||||
}
|
||||
const command = if (open_arg) |arg|
|
||||
parseArgs(&.{ "mim", arg })
|
||||
else
|
||||
parseArgs(&.{"mim"});
|
||||
@@ -135,7 +146,7 @@ pub fn main(init: std.process.Init) !u8 {
|
||||
switch (command) {
|
||||
.help => try stdout.writeStreamingAll(init.io, help_text),
|
||||
.version => try stdout.writeStreamingAll(init.io, versionText()),
|
||||
.open => |path| try openLocalEditor(allocator, init.io, stdout, stderr, path),
|
||||
.open => |path| try openLocalEditor(allocator, init.io, stdout, stderr, path, e2e_prelude_path),
|
||||
}
|
||||
|
||||
return 0;
|
||||
@@ -147,6 +158,7 @@ fn openLocalEditor(
|
||||
stdout: std.Io.File,
|
||||
stderr: std.Io.File,
|
||||
path: []const u8,
|
||||
e2e_prelude_path: ?[]const u8,
|
||||
) !void {
|
||||
var client = try tui.Client.init(allocator, .{ .width = 80, .height = 22 });
|
||||
defer client.deinit();
|
||||
@@ -167,7 +179,7 @@ fn openLocalEditor(
|
||||
const bytes = std.Io.Dir.cwd().readFileAlloc(io, path, allocator, .limited(diagnostics.max_file_bytes)) catch |err| switch (err) {
|
||||
error.StreamTooLong => {
|
||||
try client.handleTraceLine("open diagnostic:file_too_large");
|
||||
return runLocalEditor(allocator, io, stdout, stderr, &client, path, false);
|
||||
return runLocalEditor(allocator, io, stdout, stderr, &client, path, false, e2e_prelude_path);
|
||||
},
|
||||
else => return err,
|
||||
};
|
||||
@@ -182,7 +194,7 @@ fn openLocalEditor(
|
||||
try client.handleTraceLine("open ");
|
||||
}
|
||||
|
||||
try runLocalEditor(allocator, io, stdout, stderr, &client, path, stat != null and stat.?.kind == .directory);
|
||||
try runLocalEditor(allocator, io, stdout, stderr, &client, path, stat != null and stat.?.kind == .directory, e2e_prelude_path);
|
||||
}
|
||||
|
||||
fn seedDirectoryRepo(allocator: std.mem.Allocator, io: std.Io, client: *tui.Client, path: []const u8) !void {
|
||||
@@ -227,6 +239,7 @@ fn runLocalEditor(
|
||||
client: *tui.Client,
|
||||
path: []const u8,
|
||||
is_dir: bool,
|
||||
e2e_prelude_path: ?[]const u8,
|
||||
) !void {
|
||||
const stdin_file = std.Io.File.stdin();
|
||||
const interactive = stdin_file.isTty(io) catch false;
|
||||
@@ -236,6 +249,13 @@ fn runLocalEditor(
|
||||
var last_client_saved: ?[]u8 = null;
|
||||
defer if (last_client_saved) |bytes| allocator.free(bytes);
|
||||
|
||||
if (e2e_prelude_path) |prelude_path| {
|
||||
const prelude = try std.Io.Dir.cwd().readFileAlloc(io, prelude_path, allocator, .limited(64 * 1024));
|
||||
defer allocator.free(prelude);
|
||||
var lines = std.mem.splitScalar(u8, prelude, '\n');
|
||||
while (lines.next()) |line| if (line.len != 0) try client.handleTraceLine(line);
|
||||
}
|
||||
|
||||
if (!interactive) {
|
||||
try renderLocalFrame(allocator, io, stdout, client, path, is_dir, false);
|
||||
return;
|
||||
|
||||
Reference in New Issue
Block a user