fix: hover should convert column to byte position in LSP response

closes: #85
This commit is contained in:
CJ van den Berg 2024-12-20 20:16:50 +01:00
parent 1aa64b8ea4
commit 69c2d06007
Signed by: neurocyte
GPG key ID: 8EB1E1BB660E3FB9
2 changed files with 31 additions and 21 deletions

View file

@ -3980,6 +3980,30 @@ pub const Editor = struct {
return project_manager.hover(file_path, row, pos);
}
pub fn add_hover_highlight(self: *Self, match_: Match) void {
const root = self.buf_root() catch return;
const match: Match = .{
.begin = .{
.row = match_.begin.row,
.col = root.pos_to_width(match_.begin.row, match_.begin.col, self.metrics) catch return,
},
.end = .{
.row = match_.end.row,
.col = root.pos_to_width(match_.end.row, match_.end.col, self.metrics) catch return,
},
};
switch (self.matches.items.len) {
0 => {
(self.matches.addOne() catch return).* = match;
},
1 => {
self.matches.items[0] = match;
},
else => {},
}
self.need_render();
}
pub fn add_diagnostic(
self: *Self,
file_path: []const u8,

View file

@ -125,7 +125,12 @@ pub fn receive(self: *Self, from_: tp.pid_ref, m: tp.message) error{Exit}!bool {
self.find_in_files_done = true;
return true;
} else if (try m.match(.{ "hover", tp.extract(&path), tp.string, tp.extract(&lines), tp.extract(&begin_line), tp.extract(&begin_pos), tp.extract(&end_line), tp.extract(&end_pos) })) {
try self.add_info_content(begin_line, begin_pos, end_line, end_pos, lines);
try self.add_info_content(lines);
if (self.get_active_editor()) |editor|
editor.add_hover_highlight(.{
.begin = .{ .row = begin_line, .col = begin_pos },
.end = .{ .row = end_line, .col = end_pos },
});
return true;
} else if (try m.match(.{"write_restore_info"})) {
self.write_restore_info();
@ -838,30 +843,11 @@ fn clear_find_in_files_results(self: *Self, file_list_type: FileListType) void {
fl.reset();
}
fn add_info_content(
self: *Self,
begin_line: usize,
begin_pos: usize,
end_line: usize,
end_pos: usize,
content: []const u8,
) tp.result {
fn add_info_content(self: *Self, content: []const u8) tp.result {
if (content.len == 0) return;
if (!self.is_panel_view_showing(info_view))
_ = self.toggle_panel_view(info_view, false) catch |e| return tp.exit_error(e, @errorReturnTrace());
const info = self.get_panel_view(info_view) orelse @panic("info_view missing");
info.set_content(content) catch |e| return tp.exit_error(e, @errorReturnTrace());
const match: ed.Match = .{ .begin = .{ .row = begin_line, .col = begin_pos }, .end = .{ .row = end_line, .col = end_pos } };
if (self.get_active_editor()) |editor|
switch (editor.matches.items.len) {
0 => {
(editor.matches.addOne() catch return).* = match;
},
1 => {
editor.matches.items[0] = match;
},
else => {},
};
tui.need_render();
}