From e469d8171f008ce070415df06a1422461f002e17 Mon Sep 17 00:00:00 2001 From: MineBill Date: Tue, 30 Nov 2021 18:50:02 +0200 Subject: [PATCH] Fixes errors that are caused by using deprecated functions --- src/DocumentStore.zig | 18 +++++++++--------- src/analysis.zig | 2 +- src/header.zig | 2 +- src/main.zig | 8 ++++---- src/setup.zig | 2 +- src/unit_tests.zig | 8 ++++---- 6 files changed, 20 insertions(+), 20 deletions(-) diff --git a/src/DocumentStore.zig b/src/DocumentStore.zig index 4954665..8ea9adb 100644 --- a/src/DocumentStore.zig +++ b/src/DocumentStore.zig @@ -154,7 +154,7 @@ fn loadPackages(context: LoadPackagesContext) !void { const pkg_uri = try URI.fromPath(allocator, pkg_abs_path); errdefer allocator.free(pkg_uri); - const duped_name = try std.mem.dupe(allocator, u8, name); + const duped_name = try allocator.dupe(u8, name); errdefer allocator.free(duped_name); (try build_file.packages.addOne(allocator)).* = .{ @@ -209,7 +209,7 @@ fn newDocument(self: *DocumentStore, uri: []const u8, text: [:0]u8) anyerror!*Ha build_file.* = .{ .refs = 1, - .uri = try std.mem.dupe(self.allocator, u8, uri), + .uri = try self.allocator.dupe(u8, uri), .packages = .{}, }; @@ -337,9 +337,9 @@ pub fn openDocument(self: *DocumentStore, uri: []const u8, text: []const u8) !*H return entry.value_ptr.*; } - const duped_text = try std.mem.dupeZ(self.allocator, u8, text); + const duped_text = try self.allocator.dupeZ(u8, text); errdefer self.allocator.free(duped_text); - const duped_uri = try std.mem.dupe(self.allocator, u8, uri); + const duped_uri = try self.allocator.dupeZ(u8, uri); errdefer self.allocator.free(duped_uri); return try self.newDocument(duped_uri, duped_text); @@ -565,14 +565,14 @@ pub fn applyChanges(self: *DocumentStore, handle: *Handle, content_changes: std. pub fn uriFromImportStr(self: *DocumentStore, allocator: *std.mem.Allocator, handle: Handle, import_str: []const u8) !?[]const u8 { if (std.mem.eql(u8, import_str, "std")) { - if (self.std_uri) |uri| return try std.mem.dupe(allocator, u8, uri) else { + if (self.std_uri) |uri| return try allocator.dupe(u8, uri) else { log.debug("Cannot resolve std library import, path is null.", .{}); return null; } } else if (std.mem.eql(u8, import_str, "builtin")) { if (handle.associated_build_file) |build_file| { if (build_file.builtin_uri) |builtin_uri| { - return try std.mem.dupe(allocator, u8, builtin_uri); + return try allocator.dupe(u8, builtin_uri); } } return null; // TODO find the correct zig-cache folder @@ -580,7 +580,7 @@ pub fn uriFromImportStr(self: *DocumentStore, allocator: *std.mem.Allocator, han if (handle.associated_build_file) |build_file| { for (build_file.packages.items) |pkg| { if (std.mem.eql(u8, import_str, pkg.name)) { - return try std.mem.dupe(allocator, u8, pkg.uri); + return try allocator.dupe(u8, pkg.uri); } } } @@ -670,7 +670,7 @@ pub fn resolveImport(self: *DocumentStore, handle: *Handle, import_str: []const try handle.imports_used.append(self.allocator, handle_uri); // Swap handles. // This takes ownership of the passed uri and text. - const duped_final_uri = try std.mem.dupe(allocator, u8, final_uri); + const duped_final_uri = try allocator.dupe(u8, final_uri); errdefer allocator.free(duped_final_uri); return try self.newDocument(duped_final_uri, file_contents); } @@ -734,7 +734,7 @@ fn tagStoreCompletionItems(self: DocumentStore, arena: *std.heap.ArenaAllocator, } var result_set = analysis.CompletionSet{}; - try result_set.ensureCapacity(&arena.allocator, max_len); + try result_set.ensureTotalCapacity(&arena.allocator, max_len); for (@field(base.document_scope, name).entries.items(.key)) |completion| { result_set.putAssumeCapacityNoClobber(completion, {}); } diff --git a/src/analysis.zig b/src/analysis.zig index 98242c4..4379590 100644 --- a/src/analysis.zig +++ b/src/analysis.zig @@ -98,7 +98,7 @@ pub fn getFunctionSnippet(allocator: *std.mem.Allocator, tree: Ast, func: Ast.fu const name_index = func.name_token.?; var buffer = std.ArrayList(u8).init(allocator); - try buffer.ensureCapacity(128); + try buffer.ensureTotalCapacity(128); try buffer.appendSlice(tree.tokenSlice(name_index)); try buffer.append('('); diff --git a/src/header.zig b/src/header.zig index 80577bc..7c215fc 100644 --- a/src/header.zig +++ b/src/header.zig @@ -32,7 +32,7 @@ pub fn readRequestHeader(allocator: *std.mem.Allocator, instream: anytype) !Requ r.content_length = std.fmt.parseInt(usize, header_value, 10) catch return error.InvalidContentLength; has_content_length = true; } else if (std.mem.eql(u8, header_name, "Content-Type")) { - r.content_type = try std.mem.dupe(allocator, u8, header_value); + r.content_type = try allocator.dupe(u8, header_value); } else { return error.UnknownHeader; } diff --git a/src/main.zig b/src/main.zig index 193dfeb..a17797d 100644 --- a/src/main.zig +++ b/src/main.zig @@ -209,7 +209,7 @@ fn publishDiagnostics(arena: *std.heap.ArenaAllocator, handle: DocumentStore.Han .severity = .Error, .code = @tagName(err.tag), .source = "zls", - .message = try std.mem.dupe(&arena.allocator, u8, fbs.getWritten()), + .message = try arena.allocator.dupe(u8, fbs.getWritten()), // .relatedInformation = undefined }); } @@ -1769,7 +1769,7 @@ pub fn main() anyerror!void { &std.json.TokenStream.init(zig_env_result.stdout), .{ .allocator = allocator }, ) catch { - logger.alert("Failed to parse zig env JSON result", .{}); + logger.err("Failed to parse zig env JSON result", .{}); break :find_lib_path; }; defer std.json.parseFree(Env, json_env, .{ .allocator = allocator }); @@ -1779,7 +1779,7 @@ pub fn main() anyerror!void { logger.info("Using zig lib path '{s}'", .{config.zig_lib_path}); } }, - else => logger.alert("zig env invocation failed", .{}), + else => logger.err("zig env invocation failed", .{}), } } } else { @@ -1828,7 +1828,7 @@ pub fn main() anyerror!void { while (keep_running) { const headers = readRequestHeader(&arena.allocator, reader) catch |err| { - logger.crit("{s}; exiting!", .{@errorName(err)}); + logger.err("{s}; exiting!", .{@errorName(err)}); return; }; const buf = try arena.allocator.alloc(u8, headers.content_length); diff --git a/src/setup.zig b/src/setup.zig index 94ab7a0..4a7adc3 100644 --- a/src/setup.zig +++ b/src/setup.zig @@ -96,7 +96,7 @@ pub fn wizard(allocator: *std.mem.Allocator) !void { else => 1024 * 1024, }; - std.debug.warn("Writing config to {s}/zls.json ... ", .{config_path}); + std.debug.print("Writing config to {s}/zls.json ... \n", .{config_path}); try std.json.stringify(.{ .zig_exe_path = zig_exe_path, diff --git a/src/unit_tests.zig b/src/unit_tests.zig index d104269..59c1175 100644 --- a/src/unit_tests.zig +++ b/src/unit_tests.zig @@ -39,13 +39,13 @@ fn testContext(comptime line: []const u8, comptime tag: anytype, comptime range: const ctx = try analysis.documentPositionContext(&arena, doc, p); if (std.meta.activeTag(ctx) != tag) { - std.debug.warn("Expected tag {}, got {}\n", .{ tag, std.meta.activeTag(ctx) }); + std.debug.print("Expected tag {}, got {}\n", .{ tag, std.meta.activeTag(ctx) }); return error.DifferentTag; } if (ctx.range()) |ctx_range| { if (range == null) { - std.debug.warn("Expected null range, got `{s}`\n", .{ + std.debug.print("Expected null range, got `{s}`\n", .{ doc.text[ctx_range.start..ctx_range.end], }); } else { @@ -53,7 +53,7 @@ fn testContext(comptime line: []const u8, comptime tag: anytype, comptime range: const range_end = range_start + range.?.len; if (range_start != ctx_range.start or range_end != ctx_range.end) { - std.debug.warn("Expected range `{s}` ({}..{}), got `{s}` ({}..{})\n", .{ + std.debug.print("Expected range `{s}` ({}..{}), got `{s}` ({}..{})\n", .{ doc.text[range_start..range_end], range_start, range_end, doc.text[ctx_range.start..ctx_range.end], ctx_range.start, ctx_range.end, }); @@ -61,7 +61,7 @@ fn testContext(comptime line: []const u8, comptime tag: anytype, comptime range: } } } else if (range != null) { - std.debug.warn("Unexpected null range\n", .{}); + std.debug.print("Unexpected null range\n", .{}); return error.DifferentRange; } }