feat: add byte offset support to vim style '+' cli arguments

This adds support for using `+b{offset}` on the command line.
This commit is contained in:
CJ van den Berg 2025-09-17 22:46:35 +02:00
parent 219b8cd00a
commit 7228a604b0
Signed by: neurocyte
GPG key ID: 8EB1E1BB660E3FB9

View file

@ -245,19 +245,34 @@ pub fn main() anyerror!void {
defer links.deinit(); defer links.deinit();
var prev: ?*file_link.Dest = null; var prev: ?*file_link.Dest = null;
var line_next: ?usize = null; var line_next: ?usize = null;
var offset_next: ?usize = null;
for (positional_args.items) |arg| { for (positional_args.items) |arg| {
if (arg.len == 0) continue; if (arg.len == 0) continue;
if (!args.literal and arg[0] == '+') { if (!args.literal and arg[0] == '+') {
const line = try std.fmt.parseInt(usize, arg[1..], 10); if (arg.len > 2 and arg[1] == 'b') {
if (prev) |p| switch (p.*) { const offset = try std.fmt.parseInt(usize, arg[2..], 10);
.file => |*file| { if (prev) |p| switch (p.*) {
file.line = line; .file => |*file| {
continue; file.offset = offset;
}, continue;
else => {}, },
}; else => {},
line_next = line; };
offset_next = offset;
line_next = null;
} else {
const line = try std.fmt.parseInt(usize, arg[1..], 10);
if (prev) |p| switch (p.*) {
.file => |*file| {
file.line = line;
continue;
},
else => {},
};
line_next = line;
offset_next = null;
}
continue; continue;
} }
@ -274,6 +289,15 @@ pub fn main() anyerror!void {
else => {}, else => {},
} }
} }
if (offset_next) |offset| {
switch (curr.*) {
.file => |*file| {
file.offset = offset;
offset_next = null;
},
else => {},
}
}
} }
var have_project = false; var have_project = false;