refactor: store file positions in project in a struct
This commit is contained in:
parent
048ef98c8d
commit
5f7b28db5f
1 changed files with 12 additions and 9 deletions
|
@ -36,9 +36,13 @@ pub const LspOrClientError = (LspError || ClientError);
|
||||||
const File = struct {
|
const File = struct {
|
||||||
path: []const u8,
|
path: []const u8,
|
||||||
mtime: i128,
|
mtime: i128,
|
||||||
|
pos: FilePos = .{},
|
||||||
|
visited: bool = false,
|
||||||
|
};
|
||||||
|
|
||||||
|
pub const FilePos = struct {
|
||||||
row: usize = 0,
|
row: usize = 0,
|
||||||
col: usize = 0,
|
col: usize = 0,
|
||||||
visited: bool = false,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const Task = struct {
|
const Task = struct {
|
||||||
|
@ -94,9 +98,9 @@ pub fn write_state_v1(self: *Self, writer: anytype) !void {
|
||||||
try cbor.writeArrayHeader(writer, 4);
|
try cbor.writeArrayHeader(writer, 4);
|
||||||
try cbor.writeValue(writer, file.path);
|
try cbor.writeValue(writer, file.path);
|
||||||
try cbor.writeValue(writer, file.mtime);
|
try cbor.writeValue(writer, file.mtime);
|
||||||
try cbor.writeValue(writer, file.row);
|
try cbor.writeValue(writer, file.pos.row);
|
||||||
try cbor.writeValue(writer, file.col);
|
try cbor.writeValue(writer, file.pos.col);
|
||||||
tp.trace(tp.channel.debug, .{ "write_state_v1", "file", file.path, file.mtime, file.row, file.col });
|
tp.trace(tp.channel.debug, .{ "write_state_v1", "file", file.path, file.mtime, file.pos.row, file.pos.col });
|
||||||
}
|
}
|
||||||
try cbor.writeArrayHeader(writer, self.tasks.items.len);
|
try cbor.writeArrayHeader(writer, self.tasks.items.len);
|
||||||
tp.trace(tp.channel.debug, .{ "write_state_v1", "tasks", self.tasks.items.len });
|
tp.trace(tp.channel.debug, .{ "write_state_v1", "tasks", self.tasks.items.len });
|
||||||
|
@ -374,7 +378,7 @@ pub fn merge_pending_files(self: *Self) OutOfMemoryError!void {
|
||||||
self.files = self.pending;
|
self.files = self.pending;
|
||||||
self.pending = std.ArrayList(File).init(self.allocator);
|
self.pending = std.ArrayList(File).init(self.allocator);
|
||||||
for (existing) |*file| {
|
for (existing) |*file| {
|
||||||
self.update_mru_internal(file.path, file.mtime, file.row, file.col) catch {};
|
self.update_mru_internal(file.path, file.mtime, file.pos.row, file.pos.col) catch {};
|
||||||
self.allocator.free(file.path);
|
self.allocator.free(file.path);
|
||||||
}
|
}
|
||||||
self.allocator.free(existing);
|
self.allocator.free(existing);
|
||||||
|
@ -390,8 +394,8 @@ fn update_mru_internal(self: *Self, file_path: []const u8, mtime: i128, row: usi
|
||||||
if (!std.mem.eql(u8, file.path, file_path)) continue;
|
if (!std.mem.eql(u8, file.path, file_path)) continue;
|
||||||
file.mtime = mtime;
|
file.mtime = mtime;
|
||||||
if (row != 0) {
|
if (row != 0) {
|
||||||
file.row = row;
|
file.pos.row = row;
|
||||||
file.col = col;
|
file.pos.col = col;
|
||||||
file.visited = true;
|
file.visited = true;
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
|
@ -400,8 +404,7 @@ fn update_mru_internal(self: *Self, file_path: []const u8, mtime: i128, row: usi
|
||||||
(try self.files.addOne()).* = .{
|
(try self.files.addOne()).* = .{
|
||||||
.path = try self.allocator.dupe(u8, file_path),
|
.path = try self.allocator.dupe(u8, file_path),
|
||||||
.mtime = mtime,
|
.mtime = mtime,
|
||||||
.row = row,
|
.pos = .{ .row = row, .col = col },
|
||||||
.col = col,
|
|
||||||
.visited = true,
|
.visited = true,
|
||||||
};
|
};
|
||||||
} else {
|
} else {
|
||||||
|
|
Loading…
Add table
Reference in a new issue