From ca58cbb3f3667e872d8ae2ee1a8c4a1192ef4509 Mon Sep 17 00:00:00 2001 From: Techatrix <19954306+Techatrix@users.noreply.github.com> Date: Sun, 25 Sep 2022 01:01:31 +0200 Subject: [PATCH] make types.Diagnostic correctly parseable --- src/Server.zig | 6 +++--- src/types.zig | 8 ++++---- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/Server.zig b/src/Server.zig index 1221f6c..05fe650 100644 --- a/src/Server.zig +++ b/src/Server.zig @@ -335,10 +335,10 @@ fn getAstCheckDiagnostics( } else if (std.mem.startsWith(u8, msg, "note: ")) { var latestDiag = &diagnostics.items[diagnostics.items.len - 1]; - var fresh = if (latestDiag.relatedInformation.len == 0) - try server.arena.allocator().alloc(types.DiagnosticRelatedInformation, 1) + var fresh = if (latestDiag.relatedInformation) |related_information| + try server.arena.allocator().realloc(@ptrCast([]types.DiagnosticRelatedInformation, related_information), related_information.len + 1) else - try server.arena.allocator().realloc(@ptrCast([]types.DiagnosticRelatedInformation, latestDiag.relatedInformation), latestDiag.relatedInformation.len + 1); + try server.arena.allocator().alloc(types.DiagnosticRelatedInformation, 1); const location = types.Location{ .uri = handle.uri(), diff --git a/src/types.zig b/src/types.zig index 2bee392..1ce356a 100644 --- a/src/types.zig +++ b/src/types.zig @@ -117,11 +117,11 @@ pub const DiagnosticRelatedInformation = struct { pub const Diagnostic = struct { range: Range, - severity: DiagnosticSeverity, - code: string, - source: string, + severity: ?DiagnosticSeverity, + code: ?string, + source: ?string, message: string, - relatedInformation: []const DiagnosticRelatedInformation = &.{}, + relatedInformation: ?[]const DiagnosticRelatedInformation = null, }; pub const TextDocument = struct {