···164164/// Saves the text to the current location based on the `filename` field.
165165pub fn saveFile(self: *Editor, gpa: std.mem.Allocator) !void {
166166 if (self.language) |*l| format_text: {
167167- const formatted = l.formatter.format(gpa, self.text.items) catch break :format_text;
167167+ const formatted = l.formatter.format(gpa, self.text.items) catch {
168168+ std.log.debug("failed to format buffer", .{});
169169+ break :format_text;
170170+ };
168171 defer gpa.free(formatted);
172172+173173+ // If, for whatever reason, the formatter doesn't return anything, we likely do not want to
174174+ // actually empty the text buffer, so we do nothing in that case.
175175+ if (std.mem.eql(u8, formatted, "")) break :format_text;
176176+177177+ std.log.debug("formatted source:\n{s}", .{formatted});
169178170179 self.text.clearRetainingCapacity();
171180 try self.text.ensureTotalCapacity(gpa, formatted.len);