Skip to content

Commit

Permalink
fix: hover should convert column to byte position in LSP response
Browse files Browse the repository at this point in the history
closes: #85
  • Loading branch information
neurocyte committed Dec 20, 2024
1 parent 1aa64b8 commit 69c2d06
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 21 deletions.
24 changes: 24 additions & 0 deletions src/tui/editor.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
28 changes: 7 additions & 21 deletions src/tui/mainview.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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();
}

0 comments on commit 69c2d06

Please sign in to comment.