Merge branch 'master' into zig-0.14
This commit is contained in:
		
						commit
						43b14d9147
					
				
					 5 changed files with 77 additions and 5 deletions
				
			
		| 
						 | 
					@ -20,6 +20,7 @@ open_time: i64,
 | 
				
			||||||
language_servers: std.StringHashMap(LSP),
 | 
					language_servers: std.StringHashMap(LSP),
 | 
				
			||||||
file_language_server: std.StringHashMap(LSP),
 | 
					file_language_server: std.StringHashMap(LSP),
 | 
				
			||||||
tasks: std.ArrayList(Task),
 | 
					tasks: std.ArrayList(Task),
 | 
				
			||||||
 | 
					persistent: bool = false,
 | 
				
			||||||
 | 
					
 | 
				
			||||||
const Self = @This();
 | 
					const Self = @This();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -130,6 +131,7 @@ pub fn restore_state(self: *Self, data: []const u8) !void {
 | 
				
			||||||
        error.InvalidType => return self.restore_state_v0(data),
 | 
					        error.InvalidType => return self.restore_state_v0(data),
 | 
				
			||||||
        else => return tp.trace(tp.channel.debug, .{ "restore_state", "unknown format", data }),
 | 
					        else => return tp.trace(tp.channel.debug, .{ "restore_state", "unknown format", data }),
 | 
				
			||||||
    };
 | 
					    };
 | 
				
			||||||
 | 
					    self.persistent = true;
 | 
				
			||||||
    return self.restore_state_v1(data);
 | 
					    return self.restore_state_v1(data);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
							
								
								
									
										13
									
								
								src/main.zig
									
										
									
									
									
								
							
							
						
						
									
										13
									
								
								src/main.zig
									
										
									
									
									
								
							| 
						 | 
					@ -56,6 +56,8 @@ pub fn main() anyerror!void {
 | 
				
			||||||
        ;
 | 
					        ;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        pub const descriptions = .{
 | 
					        pub const descriptions = .{
 | 
				
			||||||
 | 
					            .project = "Set project directory (default: cwd)",
 | 
				
			||||||
 | 
					            .no_persist = "Do not persist new projects",
 | 
				
			||||||
            .frame_rate = "Set target frame rate (default: 60)",
 | 
					            .frame_rate = "Set target frame rate (default: 60)",
 | 
				
			||||||
            .debug_wait = "Wait for key press before starting UI",
 | 
					            .debug_wait = "Wait for key press before starting UI",
 | 
				
			||||||
            .debug_dump_on_error = "Dump stack traces on errors",
 | 
					            .debug_dump_on_error = "Dump stack traces on errors",
 | 
				
			||||||
| 
						 | 
					@ -78,6 +80,8 @@ pub fn main() anyerror!void {
 | 
				
			||||||
        pub const formats = .{ .frame_rate = "num", .trace_level = "num", .exec = "cmds" };
 | 
					        pub const formats = .{ .frame_rate = "num", .trace_level = "num", .exec = "cmds" };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        pub const switches = .{
 | 
					        pub const switches = .{
 | 
				
			||||||
 | 
					            .project = 'p',
 | 
				
			||||||
 | 
					            .no_persist = 'N',
 | 
				
			||||||
            .frame_rate = 'f',
 | 
					            .frame_rate = 'f',
 | 
				
			||||||
            .trace_level = 't',
 | 
					            .trace_level = 't',
 | 
				
			||||||
            .language = 'l',
 | 
					            .language = 'l',
 | 
				
			||||||
| 
						 | 
					@ -86,6 +90,8 @@ pub fn main() anyerror!void {
 | 
				
			||||||
            .version = 'v',
 | 
					            .version = 'v',
 | 
				
			||||||
        };
 | 
					        };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        project: ?[]const u8,
 | 
				
			||||||
 | 
					        no_persist: bool,
 | 
				
			||||||
        frame_rate: ?usize,
 | 
					        frame_rate: ?usize,
 | 
				
			||||||
        debug_wait: bool,
 | 
					        debug_wait: bool,
 | 
				
			||||||
        debug_dump_on_error: bool,
 | 
					        debug_dump_on_error: bool,
 | 
				
			||||||
| 
						 | 
					@ -203,6 +209,7 @@ pub fn main() anyerror!void {
 | 
				
			||||||
    log.set_std_log_pid(log_proc.ref());
 | 
					    log.set_std_log_pid(log_proc.ref());
 | 
				
			||||||
    defer log.set_std_log_pid(null);
 | 
					    defer log.set_std_log_pid(null);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    env.set("no-persist", args.no_persist);
 | 
				
			||||||
    env.set("restore-session", args.restore_session);
 | 
					    env.set("restore-session", args.restore_session);
 | 
				
			||||||
    env.set("no-alternate", args.no_alternate);
 | 
					    env.set("no-alternate", args.no_alternate);
 | 
				
			||||||
    env.set("show-input", args.show_input);
 | 
					    env.set("show-input", args.show_input);
 | 
				
			||||||
| 
						 | 
					@ -271,11 +278,15 @@ pub fn main() anyerror!void {
 | 
				
			||||||
    var have_project = false;
 | 
					    var have_project = false;
 | 
				
			||||||
    var files = std.ArrayList(Dest).init(a);
 | 
					    var files = std.ArrayList(Dest).init(a);
 | 
				
			||||||
    defer files.deinit();
 | 
					    defer files.deinit();
 | 
				
			||||||
 | 
					    if (args.project) |project| {
 | 
				
			||||||
 | 
					        try tui_proc.send(.{ "cmd", "open_project_dir", .{project} });
 | 
				
			||||||
 | 
					        have_project = true;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
    for (dests.items) |dest| {
 | 
					    for (dests.items) |dest| {
 | 
				
			||||||
        if (dest.file.len == 0) continue;
 | 
					        if (dest.file.len == 0) continue;
 | 
				
			||||||
        if (is_directory(dest.file)) {
 | 
					        if (is_directory(dest.file)) {
 | 
				
			||||||
            if (have_project) {
 | 
					            if (have_project) {
 | 
				
			||||||
                std.debug.print("more than one directory is not allowed\n", .{});
 | 
					                std.debug.print("more than one project directory is not allowed\n", .{});
 | 
				
			||||||
                exit(1);
 | 
					                exit(1);
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
            try tui_proc.send(.{ "cmd", "open_project_dir", .{dest.file} });
 | 
					            try tui_proc.send(.{ "cmd", "open_project_dir", .{dest.file} });
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -64,6 +64,12 @@ pub fn open(rel_project_directory: []const u8) (ProjectManagerError || FileSyste
 | 
				
			||||||
    return send(.{ "open", project_directory });
 | 
					    return send(.{ "open", project_directory });
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					pub fn close(project_directory: []const u8) (ProjectManagerError || error{CloseCurrentProject})!void {
 | 
				
			||||||
 | 
					    const current_project = tp.env.get().str("project");
 | 
				
			||||||
 | 
					    if (std.mem.eql(u8, current_project, project_directory)) return error.CloseCurrentProject;
 | 
				
			||||||
 | 
					    return send(.{ "close", project_directory });
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
pub fn request_n_most_recent_file(allocator: std.mem.Allocator, n: usize) (CallError || ProjectError || cbor.Error)!?[]const u8 {
 | 
					pub fn request_n_most_recent_file(allocator: std.mem.Allocator, n: usize) (CallError || ProjectError || cbor.Error)!?[]const u8 {
 | 
				
			||||||
    const project = tp.env.get().str("project");
 | 
					    const project = tp.env.get().str("project");
 | 
				
			||||||
    if (project.len == 0)
 | 
					    if (project.len == 0)
 | 
				
			||||||
| 
						 | 
					@ -339,6 +345,8 @@ const Process = struct {
 | 
				
			||||||
            self.logger.print_err("lsp-handling", "child '{s}' terminated", .{path});
 | 
					            self.logger.print_err("lsp-handling", "child '{s}' terminated", .{path});
 | 
				
			||||||
        } else if (try cbor.match(m.buf, .{ "open", tp.extract(&project_directory) })) {
 | 
					        } else if (try cbor.match(m.buf, .{ "open", tp.extract(&project_directory) })) {
 | 
				
			||||||
            self.open(project_directory) catch |e| return from.forward_error(e, @errorReturnTrace()) catch error.ClientFailed;
 | 
					            self.open(project_directory) catch |e| return from.forward_error(e, @errorReturnTrace()) catch error.ClientFailed;
 | 
				
			||||||
 | 
					        } else if (try cbor.match(m.buf, .{ "close", tp.extract(&project_directory) })) {
 | 
				
			||||||
 | 
					            self.close(project_directory) catch |e| return from.forward_error(e, @errorReturnTrace()) catch error.ClientFailed;
 | 
				
			||||||
        } else if (try cbor.match(m.buf, .{ "request_n_most_recent_file", tp.extract(&project_directory), tp.extract(&n) })) {
 | 
					        } else if (try cbor.match(m.buf, .{ "request_n_most_recent_file", tp.extract(&project_directory), tp.extract(&n) })) {
 | 
				
			||||||
            self.request_n_most_recent_file(from, project_directory, n) catch |e| return from.forward_error(e, @errorReturnTrace()) catch error.ClientFailed;
 | 
					            self.request_n_most_recent_file(from, project_directory, n) catch |e| return from.forward_error(e, @errorReturnTrace()) catch error.ClientFailed;
 | 
				
			||||||
        } else if (try cbor.match(m.buf, .{ "request_recent_files", tp.extract(&project_directory), tp.extract(&max) })) {
 | 
					        } else if (try cbor.match(m.buf, .{ "request_recent_files", tp.extract(&project_directory), tp.extract(&max) })) {
 | 
				
			||||||
| 
						 | 
					@ -412,6 +420,16 @@ const Process = struct {
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    fn close(self: *Process, project_directory: []const u8) error{}!void {
 | 
				
			||||||
 | 
					        if (self.projects.fetchRemove(project_directory)) |kv| {
 | 
				
			||||||
 | 
					            self.allocator.free(kv.key);
 | 
				
			||||||
 | 
					            self.persist_project(kv.value) catch {};
 | 
				
			||||||
 | 
					            kv.value.deinit();
 | 
				
			||||||
 | 
					            self.allocator.destroy(kv.value);
 | 
				
			||||||
 | 
					            self.logger.print("closed: {s}", .{project_directory});
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    fn loaded(self: *Process, project_directory: []const u8) OutOfMemoryError!void {
 | 
					    fn loaded(self: *Process, project_directory: []const u8) OutOfMemoryError!void {
 | 
				
			||||||
        const project = self.projects.get(project_directory) orelse return;
 | 
					        const project = self.projects.get(project_directory) orelse return;
 | 
				
			||||||
        try project.merge_pending_files();
 | 
					        try project.merge_pending_files();
 | 
				
			||||||
| 
						 | 
					@ -442,8 +460,11 @@ const Process = struct {
 | 
				
			||||||
        var message = std.ArrayList(u8).init(self.allocator);
 | 
					        var message = std.ArrayList(u8).init(self.allocator);
 | 
				
			||||||
        const writer = message.writer();
 | 
					        const writer = message.writer();
 | 
				
			||||||
        try cbor.writeArrayHeader(writer, recent_projects.items.len);
 | 
					        try cbor.writeArrayHeader(writer, recent_projects.items.len);
 | 
				
			||||||
        for (recent_projects.items) |project|
 | 
					        for (recent_projects.items) |project| {
 | 
				
			||||||
 | 
					            try cbor.writeArrayHeader(writer, 2);
 | 
				
			||||||
            try cbor.writeValue(writer, project.name);
 | 
					            try cbor.writeValue(writer, project.name);
 | 
				
			||||||
 | 
					            try cbor.writeValue(writer, if (self.projects.get(project.name)) |_| true else false);
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
        from.send_raw(.{ .buf = message.items }) catch return error.ClientFailed;
 | 
					        from.send_raw(.{ .buf = message.items }) catch return error.ClientFailed;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -609,6 +630,8 @@ const Process = struct {
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    fn persist_project(self: *Process, project: *Project) !void {
 | 
					    fn persist_project(self: *Process, project: *Project) !void {
 | 
				
			||||||
 | 
					        const no_persist = tp.env.get().is("no-persist");
 | 
				
			||||||
 | 
					        if (no_persist and !project.persistent) return;
 | 
				
			||||||
        tp.trace(tp.channel.debug, .{ "persist_project", project.name });
 | 
					        tp.trace(tp.channel.debug, .{ "persist_project", project.name });
 | 
				
			||||||
        self.logger.print("saving: {s}", .{project.name});
 | 
					        self.logger.print("saving: {s}", .{project.name});
 | 
				
			||||||
        const file_name = try get_project_state_file_path(self.allocator, project);
 | 
					        const file_name = try get_project_state_file_path(self.allocator, project);
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -274,6 +274,21 @@ const cmds = struct {
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    pub const open_project_dir_meta: Meta = .{ .arguments = &.{.string} };
 | 
					    pub const open_project_dir_meta: Meta = .{ .arguments = &.{.string} };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    pub fn close_project(_: *Self, ctx: Ctx) Result {
 | 
				
			||||||
 | 
					        var project_dir: []const u8 = undefined;
 | 
				
			||||||
 | 
					        if (!try ctx.args.match(.{tp.extract(&project_dir)}))
 | 
				
			||||||
 | 
					            return;
 | 
				
			||||||
 | 
					        project_manager.close(project_dir) catch |e| switch (e) {
 | 
				
			||||||
 | 
					            error.CloseCurrentProject => {
 | 
				
			||||||
 | 
					                const logger = log.logger("project");
 | 
				
			||||||
 | 
					                defer logger.deinit();
 | 
				
			||||||
 | 
					                logger.print_err("project", "cannot close current project", .{});
 | 
				
			||||||
 | 
					            },
 | 
				
			||||||
 | 
					            else => return e,
 | 
				
			||||||
 | 
					        };
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    pub const close_project_meta: Meta = .{ .arguments = &.{.string} };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    pub fn change_project(self: *Self, ctx: Ctx) Result {
 | 
					    pub fn change_project(self: *Self, ctx: Ctx) Result {
 | 
				
			||||||
        var project_dir: []const u8 = undefined;
 | 
					        var project_dir: []const u8 = undefined;
 | 
				
			||||||
        if (!try ctx.args.match(.{tp.extract(&project_dir)}))
 | 
					        if (!try ctx.args.match(.{tp.extract(&project_dir)}))
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -2,8 +2,10 @@ const std = @import("std");
 | 
				
			||||||
const cbor = @import("cbor");
 | 
					const cbor = @import("cbor");
 | 
				
			||||||
const tp = @import("thespian");
 | 
					const tp = @import("thespian");
 | 
				
			||||||
const project_manager = @import("project_manager");
 | 
					const project_manager = @import("project_manager");
 | 
				
			||||||
 | 
					const command = @import("command");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
pub const Type = @import("palette.zig").Create(@This());
 | 
					pub const Type = @import("palette.zig").Create(@This());
 | 
				
			||||||
 | 
					const module_name = @typeName(@This());
 | 
				
			||||||
 | 
					
 | 
				
			||||||
pub const label = "Search projects";
 | 
					pub const label = "Search projects";
 | 
				
			||||||
pub const name = " project";
 | 
					pub const name = " project";
 | 
				
			||||||
| 
						 | 
					@ -11,6 +13,7 @@ pub const description = "project";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
pub const Entry = struct {
 | 
					pub const Entry = struct {
 | 
				
			||||||
    label: []const u8,
 | 
					    label: []const u8,
 | 
				
			||||||
 | 
					    open: bool,
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
pub const Match = struct {
 | 
					pub const Match = struct {
 | 
				
			||||||
| 
						 | 
					@ -31,18 +34,28 @@ pub fn load_entries(palette: *Type) !usize {
 | 
				
			||||||
    var len = try cbor.decodeArrayHeader(&iter);
 | 
					    var len = try cbor.decodeArrayHeader(&iter);
 | 
				
			||||||
    while (len > 0) : (len -= 1) {
 | 
					    while (len > 0) : (len -= 1) {
 | 
				
			||||||
        var name_: []const u8 = undefined;
 | 
					        var name_: []const u8 = undefined;
 | 
				
			||||||
        if (try cbor.matchValue(&iter, cbor.extract(&name_))) {
 | 
					        var open: bool = false;
 | 
				
			||||||
            (try palette.entries.addOne()).* = .{ .label = try palette.allocator.dupe(u8, name_) };
 | 
					        if (try cbor.decodeArrayHeader(&iter) != 2)
 | 
				
			||||||
        } else return error.InvalidMessageField;
 | 
					            return error.InvalidMessageField;
 | 
				
			||||||
 | 
					        if (!try cbor.matchValue(&iter, cbor.extract(&name_)))
 | 
				
			||||||
 | 
					            return error.InvalidMessageField;
 | 
				
			||||||
 | 
					        if (!try cbor.matchValue(&iter, cbor.extract(&open)))
 | 
				
			||||||
 | 
					            return error.InvalidMessageField;
 | 
				
			||||||
 | 
					        (try palette.entries.addOne()).* = .{ .label = try palette.allocator.dupe(u8, name_), .open = open };
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    return 1;
 | 
					    return 1;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					pub fn clear_entries(palette: *Type) void {
 | 
				
			||||||
 | 
					    palette.entries.clearRetainingCapacity();
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
pub fn add_menu_entry(palette: *Type, entry: *Entry, matches: ?[]const usize) !void {
 | 
					pub fn add_menu_entry(palette: *Type, entry: *Entry, matches: ?[]const usize) !void {
 | 
				
			||||||
    var value = std.ArrayList(u8).init(palette.allocator);
 | 
					    var value = std.ArrayList(u8).init(palette.allocator);
 | 
				
			||||||
    defer value.deinit();
 | 
					    defer value.deinit();
 | 
				
			||||||
    const writer = value.writer();
 | 
					    const writer = value.writer();
 | 
				
			||||||
    try cbor.writeValue(writer, entry.label);
 | 
					    try cbor.writeValue(writer, entry.label);
 | 
				
			||||||
 | 
					    try cbor.writeValue(writer, if (entry.open) "-" else "");
 | 
				
			||||||
    try cbor.writeValue(writer, matches orelse &[_]usize{});
 | 
					    try cbor.writeValue(writer, matches orelse &[_]usize{});
 | 
				
			||||||
    try palette.menu.add_item_with_handler(value.items, select);
 | 
					    try palette.menu.add_item_with_handler(value.items, select);
 | 
				
			||||||
    palette.items += 1;
 | 
					    palette.items += 1;
 | 
				
			||||||
| 
						 | 
					@ -55,3 +68,11 @@ fn select(menu: **Type.MenuState, button: *Type.ButtonState) void {
 | 
				
			||||||
    tp.self_pid().send(.{ "cmd", "exit_overlay_mode" }) catch |e| menu.*.opts.ctx.logger.err("open_recent_project", e);
 | 
					    tp.self_pid().send(.{ "cmd", "exit_overlay_mode" }) catch |e| menu.*.opts.ctx.logger.err("open_recent_project", e);
 | 
				
			||||||
    tp.self_pid().send(.{ "cmd", "change_project", .{name_} }) catch |e| menu.*.opts.ctx.logger.err("open_recent_project", e);
 | 
					    tp.self_pid().send(.{ "cmd", "change_project", .{name_} }) catch |e| menu.*.opts.ctx.logger.err("open_recent_project", e);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					pub fn delete_item(menu: *Type.MenuState, button: *Type.ButtonState) bool {
 | 
				
			||||||
 | 
					    var name_: []const u8 = undefined;
 | 
				
			||||||
 | 
					    var iter = button.opts.label;
 | 
				
			||||||
 | 
					    if (!(cbor.matchString(&iter, &name_) catch false)) return false;
 | 
				
			||||||
 | 
					    command.executeName("close_project", command.fmt(.{name_})) catch |e| menu.*.opts.ctx.logger.err(module_name, e);
 | 
				
			||||||
 | 
					    return true; //refresh list
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue