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}`
This commit is contained in:
parent
7c5a22c959
commit
219b8cd00a
1 changed files with 11 additions and 1 deletions
|
@ -13,6 +13,7 @@ pub const FileDest = struct {
|
||||||
column: ?usize = null,
|
column: ?usize = null,
|
||||||
end_column: ?usize = null,
|
end_column: ?usize = null,
|
||||||
exists: bool = false,
|
exists: bool = false,
|
||||||
|
offset: ?usize = null,
|
||||||
};
|
};
|
||||||
|
|
||||||
pub const DirDest = struct {
|
pub const DirDest = struct {
|
||||||
|
@ -37,11 +38,17 @@ pub fn parse(link: []const u8) error{InvalidFileLink}!Dest {
|
||||||
.{ .file = .{ .path = it.first() } };
|
.{ .file = .{ .path = it.first() } };
|
||||||
switch (dest) {
|
switch (dest) {
|
||||||
.file => |*file| {
|
.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.line = std.fmt.parseInt(usize, line_, 10) catch blk: {
|
||||||
file.path = link;
|
file.path = link;
|
||||||
break :blk null;
|
break :blk null;
|
||||||
};
|
};
|
||||||
|
};
|
||||||
if (file.line) |_| if (it.next()) |col_| {
|
if (file.line) |_| if (it.next()) |col_| {
|
||||||
file.column = std.fmt.parseInt(usize, col_, 10) catch null;
|
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 {
|
pub fn navigate(to: tp.pid_ref, link: *const Dest) anyerror!void {
|
||||||
switch (link.*) {
|
switch (link.*) {
|
||||||
.file => |file| {
|
.file => |file| {
|
||||||
|
if (file.offset) |offset| {
|
||||||
|
return to.send(.{ "cmd", "navigate", .{ .file = file.path, .offset = offset } });
|
||||||
|
}
|
||||||
if (file.line) |l| {
|
if (file.line) |l| {
|
||||||
if (file.column) |col| {
|
if (file.column) |col| {
|
||||||
try to.send(.{ "cmd", "navigate", .{ .file = file.path, .line = l, .column = col } });
|
try to.send(.{ "cmd", "navigate", .{ .file = file.path, .line = l, .column = col } });
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue