From 75677f424c994c615105c59b3c71b385adb38db8 Mon Sep 17 00:00:00 2001 From: Techatrix <19954306+Techatrix@users.noreply.github.com> Date: Sun, 11 Sep 2022 21:50:37 +0200 Subject: [PATCH 1/2] place build_runner.zig in zls subfolder --- src/Config.zig | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/src/Config.zig b/src/Config.zig index bb19677..74d44c0 100644 --- a/src/Config.zig +++ b/src/Config.zig @@ -202,13 +202,19 @@ pub fn configChanged(config: *Config, allocator: std.mem.Allocator, builtin_crea config.builtin_path = try std.fs.path.join(allocator, &.{ builtin_creation_dir.?, "builtin.zig" }); } - const cache_dir_path = (try known_folders.getPath(allocator, .cache)) orelse { - logger.warn("Known-folders could not fetch the cache path", .{}); - return; - }; + + if (null == config.global_cache_path) { + const cache_dir_path = (try known_folders.getPath(allocator, .cache)) orelse { + logger.warn("Known-folders could not fetch the cache path", .{}); + return; + }; + defer allocator.free(cache_dir_path); + + config.global_cache_path = try std.fs.path.resolve(allocator, &[_][]const u8{ cache_dir_path, "zls" }); + } if (null == config.build_runner_path) { - config.build_runner_path = try std.fs.path.resolve(allocator, &[_][]const u8{ cache_dir_path, "build_runner.zig" }); + config.build_runner_path = try std.fs.path.resolve(allocator, &[_][]const u8{ config.global_cache_path.?, "build_runner.zig" }); const file = try std.fs.createFileAbsolute(config.build_runner_path.?, .{}); defer file.close(); @@ -216,8 +222,4 @@ pub fn configChanged(config: *Config, allocator: std.mem.Allocator, builtin_crea try file.writeAll(@embedFile("special/build_runner.zig")); } - if (null == config.global_cache_path) { - defer allocator.free(cache_dir_path); - config.global_cache_path = try std.fs.path.resolve(allocator, &[_][]const u8{ cache_dir_path, "zls" }); - } } From 834127f23e241826db132f51ea62fa307f57af56 Mon Sep 17 00:00:00 2001 From: Techatrix <19954306+Techatrix@users.noreply.github.com> Date: Sun, 11 Sep 2022 22:36:38 +0200 Subject: [PATCH 2/2] create global cache path directory if it doesn't exist yet --- src/Config.zig | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/Config.zig b/src/Config.zig index 74d44c0..77ba0b2 100644 --- a/src/Config.zig +++ b/src/Config.zig @@ -211,6 +211,11 @@ pub fn configChanged(config: *Config, allocator: std.mem.Allocator, builtin_crea defer allocator.free(cache_dir_path); config.global_cache_path = try std.fs.path.resolve(allocator, &[_][]const u8{ cache_dir_path, "zls" }); + + std.fs.makeDirAbsolute(config.global_cache_path.?) catch |err| switch(err) { + error.PathAlreadyExists => {}, + else => return err, + }; } if (null == config.build_runner_path) {