Minor cleanup in formatting function

This commit is contained in:
Jeffery Stager 2022-08-13 17:23:39 -04:00
parent 254353a9f4
commit 1fbf1c5427

View File

@ -2234,11 +2234,11 @@ fn formattingHandler(server: *Server, writer: anytype, id: types.RequestId, req:
edits.deinit(); edits.deinit();
} }
// Convert from `[]diff.Edit` to `[]types.TextEdit`
var text_edits = try std var text_edits = try std
.ArrayList(types.TextEdit) .ArrayList(types.TextEdit)
.initCapacity(server.allocator, edits.items.len); .initCapacity(server.allocator, edits.items.len);
defer text_edits.deinit(); defer text_edits.deinit();
for (edits.items) |edit| { for (edits.items) |edit| {
try text_edits.append(.{ try text_edits.append(.{
.range = edit.range, .range = edit.range,
@ -2246,14 +2246,13 @@ fn formattingHandler(server: *Server, writer: anytype, id: types.RequestId, req:
}); });
} }
const result = types.ResponseParams{
.TextEdits = text_edits.items,
};
return try send( return try send(
writer, writer,
server.arena.allocator(), server.arena.allocator(),
types.Response{ .id = id, .result = result }, types.Response{
.id = id,
.result = .{ .TextEdits = text_edits.items },
},
); );
}, },
else => {}, else => {},