From 04951e7e9b00f65f9980039e6fae61e3b646c4c8 Mon Sep 17 00:00:00 2001 From: CJ van den Berg Date: Tue, 9 Sep 2025 11:58:19 +0200 Subject: [PATCH] feat: add support for bracketed file link syntax These file links are produced by MS compilers. e.g: dir/file.cs(12,15): --- src/file_link.zig | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/src/file_link.zig b/src/file_link.zig index aac4cfa..4d86200 100644 --- a/src/file_link.zig +++ b/src/file_link.zig @@ -21,6 +21,15 @@ pub const DirDest = struct { pub fn parse(link: []const u8) error{InvalidFileLink}!Dest { if (link.len == 0) return error.InvalidFileLink; + + if (std.mem.lastIndexOfScalar(u8, link, '(')) |pos| blk: { + for (link[pos + 1 ..]) |c| switch (c) { + '0'...'9', ',', ')', ':' => continue, + else => break :blk, + }; + return parse_bracket_link(link); + } + var it = std.mem.splitScalar(u8, link, ':'); var dest: Dest = if (root.is_directory(link)) .{ .dir = .{ .path = link } } @@ -46,6 +55,36 @@ pub fn parse(link: []const u8) error{InvalidFileLink}!Dest { return dest; } +pub fn parse_bracket_link(link: []const u8) error{InvalidFileLink}!Dest { + var it_ = std.mem.splitScalar(u8, link, '('); + var dest: Dest = if (root.is_directory(link)) + .{ .dir = .{ .path = link } } + else + .{ .file = .{ .path = it_.first() } }; + + const rest = it_.next() orelse ""; + var it = std.mem.splitAny(u8, rest, ",):"); + + switch (dest) { + .file => |*file| { + if (it.next()) |line_| + 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; + }; + if (file.column) |_| if (it.next()) |col_| { + file.end_column = std.fmt.parseInt(usize, col_, 10) catch null; + }; + file.exists = root.is_file(file.path); + }, + .dir => {}, + } + return dest; +} + pub fn navigate(to: tp.pid_ref, link: *const Dest) anyerror!void { switch (link.*) { .file => |file| {