Skip to content

Commit

Permalink
remove diagnostics when stopping build on save
Browse files Browse the repository at this point in the history
  • Loading branch information
Techatrix committed Dec 31, 2024
1 parent 8d8eb29 commit b36f7c4
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
23 changes: 23 additions & 0 deletions src/DiagnosticsCollection.zig
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,29 @@ pub fn pushErrorBundle(
}
}

pub fn clearErrorBundle(collection: *DiagnosticsCollection, tag: Tag) void {
collection.mutex.lock();
defer collection.mutex.unlock();

const item = collection.tag_set.getPtr(tag) orelse return;

collectUrisFromErrorBundle(
collection.allocator,
item.error_bundle,
item.error_bundle_src_base_path,
&collection.outdated_files,
) catch |err| switch (err) {
error.OutOfMemory => return,
};

if (item.error_bundle_src_base_path) |base_path| {
collection.allocator.free(base_path);
item.error_bundle_src_base_path = null;
}
item.error_bundle.deinit(collection.allocator);
item.error_bundle = .empty;
}

fn collectUrisFromErrorBundle(
allocator: std.mem.Allocator,
error_bundle: std.zig.ErrorBundle,
Expand Down
10 changes: 10 additions & 0 deletions src/features/diagnostics.zig
Original file line number Diff line number Diff line change
Expand Up @@ -551,6 +551,12 @@ pub const BuildOnSave = struct {
});
defer transport.deinit();

var diagnostic_tags: std.AutoArrayHashMapUnmanaged(DiagnosticsCollection.Tag, void) = .empty;
defer {
for (diagnostic_tags.keys()) |tag| collection.clearErrorBundle(tag);
collection.publishDiagnostics() catch {};
}

while (true) {
const header = transport.receiveMessage(null) catch |err| switch (err) {
error.EndOfStream => {
Expand All @@ -570,6 +576,7 @@ pub const BuildOnSave = struct {
&transport,
collection,
workspace_path,
&diagnostic_tags,
) catch |err| {
log.err("failed to handle error bundle message from zig build runner: {}", .{err});
return;
Expand All @@ -587,6 +594,7 @@ pub const BuildOnSave = struct {
transport: *Transport,
collection: *DiagnosticsCollection,
workspace_path: []const u8,
diagnostic_tags: *std.AutoArrayHashMapUnmanaged(DiagnosticsCollection.Tag, void),
) !void {
const header = try transport.reader().readStructEndian(ServerToClient.ErrorBundle, .little);

Expand All @@ -604,6 +612,8 @@ pub const BuildOnSave = struct {

const diagnostic_tag: DiagnosticsCollection.Tag = @enumFromInt(@as(u32, @truncate(hasher.final())));

try diagnostic_tags.put(self.allocator, diagnostic_tag, {});

try collection.pushErrorBundle(diagnostic_tag, header.cycle, workspace_path, error_bundle);
try collection.publishDiagnostics();
}
Expand Down

0 comments on commit b36f7c4

Please sign in to comment.