feat: open most recent file on project switch
This commit is contained in:
parent
53310cc2dd
commit
bd27db46d1
3 changed files with 27 additions and 0 deletions
|
@ -45,6 +45,16 @@ pub fn open(rel_project_directory: []const u8) !void {
|
|||
return (try get()).pid.send(.{ "open", project_directory });
|
||||
}
|
||||
|
||||
pub fn request_most_recent_file(a: std.mem.Allocator) !?[]const u8 {
|
||||
const project = tp.env.get().str("project");
|
||||
if (project.len == 0)
|
||||
return tp.exit("No project");
|
||||
const rsp = try (try get()).pid.call(a, request_timeout, .{ "request_most_recent_file", project });
|
||||
defer a.free(rsp.buf);
|
||||
var file_path: []const u8 = undefined;
|
||||
return if (try rsp.match(.{tp.extract(&file_path)})) try a.dupe(u8, file_path) else null;
|
||||
}
|
||||
|
||||
pub fn request_recent_files(max: usize) !void {
|
||||
const project = tp.env.get().str("project");
|
||||
if (project.len == 0)
|
||||
|
@ -225,6 +235,8 @@ const Process = struct {
|
|||
self.logger.print_err("lsp-handling", "child '{s}' terminated", .{path});
|
||||
} else if (try m.match(.{ "open", tp.extract(&project_directory) })) {
|
||||
self.open(project_directory) catch |e| return from.forward_error(e, @errorReturnTrace());
|
||||
} else if (try m.match(.{ "request_most_recent_file", tp.extract(&project_directory) })) {
|
||||
self.request_most_recent_file(from, project_directory) catch |e| return from.forward_error(e, @errorReturnTrace());
|
||||
} else if (try m.match(.{ "request_recent_files", tp.extract(&project_directory), tp.extract(&max) })) {
|
||||
self.request_recent_files(from, project_directory, max) catch |e| return from.forward_error(e, @errorReturnTrace());
|
||||
} else if (try m.match(.{ "request_recent_projects", tp.extract(&project_directory) })) {
|
||||
|
@ -286,6 +298,12 @@ const Process = struct {
|
|||
});
|
||||
}
|
||||
|
||||
fn request_most_recent_file(self: *Process, from: tp.pid_ref, project_directory: []const u8) error{ OutOfMemory, Exit }!void {
|
||||
const project = if (self.projects.get(project_directory)) |p| p else return tp.exit("No project");
|
||||
project.sort_files_by_mtime();
|
||||
return project.request_most_recent_file(from);
|
||||
}
|
||||
|
||||
fn request_recent_files(self: *Process, from: tp.pid_ref, project_directory: []const u8, max: usize) error{ OutOfMemory, Exit }!void {
|
||||
const project = if (self.projects.get(project_directory)) |p| p else return tp.exit("No project");
|
||||
project.sort_files_by_mtime();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue