From dc0d5dda80749e89b6900350dcbbdc452ec2186c Mon Sep 17 00:00:00 2001 From: CJ van den Berg Date: Sun, 28 Dec 2025 22:02:22 +0100 Subject: [PATCH 1/3] fix: Never walk into AppData as that is likely not useful closes #438 --- src/walk_tree.zig | 1 + 1 file changed, 1 insertion(+) diff --git a/src/walk_tree.zig b/src/walk_tree.zig index 6c0e3e7..c88bbeb 100644 --- a/src/walk_tree.zig +++ b/src/walk_tree.zig @@ -90,6 +90,7 @@ pub fn start(a_: std.mem.Allocator, root_path_: []const u8, entry_handler: Entry } const filtered_dirs = [_][]const u8{ + "AppData", ".cache", ".cargo", ".git", From 865ec97c16f5c8873d6fa64334442943ff0e73af Mon Sep 17 00:00:00 2001 From: CJ van den Berg Date: Sun, 28 Dec 2025 22:12:03 +0100 Subject: [PATCH 2/3] refactor: unify URI to file path decoding in one location --- src/Project.zig | 41 ++++++++++++----------------------------- 1 file changed, 12 insertions(+), 29 deletions(-) diff --git a/src/Project.zig b/src/Project.zig index 50ba2f3..d123dca 100644 --- a/src/Project.zig +++ b/src/Project.zig @@ -990,25 +990,26 @@ fn send_goto_request(self: *Self, from: tp.pid_ref, file_path: []const u8, row: } fn file_uri_to_path(uri: []const u8, file_path_buf: []u8) error{InvalidTargetURI}![]u8 { - return std.Uri.percentDecodeBackwards(file_path_buf, if (std.mem.eql(u8, uri[0..7], "file://")) + const file_path = std.Uri.percentDecodeBackwards(file_path_buf, if (std.mem.eql(u8, uri[0..7], "file://")) uri[7..] else if (std.mem.eql(u8, uri[0..5], "file:")) uri[5..] else return error.InvalidTargetURI); -} - -fn navigate_to_location_link(from: tp.pid_ref, location_link: []const u8) (error{InvalidTargetURI} || LocationLinkError)!void { - const location: LocationLink = try read_locationlink(location_link); - if (location.targetUri == null or location.targetRange == null) return error.InvalidLocationLink; - var file_path_buf: [std.fs.max_path_bytes]u8 = undefined; - var file_path = try file_uri_to_path(location.targetUri.?, &file_path_buf); if (builtin.os.tag == .windows) { if (file_path[0] == '/') file_path = file_path[1..]; for (file_path, 0..) |c, i| if (c == '/') { file_path[i] = '\\'; }; } + return file_path; +} + +fn navigate_to_location_link(from: tp.pid_ref, location_link: []const u8) (error{InvalidTargetURI} || LocationLinkError)!void { + const location: LocationLink = try read_locationlink(location_link); + if (location.targetUri == null or location.targetRange == null) return error.InvalidLocationLink; + var file_path_buf: [std.fs.max_path_bytes]u8 = undefined; + const file_path = try file_uri_to_path(location.targetUri.?, &file_path_buf); if (location.targetSelectionRange) |sel| { from.send(.{ "cmd", "navigate", .{ .file = file_path, @@ -1134,13 +1135,7 @@ fn send_reference(tag: []const u8, to: tp.pid_ref, location_: []const u8, name: const location: LocationLink = try read_locationlink(location_); if (location.targetUri == null or location.targetRange == null) return error.InvalidLocationLink; var file_path_buf: [std.fs.max_path_bytes]u8 = undefined; - var file_path = try file_uri_to_path(location.targetUri.?, &file_path_buf); - if (builtin.os.tag == .windows) { - if (file_path[0] == '/') file_path = file_path[1..]; - for (file_path, 0..) |c, i| if (c == '/') { - file_path[i] = '\\'; - }; - } + const file_path = try file_uri_to_path(location.targetUri.?, &file_path_buf); const line = try get_line_of_file(allocator, file_path, location.targetRange.?.start.line); defer allocator.free(line); const file_path_ = if (file_path.len > name.len and std.mem.eql(u8, name, file_path[0..name.len])) @@ -1407,13 +1402,7 @@ fn send_symbol_information(to: tp.pid_ref, file_path: []const u8, item: []const if (location) |location_| { if (location_.targetUri == null or location_.targetRange == null) return error.InvalidSymbolInformationField; var file_path_buf: [std.fs.max_path_bytes]u8 = undefined; - var file_path_ = try file_uri_to_path(location_.targetUri.?, &file_path_buf); - if (builtin.os.tag == .windows) { - if (file_path_[0] == '/') file_path_ = file_path_[1..]; - for (file_path_, 0..) |c, i| if (c == '/') { - file_path_[i] = '\\'; - }; - } + const file_path_ = try file_uri_to_path(location_.targetUri.?, &file_path_buf); fp = file_path_; to.send(.{ "cmd", "add_symbol_information", .{ fp, name, parent_name, kind, location_.targetRange.?.start.line, location_.targetRange.?.start.character, location_.targetRange.?.end.line, location_.targetRange.?.end.character, tags[0..len_tags_], location_.targetSelectionRange.?.start.line, location_.targetSelectionRange.?.start.character, location_.targetSelectionRange.?.end.line, location_.targetSelectionRange.?.end.character, deprecated, location_.targetUri } }) catch |e| { std.log.err("send add_symbol_information failed: {t}", .{e}); @@ -1622,13 +1611,7 @@ pub fn rename_symbol(self: *Self, from: tp.pid_ref, file_path: []const u8, row: try cbor.writeArrayHeader(w, renames.items.len); for (renames.items) |rename| { var file_path_buf: [std.fs.max_path_bytes]u8 = undefined; - var file_path_ = try file_uri_to_path(rename.uri, &file_path_buf); - if (builtin.os.tag == .windows) { - if (file_path_[0] == '/') file_path_ = file_path_[1..]; - for (file_path_, 0..) |c, i| if (c == '/') { - file_path_[i] = '\\'; - }; - } + const file_path_ = try file_uri_to_path(rename.uri, &file_path_buf); const line = try get_line_of_file(allocator, self_.file_path, rename.range.start.line); try cbor.writeValue(w, .{ file_path_, From 0e3f7c8c1c3a85d7ee322aacf9c8f680415d55f8 Mon Sep 17 00:00:00 2001 From: CJ van den Berg Date: Sun, 28 Dec 2025 22:20:41 +0100 Subject: [PATCH 3/3] fix: convert file paths returned by git on windows --- src/Project.zig | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/Project.zig b/src/Project.zig index d123dca..26da36e 100644 --- a/src/Project.zig +++ b/src/Project.zig @@ -996,6 +996,10 @@ fn file_uri_to_path(uri: []const u8, file_path_buf: []u8) error{InvalidTargetURI uri[5..] else return error.InvalidTargetURI); + return convert_path(file_path); +} + +fn convert_path(file_path: []u8) []u8 { if (builtin.os.tag == .windows) { if (file_path[0] == '/') file_path = file_path[1..]; for (file_path, 0..) |c, i| if (c == '/') { @@ -2628,7 +2632,7 @@ pub fn process_git(self: *Self, parent: tp.pid_ref, m: tp.message) (OutOfMemoryE try self.loaded(parent); } else if (try m.match(.{ tp.any, tp.any, "workspace_path", tp.extract(&value) })) { if (self.workspace) |p| self.allocator.free(p); - self.workspace = try self.allocator.dupe(u8, value); + self.workspace = convert_path(try self.allocator.dupe(u8, value)); self.state.workspace_path = .done; self.state.workspace_files = .running; git.workspace_files(@intFromPtr(self)) catch { @@ -2659,7 +2663,7 @@ pub fn process_git(self: *Self, parent: tp.pid_ref, m: tp.message) (OutOfMemoryE }; const file_type: []const u8, const file_icon: []const u8, const file_color: u24 = guess_file_type(path); (try self.pending.addOne(self.allocator)).* = .{ - .path = try self.allocator.dupe(u8, path), + .path = convert_path(try self.allocator.dupe(u8, path)), .type = file_type, .icon = file_icon, .color = file_color, @@ -2675,7 +2679,7 @@ pub fn process_git(self: *Self, parent: tp.pid_ref, m: tp.message) (OutOfMemoryE self.longest_new_or_modified_file_path = @max(self.longest_new_or_modified_file_path, path.len); const file_type: []const u8, const file_icon: []const u8, const file_color: u24 = guess_file_type(path); (try self.new_or_modified_files.addOne(self.allocator)).* = .{ - .path = try self.allocator.dupe(u8, path), + .path = convert_path(try self.allocator.dupe(u8, path)), .type = file_type, .icon = file_icon, .color = file_color,