diff --git a/src/Project.zig b/src/Project.zig index a15a2c0..e9ce980 100644 --- a/src/Project.zig +++ b/src/Project.zig @@ -418,8 +418,7 @@ 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 { for (self.files.items) |*file| { if (!std.mem.eql(u8, file.path, file_path)) continue; - if (file.row != 0) - from.send(.{ "cmd", "goto_line_and_column", .{ file.row + 1, file.col + 1 } }) catch return error.ClientFailed; + from.send(.{ file.pos.row, file.pos.col }) catch return error.ClientFailed; return; } } diff --git a/src/project_manager.zig b/src/project_manager.zig index b749397..7a7ff2b 100644 --- a/src/project_manager.zig +++ b/src/project_manager.zig @@ -16,6 +16,8 @@ const Self = @This(); const module_name = @typeName(Self); const request_timeout = std.time.ns_per_s * 5; +pub const FilePos = Project.FilePos; + pub const Error = ProjectError || ProjectManagerError; pub const ProjectError = error{NoProject}; @@ -226,11 +228,16 @@ pub fn update_mru(file_path: []const u8, row: usize, col: usize, ephemeral: bool return send(.{ "update_mru", project, file_path, row, col }); } -pub fn get_mru_position(file_path: []const u8) (ProjectManagerError || ProjectError)!void { +pub fn get_mru_position(allocator: std.mem.Allocator, file_path: []const u8) (ProjectManagerError || ProjectError || CallError || cbor.Error)!?Project.FilePos { + const frame = tracy.initZone(@src(), .{ .name = "get_mru_position" }); + defer frame.deinit(); const project = tp.env.get().str("project"); if (project.len == 0) return error.NoProject; - return send(.{ "get_mru_position", project, file_path }); + const rsp = try (try get()).pid.call(allocator, request_timeout, .{ "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 { diff --git a/src/tui/mainview.zig b/src/tui/mainview.zig index 1bc11e9..3fd2331 100644 --- a/src/tui/mainview.zig +++ b/src/tui/mainview.zig @@ -359,6 +359,12 @@ const cmds = struct { 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; + 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 (self.get_active_editor()) |editor| { editor.send_editor_jump_source() catch {}; @@ -374,9 +380,6 @@ const cmds = struct { try command.executeName("scroll_view_center", .{}); if (column) |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(); }