feat: add support for bracketed file link syntax
These file links are produced by MS compilers. e.g: dir/file.cs(12,15):
This commit is contained in:
		
							parent
							
								
									fda9338a06
								
							
						
					
					
						commit
						04951e7e9b
					
				
					 1 changed files with 39 additions and 0 deletions
				
			
		|  | @ -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| { | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue