Compare commits
No commits in common. "6301c078c80f9de559cc86b406d63811d47a0c78" and "fa397b1642a3e24c34c474776923ab4a380ebb4c" have entirely different histories.
6301c078c8
...
fa397b1642
3 changed files with 18 additions and 44 deletions
|
|
@ -421,44 +421,22 @@ pub fn query_recent_files(self: *Self, from: tp.pid_ref, max: usize, query: []co
|
||||||
return @min(max, matches.items.len);
|
return @min(max, matches.items.len);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn walk_tree_entry_callback(parent: tp.pid_ref, root_path: []const u8, file_path: []const u8, mtime_high: i64, mtime_low: i64) error{Exit}!void {
|
pub fn walk_tree_entry(
|
||||||
|
self: *Self,
|
||||||
|
file_path: []const u8,
|
||||||
|
mtime: i128,
|
||||||
|
) OutOfMemoryError!void {
|
||||||
const file_type: []const u8, const file_icon: []const u8, const file_color: u24 = guess_file_type(file_path);
|
const file_type: []const u8, const file_icon: []const u8, const file_color: u24 = guess_file_type(file_path);
|
||||||
try parent.send(.{ "walk_tree_entry", root_path, file_path, mtime_high, mtime_low, file_type, file_icon, file_color });
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn walk_tree_entry(self: *Self, m: tp.message) OutOfMemoryError!void {
|
|
||||||
var file_path: []const u8 = undefined;
|
|
||||||
var mtime_high: i64 = 0;
|
|
||||||
var mtime_low: i64 = 0;
|
|
||||||
var file_type: []const u8 = undefined;
|
|
||||||
var file_icon: []const u8 = undefined;
|
|
||||||
var file_color: u32 = 0;
|
|
||||||
if (!(cbor.match(m.buf, .{
|
|
||||||
tp.string,
|
|
||||||
tp.string,
|
|
||||||
tp.extract(&file_path),
|
|
||||||
tp.extract(&mtime_high),
|
|
||||||
tp.extract(&mtime_low),
|
|
||||||
tp.extract(&file_type),
|
|
||||||
tp.extract(&file_icon),
|
|
||||||
tp.extract(&file_color),
|
|
||||||
}) catch return)) return;
|
|
||||||
const mtime = (@as(i128, @intCast(mtime_high)) << 64) | @as(i128, @intCast(mtime_low));
|
|
||||||
|
|
||||||
self.longest_file_path = @max(self.longest_file_path, file_path.len);
|
self.longest_file_path = @max(self.longest_file_path, file_path.len);
|
||||||
(try self.pending.addOne(self.allocator)).* = .{
|
(try self.pending.addOne(self.allocator)).* = .{
|
||||||
.path = try self.allocator.dupe(u8, file_path),
|
.path = try self.allocator.dupe(u8, file_path),
|
||||||
.type = file_type,
|
.type = file_type,
|
||||||
.icon = file_icon,
|
.icon = file_icon,
|
||||||
.color = @intCast(file_color),
|
.color = file_color,
|
||||||
.mtime = mtime,
|
.mtime = mtime,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
fn walk_tree_done_callback(parent: tp.pid_ref, root_path: []const u8) error{Exit}!void {
|
|
||||||
try parent.send(.{ "walk_tree_done", root_path });
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn walk_tree_done(self: *Self, parent: tp.pid_ref) OutOfMemoryError!void {
|
pub fn walk_tree_done(self: *Self, parent: tp.pid_ref) OutOfMemoryError!void {
|
||||||
self.state.walk_tree = .done;
|
self.state.walk_tree = .done;
|
||||||
if (self.walker) |pid| pid.deinit();
|
if (self.walker) |pid| pid.deinit();
|
||||||
|
|
@ -2009,7 +1987,7 @@ pub fn query_git(self: *Self) void {
|
||||||
|
|
||||||
fn start_walker(self: *Self) void {
|
fn start_walker(self: *Self) void {
|
||||||
self.state.walk_tree = .running;
|
self.state.walk_tree = .running;
|
||||||
self.walker = walk_tree.start(self.allocator, self.name, walk_tree_entry_callback, walk_tree_done_callback) catch blk: {
|
self.walker = walk_tree.start(self.allocator, self.name) catch blk: {
|
||||||
self.state.walk_tree = .failed;
|
self.state.walk_tree = .failed;
|
||||||
break :blk null;
|
break :blk null;
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -318,6 +318,8 @@ const Process = struct {
|
||||||
var method: []const u8 = undefined;
|
var method: []const u8 = undefined;
|
||||||
var cbor_id: []const u8 = undefined;
|
var cbor_id: []const u8 = undefined;
|
||||||
var params_cb: []const u8 = undefined;
|
var params_cb: []const u8 = undefined;
|
||||||
|
var high: i64 = 0;
|
||||||
|
var low: i64 = 0;
|
||||||
var max: usize = 0;
|
var max: usize = 0;
|
||||||
var row: usize = 0;
|
var row: usize = 0;
|
||||||
var col: usize = 0;
|
var col: usize = 0;
|
||||||
|
|
@ -336,9 +338,10 @@ const Process = struct {
|
||||||
|
|
||||||
var eol_mode: Buffer.EolModeTag = @intFromEnum(Buffer.EolMode.lf);
|
var eol_mode: Buffer.EolModeTag = @intFromEnum(Buffer.EolMode.lf);
|
||||||
|
|
||||||
if (try cbor.match(m.buf, .{ "walk_tree_entry", tp.extract(&project_directory), tp.more })) {
|
if (try cbor.match(m.buf, .{ "walk_tree_entry", tp.extract(&project_directory), tp.extract(&path), tp.extract(&high), tp.extract(&low) })) {
|
||||||
|
const mtime = (@as(i128, @intCast(high)) << 64) | @as(i128, @intCast(low));
|
||||||
if (self.projects.get(project_directory)) |project|
|
if (self.projects.get(project_directory)) |project|
|
||||||
project.walk_tree_entry(m) catch |e| self.logger.err("walk_tree_entry", e);
|
project.walk_tree_entry(path, mtime) catch |e| self.logger.err("walk_tree_entry", e);
|
||||||
} else if (try cbor.match(m.buf, .{ "walk_tree_done", tp.extract(&project_directory) })) {
|
} else if (try cbor.match(m.buf, .{ "walk_tree_done", tp.extract(&project_directory) })) {
|
||||||
if (self.projects.get(project_directory)) |project|
|
if (self.projects.get(project_directory)) |project|
|
||||||
project.walk_tree_done(self.parent.ref()) catch |e| return from.forward_error(e, @errorReturnTrace()) catch error.ClientFailed;
|
project.walk_tree_done(self.parent.ref()) catch |e| return from.forward_error(e, @errorReturnTrace()) catch error.ClientFailed;
|
||||||
|
|
|
||||||
|
|
@ -7,10 +7,7 @@ const module_name = @typeName(@This());
|
||||||
const SpawnError = (OutOfMemoryError || error{ThespianSpawnFailed});
|
const SpawnError = (OutOfMemoryError || error{ThespianSpawnFailed});
|
||||||
const OutOfMemoryError = error{OutOfMemory};
|
const OutOfMemoryError = error{OutOfMemory};
|
||||||
|
|
||||||
pub const EntryCallBack = *const fn (parent: tp.pid_ref, root_path: []const u8, path: []const u8, mtime_high: i64, mtime_low: i64) error{Exit}!void;
|
pub fn start(a_: std.mem.Allocator, root_path_: []const u8) (SpawnError || std.fs.Dir.OpenError)!tp.pid {
|
||||||
pub const DoneCallBack = *const fn (parent: tp.pid_ref, root_path: []const u8) error{Exit}!void;
|
|
||||||
|
|
||||||
pub fn start(a_: std.mem.Allocator, root_path_: []const u8, entry_handler: EntryCallBack, done_handler: DoneCallBack) (SpawnError || std.fs.Dir.OpenError)!tp.pid {
|
|
||||||
return struct {
|
return struct {
|
||||||
allocator: std.mem.Allocator,
|
allocator: std.mem.Allocator,
|
||||||
root_path: []const u8,
|
root_path: []const u8,
|
||||||
|
|
@ -18,13 +15,11 @@ pub fn start(a_: std.mem.Allocator, root_path_: []const u8, entry_handler: Entry
|
||||||
receiver: Receiver,
|
receiver: Receiver,
|
||||||
dir: std.fs.Dir,
|
dir: std.fs.Dir,
|
||||||
walker: FilteredWalker,
|
walker: FilteredWalker,
|
||||||
entry_handler: EntryCallBack,
|
|
||||||
done_handler: DoneCallBack,
|
|
||||||
|
|
||||||
const tree_walker = @This();
|
const tree_walker = @This();
|
||||||
const Receiver = tp.Receiver(*tree_walker);
|
const Receiver = tp.Receiver(*tree_walker);
|
||||||
|
|
||||||
fn spawn_link(allocator: std.mem.Allocator, root_path: []const u8, entry_handler_: EntryCallBack, done_handler_: DoneCallBack) (SpawnError || std.fs.Dir.OpenError)!tp.pid {
|
fn spawn_link(allocator: std.mem.Allocator, root_path: []const u8) (SpawnError || std.fs.Dir.OpenError)!tp.pid {
|
||||||
const self = try allocator.create(tree_walker);
|
const self = try allocator.create(tree_walker);
|
||||||
errdefer allocator.destroy(self);
|
errdefer allocator.destroy(self);
|
||||||
self.* = .{
|
self.* = .{
|
||||||
|
|
@ -34,8 +29,6 @@ pub fn start(a_: std.mem.Allocator, root_path_: []const u8, entry_handler: Entry
|
||||||
.receiver = .init(tree_walker.receive, self),
|
.receiver = .init(tree_walker.receive, self),
|
||||||
.dir = try std.fs.cwd().openDir(self.root_path, .{ .iterate = true }),
|
.dir = try std.fs.cwd().openDir(self.root_path, .{ .iterate = true }),
|
||||||
.walker = try .init(self.dir, self.allocator),
|
.walker = try .init(self.dir, self.allocator),
|
||||||
.entry_handler = entry_handler_,
|
|
||||||
.done_handler = done_handler_,
|
|
||||||
};
|
};
|
||||||
return tp.spawn_link(allocator, self, tree_walker.start, module_name ++ ".tree_walker");
|
return tp.spawn_link(allocator, self, tree_walker.start, module_name ++ ".tree_walker");
|
||||||
}
|
}
|
||||||
|
|
@ -72,21 +65,21 @@ pub fn start(a_: std.mem.Allocator, root_path_: []const u8, entry_handler: Entry
|
||||||
fn next(self: *tree_walker) !void {
|
fn next(self: *tree_walker) !void {
|
||||||
if (try self.walker.next()) |path| {
|
if (try self.walker.next()) |path| {
|
||||||
const stat = self.dir.statFile(path) catch {
|
const stat = self.dir.statFile(path) catch {
|
||||||
try self.entry_handler(self.parent.ref(), self.root_path, path, 0, 0);
|
try self.parent.send(.{ "walk_tree_entry", self.root_path, path, 0, 0 });
|
||||||
return tp.self_pid().send(.{"next"});
|
return tp.self_pid().send(.{"next"});
|
||||||
};
|
};
|
||||||
const mtime = stat.mtime;
|
const mtime = stat.mtime;
|
||||||
const high: i64 = @intCast(mtime >> 64);
|
const high: i64 = @intCast(mtime >> 64);
|
||||||
const low: i64 = @truncate(mtime);
|
const low: i64 = @truncate(mtime);
|
||||||
std.debug.assert(mtime == (@as(i128, @intCast(high)) << 64) | @as(i128, @intCast(low)));
|
std.debug.assert(mtime == (@as(i128, @intCast(high)) << 64) | @as(i128, @intCast(low)));
|
||||||
try self.entry_handler(self.parent.ref(), self.root_path, path, high, low);
|
try self.parent.send(.{ "walk_tree_entry", self.root_path, path, high, low });
|
||||||
return tp.self_pid().send(.{"next"});
|
return tp.self_pid().send(.{"next"});
|
||||||
} else {
|
} else {
|
||||||
self.done_handler(self.parent.ref(), self.root_path) catch {};
|
self.parent.send(.{ "walk_tree_done", self.root_path }) catch {};
|
||||||
return tp.exit_normal();
|
return tp.exit_normal();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}.spawn_link(a_, root_path_, entry_handler, done_handler);
|
}.spawn_link(a_, root_path_);
|
||||||
}
|
}
|
||||||
|
|
||||||
const filtered_dirs = [_][]const u8{
|
const filtered_dirs = [_][]const u8{
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue