From 219b8cd00a3dcd1bd3bba994b97fd079ee183bed Mon Sep 17 00:00:00 2001 From: CJ van den Berg Date: Wed, 17 Sep 2025 22:42:25 +0200 Subject: [PATCH] feat: support byte offsets in file links This adds support for a 'b' prefix to the first file link argument to denote a byte offset. `{path/to/file.ext}:b{offset}` --- src/file_link.zig | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/file_link.zig b/src/file_link.zig index ec53f39..cc3b817 100644 --- a/src/file_link.zig +++ b/src/file_link.zig @@ -13,6 +13,7 @@ pub const FileDest = struct { column: ?usize = null, end_column: ?usize = null, exists: bool = false, + offset: ?usize = null, }; pub const DirDest = struct { @@ -37,11 +38,17 @@ pub fn parse(link: []const u8) error{InvalidFileLink}!Dest { .{ .file = .{ .path = it.first() } }; switch (dest) { .file => |*file| { - if (it.next()) |line_| + if (it.next()) |line_| if (line_.len > 0 and line_[0] == 'b') { + file.offset = std.fmt.parseInt(usize, line_[1..], 10) catch blk: { + file.path = link; + break :blk null; + }; + } else { file.line = std.fmt.parseInt(usize, line_, 10) catch blk: { file.path = link; break :blk null; }; + }; if (file.line) |_| if (it.next()) |col_| { file.column = std.fmt.parseInt(usize, col_, 10) catch null; }; @@ -88,6 +95,9 @@ pub fn parse_bracket_link(link: []const u8) error{InvalidFileLink}!Dest { pub fn navigate(to: tp.pid_ref, link: *const Dest) anyerror!void { switch (link.*) { .file => |file| { + if (file.offset) |offset| { + return to.send(.{ "cmd", "navigate", .{ .file = file.path, .offset = offset } }); + } if (file.line) |l| { if (file.column) |col| { try to.send(.{ "cmd", "navigate", .{ .file = file.path, .line = l, .column = col } });