Compare commits

..

No commits in common. "2a76da6cf619b954c4d61e31b4e4d9ab0f8a54fa" and "048ef98c8d245dedc8ac0a9619bd322701a9abfd" have entirely different histories.

3 changed files with 16 additions and 28 deletions

View file

@ -36,13 +36,9 @@ 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 {
@ -98,9 +94,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.pos.row); try cbor.writeValue(writer, file.row);
try cbor.writeValue(writer, file.pos.col); try cbor.writeValue(writer, file.col);
tp.trace(tp.channel.debug, .{ "write_state_v1", "file", file.path, file.mtime, file.pos.row, file.pos.col }); tp.trace(tp.channel.debug, .{ "write_state_v1", "file", file.path, file.mtime, file.row, file.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 });
@ -378,7 +374,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.pos.row, file.pos.col) catch {}; self.update_mru_internal(file.path, file.mtime, file.row, file.col) catch {};
self.allocator.free(file.path); self.allocator.free(file.path);
} }
self.allocator.free(existing); self.allocator.free(existing);
@ -394,8 +390,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.pos.row = row; file.row = row;
file.pos.col = col; file.col = col;
file.visited = true; file.visited = true;
} }
return; return;
@ -404,7 +400,8 @@ 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,
.pos = .{ .row = row, .col = col }, .row = row,
.col = col,
.visited = true, .visited = true,
}; };
} else { } else {
@ -418,7 +415,8 @@ fn update_mru_internal(self: *Self, file_path: []const u8, mtime: i128, row: usi
pub fn get_mru_position(self: *Self, from: tp.pid_ref, file_path: []const u8) ClientError!void { pub fn get_mru_position(self: *Self, from: tp.pid_ref, file_path: []const u8) ClientError!void {
for (self.files.items) |*file| { for (self.files.items) |*file| {
if (!std.mem.eql(u8, file.path, file_path)) continue; if (!std.mem.eql(u8, file.path, file_path)) continue;
from.send(.{ file.pos.row, file.pos.col }) catch return error.ClientFailed; if (file.row != 0)
from.send(.{ "cmd", "goto_line_and_column", .{ file.row + 1, file.col + 1 } }) catch return error.ClientFailed;
return; return;
} }
} }

View file

@ -16,8 +16,6 @@ const Self = @This();
const module_name = @typeName(Self); const module_name = @typeName(Self);
const request_timeout = std.time.ns_per_s * 5; const request_timeout = std.time.ns_per_s * 5;
pub const FilePos = Project.FilePos;
pub const Error = ProjectError || ProjectManagerError; pub const Error = ProjectError || ProjectManagerError;
pub const ProjectError = error{NoProject}; pub const ProjectError = error{NoProject};
@ -228,16 +226,11 @@ pub fn update_mru(file_path: []const u8, row: usize, col: usize, ephemeral: bool
return send(.{ "update_mru", project, file_path, row, col }); return send(.{ "update_mru", project, file_path, row, col });
} }
pub fn get_mru_position(allocator: std.mem.Allocator, file_path: []const u8) (ProjectManagerError || ProjectError || CallError || cbor.Error)!?Project.FilePos { pub fn get_mru_position(file_path: []const u8) (ProjectManagerError || ProjectError)!void {
const frame = tracy.initZone(@src(), .{ .name = "get_mru_position" });
defer frame.deinit();
const project = tp.env.get().str("project"); const project = tp.env.get().str("project");
if (project.len == 0) if (project.len == 0)
return error.NoProject; return error.NoProject;
const rsp = try (try get()).pid.call(allocator, request_timeout, .{ "get_mru_position", project, file_path }); return send(.{ "get_mru_position", project, file_path });
defer allocator.free(rsp.buf);
var pos: Project.FilePos = undefined;
return if (try cbor.match(rsp.buf, .{ tp.extract(&pos.row), tp.extract(&pos.col) })) pos else null;
} }
const Process = struct { const Process = struct {

View file

@ -359,12 +359,6 @@ const cmds = struct {
const same_file = if (self.get_active_file_path()) |fp| std.mem.eql(u8, fp, f) else false; const same_file = if (self.get_active_file_path()) |fp| std.mem.eql(u8, fp, f) else false;
const have_editor_metadata = if (self.buffer_manager.get_buffer_for_file(f)) |_| true else false; const have_editor_metadata = if (self.buffer_manager.get_buffer_for_file(f)) |_| true else false;
if (!same_file and !have_editor_metadata)
if (try project_manager.get_mru_position(self.allocator, f)) |pos| {
line = @intCast(pos.row);
column = @intCast(pos.col);
};
if (!same_file) { if (!same_file) {
if (self.get_active_editor()) |editor| { if (self.get_active_editor()) |editor| {
editor.send_editor_jump_source() catch {}; editor.send_editor_jump_source() catch {};
@ -380,6 +374,9 @@ const cmds = struct {
try command.executeName("scroll_view_center", .{}); try command.executeName("scroll_view_center", .{});
if (column) |col| if (column) |col|
try command.executeName("goto_column", command.fmt(.{col})); try command.executeName("goto_column", command.fmt(.{col}));
} else {
if (!same_file and !have_editor_metadata)
try project_manager.get_mru_position(f);
} }
tui.need_render(); tui.need_render();
} }