From c355a54dd1072fafa1c4b37d6f1d2b5b31255475 Mon Sep 17 00:00:00 2001 From: Auguste Rame <19855629+SuperAuguste@users.noreply.github.com> Date: Mon, 19 Dec 2022 16:01:08 -0500 Subject: [PATCH] Fix raw, responseless returns on willSaveWaitUntil (#833) * Fix raw, responseless returns on willSaveWaitUntil * Make this code pretty --- src/Server.zig | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/src/Server.zig b/src/Server.zig index 874d23a..588af8e 100644 --- a/src/Server.zig +++ b/src/Server.zig @@ -1879,20 +1879,28 @@ fn willSaveWaitUntilHandler(server: *Server, writer: anytype, id: types.RequestI const tracy_zone = tracy.trace(@src()); defer tracy_zone.end(); - if (!server.config.enable_ast_check_diagnostics) return; - if (!server.config.enable_autofix) return; - const allocator = server.arena.allocator(); - const uri = req.params.textDocument.uri; - const handle = server.document_store.getHandle(uri) orelse return; - if (handle.tree.errors.len != 0) return; + b: { + if (!server.config.enable_ast_check_diagnostics or !server.config.enable_autofix) + break :b; - var text_edits = try server.autofix(allocator, handle); + const uri = req.params.textDocument.uri; + + const handle = server.document_store.getHandle(uri) orelse break :b; + if (handle.tree.errors.len != 0) break :b; + + var text_edits = try server.autofix(allocator, handle); + + return try send(writer, allocator, types.Response{ + .id = id, + .result = .{ .TextEdits = try text_edits.toOwnedSlice(allocator) }, + }); + } return try send(writer, allocator, types.Response{ .id = id, - .result = .{ .TextEdits = try text_edits.toOwnedSlice(allocator) }, + .result = .{ .TextEdits = &.{} }, }); }