handle AccessDenied when making 'builtin.zig' fill-in

This commit is contained in:
Meghan Denny 2021-12-29 22:53:30 -08:00
parent 304c9bec2f
commit 09d51af161
2 changed files with 6 additions and 3 deletions

View File

@ -1789,7 +1789,7 @@ pub fn main() anyerror!void {
logger.warn("Zig standard library path not specified in zls.json and could not be resolved from the zig executable", .{});
}
if (config.builtin_path == null and config.zig_exe_path != null and config_path != null) {
if (config.builtin_path == null and config.zig_exe_path != null and config_path != null) blk: {
const result = try std.ChildProcess.exec(.{
.allocator = allocator,
.argv = &.{
@ -1805,7 +1805,10 @@ pub fn main() anyerror!void {
var d = try std.fs.cwd().openDir(config_path.?, .{});
defer d.close();
const f = try d.createFile("builtin.zig", .{});
const f = d.createFile("builtin.zig", .{}) catch |err| switch (err) {
error.AccessDenied => break :blk,
else => |e| return e,
};
defer f.close();
try f.writer().writeAll(result.stdout);

View File

@ -111,7 +111,7 @@ fn startZls() !*std.ChildProcess {
var process = try std.ChildProcess.init(&[_][]const u8{"zig-out/bin/zls" ++ suffix}, allocator);
process.stdin_behavior = .Pipe;
process.stdout_behavior = .Pipe;
process.stderr_behavior = .Inherit; //std.ChildProcess.StdIo.Inherit;
process.stderr_behavior = .Inherit;
process.spawn() catch |err| {
std.debug.print("Failed to spawn zls process, error: {}\n", .{err});