feat: allow to update vcs changed files info for current project

This commit is contained in:
Igor Támara 2025-10-25 08:31:45 -05:00 committed by CJ van den Berg
parent 8d0fa9a355
commit fdf2b6d376
3 changed files with 20 additions and 0 deletions

View file

@ -2174,6 +2174,8 @@ pub fn query_git(self: *Self) void {
self.state.status = .failed;
};
// TODO: This needs to be invoked when there are identified changes in the fs
for (self.new_or_modified_files.items) |file| self.allocator.free(file.path);
self.new_or_modified_files.clearRetainingCapacity();
self.state.vcs_new_or_modified_files = .running;
git.new_or_modified_files(@intFromPtr(self)) catch {
self.state.vcs_new_or_modified_files = .failed;

View file

@ -105,6 +105,13 @@ pub fn request_new_or_modified_files(max: usize) (ProjectManagerError || Project
return send(.{ "request_new_or_modified_files", project, max });
}
pub fn request_sync_with_vcs() (ProjectManagerError || ProjectError)!void {
const project = tp.env.get().str("project");
if (project.len == 0)
return error.NoProject;
return send(.{ "sync_with_vcs", project });
}
pub fn request_recent_projects() (ProjectManagerError || ProjectError)!void {
const project = tp.env.get().str("project");
return send(.{ "request_recent_projects", project });
@ -386,6 +393,8 @@ const Process = struct {
self.request_recent_files(from, project_directory, max) catch |e| return from.forward_error(e, @errorReturnTrace()) catch error.ClientFailed;
} else if (try cbor.match(m.buf, .{ "request_new_or_modified_files", tp.extract(&project_directory), tp.extract(&max) })) {
self.request_new_or_modified_files(from, project_directory, max) catch |e| return from.forward_error(e, @errorReturnTrace()) catch error.ClientFailed;
} else if (try cbor.match(m.buf, .{ "sync_with_vcs", tp.extract(&project_directory) })) {
self.request_sync_with_vcs(from, project_directory) catch |e| return from.forward_error(e, @errorReturnTrace()) catch error.ClientFailed;
} else if (try cbor.match(m.buf, .{ "request_recent_projects", tp.extract(&project_directory) })) {
self.request_recent_projects(from, project_directory) catch |e| return from.forward_error(e, @errorReturnTrace()) catch error.ClientFailed;
} else if (try cbor.match(m.buf, .{ "query_recent_files", tp.extract(&project_directory), tp.extract(&max), tp.extract(&query) })) {
@ -486,6 +495,11 @@ const Process = struct {
return project.request_recent_files(from, max);
}
fn request_sync_with_vcs(self: *Process, _: tp.pid_ref, project_directory: []const u8) (ProjectError || Project.ClientError)!void {
const project = self.projects.get(project_directory) orelse return error.NoProject;
return project.query_git();
}
fn request_new_or_modified_files(self: *Process, from: tp.pid_ref, project_directory: []const u8, max: usize) (ProjectError || Project.ClientError)!void {
const project = self.projects.get(project_directory) orelse return error.NoProject;
return project.request_new_or_modified_files(from, max);

View file

@ -1370,6 +1370,10 @@ pub fn mainview() ?*MainView {
return if (current().mainview_) |*mv| mv.dynamic_cast(MainView) else null;
}
pub fn sync_with_vcs() !void {
try project_manager.request_sync_with_vcs();
}
pub fn mainview_widget() Widget {
return current().mainview_ orelse @panic("tui main view not found");
}