fix cimport duplicate messages & crash (#828)

This commit is contained in:
Techatrix 2022-12-16 21:24:03 +01:00 committed by GitHub
parent 68ac6f9f30
commit e1973afafc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 5 additions and 21 deletions

View File

@ -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);
}
}

View File

@ -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);
}