From e1973afafc4682042f3d4bec972126734a90cfb6 Mon Sep 17 00:00:00 2001 From: Techatrix <19954306+Techatrix@users.noreply.github.com> Date: Fri, 16 Dec 2022 21:24:03 +0100 Subject: [PATCH] fix cimport duplicate messages & crash (#828) --- src/DocumentStore.zig | 6 +++++- src/Server.zig | 20 -------------------- 2 files changed, 5 insertions(+), 21 deletions(-) diff --git a/src/DocumentStore.zig b/src/DocumentStore.zig index a475af6..13dc1cb 100644 --- a/src/DocumentStore.zig +++ b/src/DocumentStore.zig @@ -317,7 +317,11 @@ fn garbageCollectionCImports(self: *DocumentStore) error{OutOfMemory}!void { continue; } var kv = self.cimports.fetchSwapRemove(hash).?; - std.log.debug("Destroying cimport {s}", .{kv.value.success}); + const message = switch (kv.value) { + .failure => "", + .success => |uri| uri, + }; + std.log.debug("Destroying cimport {s}", .{message}); kv.value.deinit(self.allocator); } } diff --git a/src/Server.zig b/src/Server.zig index 7c38d92..0a7bc8c 100644 --- a/src/Server.zig +++ b/src/Server.zig @@ -180,26 +180,6 @@ fn publishDiagnostics(server: *Server, writer: anytype, handle: DocumentStore.Ha }); } - for (handle.cimports.items(.hash)) |hash, i| { - const result = server.document_store.cimports.get(hash) orelse continue; - if (result != .failure) continue; - const stderr = std.mem.trim(u8, result.failure, " "); - - var pos_and_diag_iterator = std.mem.split(u8, stderr, ":"); - _ = pos_and_diag_iterator.next(); // skip file path - _ = pos_and_diag_iterator.next(); // skip line - _ = pos_and_diag_iterator.next(); // skip character - - const node = handle.cimports.items(.node)[i]; - try diagnostics.append(allocator, .{ - .range = offsets.nodeToRange(handle.tree, node, server.offset_encoding), - .severity = .Error, - .code = "cImport", - .source = "zls", - .message = try allocator.dupe(u8, pos_and_diag_iterator.rest()), - }); - } - if (server.config.enable_ast_check_diagnostics and tree.errors.len == 0) { try getAstCheckDiagnostics(server, handle, &diagnostics); }