Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions src/DiagnosticsCollection.zig
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,26 @@ pub fn clearErrorBundle(collection: *DiagnosticsCollection, tag: Tag) void {
item.error_bundle = .empty;
}

pub fn clearSingleDocumentDiagnostics(collection: *DiagnosticsCollection, document_uri: Uri) void {
const tracy_zone = tracy.trace(@src());
defer tracy_zone.end();

collection.mutex.lock();
defer collection.mutex.unlock();

for (collection.tag_set.values()) |*item| {
var kv = item.diagnostics_set.fetchSwapRemove(document_uri) orelse continue;
kv.value.arena.promote(collection.allocator).deinit();
kv.value.error_bundle.deinit(collection.allocator);

const gop = collection.outdated_files.getOrPut(collection.allocator, kv.key) catch {
kv.key.deinit(collection.allocator);
continue;
};
if (gop.found_existing) kv.key.deinit(collection.allocator);
}
}

fn collectUrisFromErrorBundle(
allocator: std.mem.Allocator,
error_bundle: std.zig.ErrorBundle,
Expand Down
10 changes: 4 additions & 6 deletions src/Server.zig
Original file line number Diff line number Diff line change
Expand Up @@ -1211,12 +1211,10 @@ fn closeDocumentHandler(server: *Server, arena: std.mem.Allocator, notification:
server.document_store.closeLspSyncedDocument(document_uri);

if (server.client_capabilities.supports_publish_diagnostics) {
// clear diagnostics on closed file
const json_message = server.sendToClientNotification("textDocument/publishDiagnostics", .{
.uri = document_uri,
.diagnostics = &.{},
}) catch return;
server.allocator.free(json_message);
server.diagnostics_collection.clearSingleDocumentDiagnostics(document_uri);
server.diagnostics_collection.publishDiagnostics() catch |err| {
std.log.err("failed to publish diagnostics: {}", .{err});
};
}
}

Expand Down
5 changes: 2 additions & 3 deletions src/Uri.zig
Original file line number Diff line number Diff line change
Expand Up @@ -151,9 +151,8 @@ pub fn eql(a: Uri, b: Uri) bool {
return std.mem.eql(u8, a.raw, b.raw);
}

pub fn format(_: Uri, _: *std.Io.Writer) std.Io.Writer.Error!void {
@compileError("Cannot format @import(\"Uri.zig\") directly!. Access the underlying raw string field instead.");
}
pub const format = @compileError("Cannot format @import(\"Uri.zig\") directly!. Access the underlying raw string field instead.");
pub const jsonStringify = @compileError("Cannot stringify @import(\"Uri.zig\") directly!. Access the underlying raw string field instead.");

pub fn ArrayHashMap(comptime V: type) type {
return std.ArrayHashMapUnmanaged(Uri, V, Context, true);
Expand Down