fix: add missing pos_to_width calls in add_diagnostic

This will fix the positioning of diagnostics in lines that have glyphs
with widths != 1 like tabs or emojis.
This commit is contained in:
CJ van den Berg 2024-10-11 21:05:35 +02:00
parent 39d4197a42
commit e9a7d681f2

View file

@ -3676,10 +3676,22 @@ pub const Editor = struct {
code: []const u8, code: []const u8,
message: []const u8, message: []const u8,
severity: i32, severity: i32,
sel: Selection, sel_: Selection,
) Result { ) Result {
if (!std.mem.eql(u8, file_path, self.file_path orelse return)) return; if (!std.mem.eql(u8, file_path, self.file_path orelse return)) return;
const root = self.buf_root() catch return;
const sel: Selection = .{
.begin = .{
.row = sel_.begin.row,
.col = root.pos_to_width(sel_.begin.row, sel_.begin.col, self.metrics) catch return,
},
.end = .{
.row = sel_.end.row,
.col = root.pos_to_width(sel_.end.row, sel_.end.col, self.metrics) catch return,
},
};
(try self.diagnostics.addOne()).* = .{ (try self.diagnostics.addOne()).* = .{
.source = try self.diagnostics.allocator.dupe(u8, source), .source = try self.diagnostics.allocator.dupe(u8, source),
.code = try self.diagnostics.allocator.dupe(u8, code), .code = try self.diagnostics.allocator.dupe(u8, code),