Fixes errors that are caused by using deprecated functions
This commit is contained in:
		
							parent
							
								
									7793b7250c
								
							
						
					
					
						commit
						e469d8171f
					
				@ -154,7 +154,7 @@ fn loadPackages(context: LoadPackagesContext) !void {
 | 
				
			|||||||
                        const pkg_uri = try URI.fromPath(allocator, pkg_abs_path);
 | 
					                        const pkg_uri = try URI.fromPath(allocator, pkg_abs_path);
 | 
				
			||||||
                        errdefer allocator.free(pkg_uri);
 | 
					                        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);
 | 
					                        errdefer allocator.free(duped_name);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                        (try build_file.packages.addOne(allocator)).* = .{
 | 
					                        (try build_file.packages.addOne(allocator)).* = .{
 | 
				
			||||||
@ -209,7 +209,7 @@ fn newDocument(self: *DocumentStore, uri: []const u8, text: [:0]u8) anyerror!*Ha
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
        build_file.* = .{
 | 
					        build_file.* = .{
 | 
				
			||||||
            .refs = 1,
 | 
					            .refs = 1,
 | 
				
			||||||
            .uri = try std.mem.dupe(self.allocator, u8, uri),
 | 
					            .uri = try self.allocator.dupe(u8, uri),
 | 
				
			||||||
            .packages = .{},
 | 
					            .packages = .{},
 | 
				
			||||||
        };
 | 
					        };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -337,9 +337,9 @@ pub fn openDocument(self: *DocumentStore, uri: []const u8, text: []const u8) !*H
 | 
				
			|||||||
        return entry.value_ptr.*;
 | 
					        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);
 | 
					    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);
 | 
					    errdefer self.allocator.free(duped_uri);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    return try self.newDocument(duped_uri, duped_text);
 | 
					    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 {
 | 
					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 (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.", .{});
 | 
					            log.debug("Cannot resolve std library import, path is null.", .{});
 | 
				
			||||||
            return null;
 | 
					            return null;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
    } else if (std.mem.eql(u8, import_str, "builtin")) {
 | 
					    } else if (std.mem.eql(u8, import_str, "builtin")) {
 | 
				
			||||||
        if (handle.associated_build_file) |build_file| {
 | 
					        if (handle.associated_build_file) |build_file| {
 | 
				
			||||||
            if (build_file.builtin_uri) |builtin_uri| {
 | 
					            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
 | 
					        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| {
 | 
					        if (handle.associated_build_file) |build_file| {
 | 
				
			||||||
            for (build_file.packages.items) |pkg| {
 | 
					            for (build_file.packages.items) |pkg| {
 | 
				
			||||||
                if (std.mem.eql(u8, import_str, pkg.name)) {
 | 
					                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);
 | 
					        try handle.imports_used.append(self.allocator, handle_uri);
 | 
				
			||||||
        // Swap handles.
 | 
					        // Swap handles.
 | 
				
			||||||
        // This takes ownership of the passed uri and text.
 | 
					        // 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);
 | 
					        errdefer allocator.free(duped_final_uri);
 | 
				
			||||||
        return try self.newDocument(duped_final_uri, file_contents);
 | 
					        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{};
 | 
					    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| {
 | 
					    for (@field(base.document_scope, name).entries.items(.key)) |completion| {
 | 
				
			||||||
        result_set.putAssumeCapacityNoClobber(completion, {});
 | 
					        result_set.putAssumeCapacityNoClobber(completion, {});
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
				
			|||||||
@ -98,7 +98,7 @@ pub fn getFunctionSnippet(allocator: *std.mem.Allocator, tree: Ast, func: Ast.fu
 | 
				
			|||||||
    const name_index = func.name_token.?;
 | 
					    const name_index = func.name_token.?;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    var buffer = std.ArrayList(u8).init(allocator);
 | 
					    var buffer = std.ArrayList(u8).init(allocator);
 | 
				
			||||||
    try buffer.ensureCapacity(128);
 | 
					    try buffer.ensureTotalCapacity(128);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    try buffer.appendSlice(tree.tokenSlice(name_index));
 | 
					    try buffer.appendSlice(tree.tokenSlice(name_index));
 | 
				
			||||||
    try buffer.append('(');
 | 
					    try buffer.append('(');
 | 
				
			||||||
 | 
				
			|||||||
@ -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;
 | 
					            r.content_length = std.fmt.parseInt(usize, header_value, 10) catch return error.InvalidContentLength;
 | 
				
			||||||
            has_content_length = true;
 | 
					            has_content_length = true;
 | 
				
			||||||
        } else if (std.mem.eql(u8, header_name, "Content-Type")) {
 | 
					        } 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 {
 | 
					        } else {
 | 
				
			||||||
            return error.UnknownHeader;
 | 
					            return error.UnknownHeader;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
				
			|||||||
@ -209,7 +209,7 @@ fn publishDiagnostics(arena: *std.heap.ArenaAllocator, handle: DocumentStore.Han
 | 
				
			|||||||
            .severity = .Error,
 | 
					            .severity = .Error,
 | 
				
			||||||
            .code = @tagName(err.tag),
 | 
					            .code = @tagName(err.tag),
 | 
				
			||||||
            .source = "zls",
 | 
					            .source = "zls",
 | 
				
			||||||
            .message = try std.mem.dupe(&arena.allocator, u8, fbs.getWritten()),
 | 
					            .message = try arena.allocator.dupe(u8, fbs.getWritten()),
 | 
				
			||||||
            // .relatedInformation = undefined
 | 
					            // .relatedInformation = undefined
 | 
				
			||||||
        });
 | 
					        });
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
@ -1769,7 +1769,7 @@ pub fn main() anyerror!void {
 | 
				
			|||||||
                            &std.json.TokenStream.init(zig_env_result.stdout),
 | 
					                            &std.json.TokenStream.init(zig_env_result.stdout),
 | 
				
			||||||
                            .{ .allocator = allocator },
 | 
					                            .{ .allocator = allocator },
 | 
				
			||||||
                        ) catch {
 | 
					                        ) catch {
 | 
				
			||||||
                            logger.alert("Failed to parse zig env JSON result", .{});
 | 
					                            logger.err("Failed to parse zig env JSON result", .{});
 | 
				
			||||||
                            break :find_lib_path;
 | 
					                            break :find_lib_path;
 | 
				
			||||||
                        };
 | 
					                        };
 | 
				
			||||||
                        defer std.json.parseFree(Env, json_env, .{ .allocator = allocator });
 | 
					                        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});
 | 
					                        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 {
 | 
					    } else {
 | 
				
			||||||
@ -1828,7 +1828,7 @@ pub fn main() anyerror!void {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    while (keep_running) {
 | 
					    while (keep_running) {
 | 
				
			||||||
        const headers = readRequestHeader(&arena.allocator, reader) catch |err| {
 | 
					        const headers = readRequestHeader(&arena.allocator, reader) catch |err| {
 | 
				
			||||||
            logger.crit("{s}; exiting!", .{@errorName(err)});
 | 
					            logger.err("{s}; exiting!", .{@errorName(err)});
 | 
				
			||||||
            return;
 | 
					            return;
 | 
				
			||||||
        };
 | 
					        };
 | 
				
			||||||
        const buf = try arena.allocator.alloc(u8, headers.content_length);
 | 
					        const buf = try arena.allocator.alloc(u8, headers.content_length);
 | 
				
			||||||
 | 
				
			|||||||
@ -96,7 +96,7 @@ pub fn wizard(allocator: *std.mem.Allocator) !void {
 | 
				
			|||||||
        else => 1024 * 1024,
 | 
					        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(.{
 | 
					    try std.json.stringify(.{
 | 
				
			||||||
        .zig_exe_path = zig_exe_path,
 | 
					        .zig_exe_path = zig_exe_path,
 | 
				
			||||||
 | 
				
			|||||||
@ -39,13 +39,13 @@ fn testContext(comptime line: []const u8, comptime tag: anytype, comptime range:
 | 
				
			|||||||
    const ctx = try analysis.documentPositionContext(&arena, doc, p);
 | 
					    const ctx = try analysis.documentPositionContext(&arena, doc, p);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if (std.meta.activeTag(ctx) != tag) {
 | 
					    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;
 | 
					        return error.DifferentTag;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if (ctx.range()) |ctx_range| {
 | 
					    if (ctx.range()) |ctx_range| {
 | 
				
			||||||
        if (range == null) {
 | 
					        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],
 | 
					                doc.text[ctx_range.start..ctx_range.end],
 | 
				
			||||||
            });
 | 
					            });
 | 
				
			||||||
        } else {
 | 
					        } else {
 | 
				
			||||||
@ -53,7 +53,7 @@ fn testContext(comptime line: []const u8, comptime tag: anytype, comptime range:
 | 
				
			|||||||
            const range_end = range_start + range.?.len;
 | 
					            const range_end = range_start + range.?.len;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            if (range_start != ctx_range.start or range_end != ctx_range.end) {
 | 
					            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[range_start..range_end],         range_start,     range_end,
 | 
				
			||||||
                    doc.text[ctx_range.start..ctx_range.end], ctx_range.start, ctx_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) {
 | 
					    } else if (range != null) {
 | 
				
			||||||
        std.debug.warn("Unexpected null range\n", .{});
 | 
					        std.debug.print("Unexpected null range\n", .{});
 | 
				
			||||||
        return error.DifferentRange;
 | 
					        return error.DifferentRange;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
		Reference in New Issue
	
	Block a user