feat: add option to align inline diagnostics to the left

closes #456
This commit is contained in:
CJ van den Berg 2026-01-15 12:03:51 +01:00
parent 1b9e01671a
commit cb1797d98c
Signed by: neurocyte
GPG key ID: 8EB1E1BB660E3FB9
2 changed files with 16 additions and 2 deletions

View file

@ -17,6 +17,7 @@ highlight_columns_alpha: u8 = 240,
highlight_columns_enabled: bool = false,
whitespace_mode: WhitespaceMode = .indent,
inline_diagnostics: bool = true,
inline_diagnostics_alignment: Alignment = .right,
animation_min_lag: usize = 0, //milliseconds
animation_max_lag: usize = 50, //milliseconds
hover_time_ms: usize = 500, //milliseconds
@ -180,3 +181,8 @@ pub const CompletionStyle = enum {
palette,
dropdown,
};
pub const Alignment = enum {
left,
right,
};

View file

@ -1433,8 +1433,16 @@ pub const Editor = struct {
fn render_diagnostic_message(self: *Self, message_: []const u8, y: usize, max_space: usize, style: Widget.Theme.Style) void {
self.plane.set_style(style);
var iter = std.mem.splitScalar(u8, message_, '\n');
if (iter.next()) |message|
_ = self.plane.print_aligned_right(@intCast(y), " • {s}", .{message[0..@min(max_space - 3, message.len)]}) catch {};
if (iter.next()) |message| {
switch (tui.config().inline_diagnostics_alignment) {
.right => _ = self.plane.print_aligned_right(@intCast(y), " • {s}", .{message[0..@min(max_space - 3, message.len)]}) catch {},
.left => {
const width = self.plane.window.width;
self.plane.cursor_move_yx(@intCast(y), @intCast(width -| max_space + 2));
_ = self.plane.print(" • {s}", .{message}) catch 0;
},
}
}
}
inline fn render_diagnostic_cell(self: *Self, style: Widget.Theme.Style) void {