Lsp completion logic
This commit is contained in:
@@ -5,8 +5,7 @@ void HoverBox::clear() {
|
||||
text = "";
|
||||
scroll_ = 0;
|
||||
is_markup = false;
|
||||
box_width = 0;
|
||||
box_height = 0;
|
||||
size = {0, 0};
|
||||
cells.clear();
|
||||
highlights.clear();
|
||||
hover_spans.clear();
|
||||
@@ -139,7 +138,7 @@ void HoverBox::render_first(bool scroll) {
|
||||
// in the loop instead as it was never meant to wrap in the first place
|
||||
longest_line = MAX(longest_line, current_width) + 1;
|
||||
uint32_t content_width = MIN(longest_line, 130u);
|
||||
box_width = content_width + 2;
|
||||
size.col = content_width + 2;
|
||||
size_t i = 0;
|
||||
size_t lines_skipped = 0;
|
||||
while (i < text.length() && lines_skipped < scroll_) {
|
||||
@@ -153,10 +152,10 @@ void HoverBox::render_first(bool scroll) {
|
||||
uint32_t base_bg = 0;
|
||||
SpanCursor span_cursor(spans);
|
||||
span_cursor.sync(i);
|
||||
cells.assign(box_width * 26, ScreenCell{" ", 0, 0, 0, 0, 0});
|
||||
cells.assign(size.col * 26, ScreenCell{" ", 0, 0, 0, 0, 0});
|
||||
auto set = [&](uint32_t r, uint32_t c, const char *text, uint32_t fg,
|
||||
uint32_t bg, uint8_t flags) {
|
||||
cells[r * box_width + c] = {std::string(text), 0, fg, bg, flags, 0};
|
||||
cells[r * size.col + c] = {std::string(text), 0, fg, bg, flags, 0};
|
||||
};
|
||||
uint32_t r = 0;
|
||||
while (i < text.length() && r < 24) {
|
||||
@@ -186,35 +185,35 @@ void HoverBox::render_first(bool scroll) {
|
||||
r++;
|
||||
}
|
||||
if (!scroll)
|
||||
box_height = r + 2;
|
||||
size.row = r + 2;
|
||||
set(0, 0, "┌", border_fg, base_bg, 0);
|
||||
for (uint32_t i = 1; i < box_width - 1; i++)
|
||||
for (uint32_t i = 1; i < size.col - 1; i++)
|
||||
set(0, i, "─", border_fg, base_bg, 0);
|
||||
set(0, box_width - 1, "┐", border_fg, base_bg, 0);
|
||||
for (uint32_t r = 1; r < box_height - 1; r++) {
|
||||
set(0, size.col - 1, "┐", border_fg, base_bg, 0);
|
||||
for (uint32_t r = 1; r < size.row - 1; r++) {
|
||||
set(r, 0, "│", border_fg, base_bg, 0);
|
||||
set(r, box_width - 1, "│", border_fg, base_bg, 0);
|
||||
set(r, size.col - 1, "│", border_fg, base_bg, 0);
|
||||
}
|
||||
set(box_height - 1, 0, "└", border_fg, base_bg, 0);
|
||||
for (uint32_t i = 1; i < box_width - 1; i++)
|
||||
set(box_height - 1, i, "─", border_fg, base_bg, 0);
|
||||
set(box_height - 1, box_width - 1, "┘", border_fg, base_bg, 0);
|
||||
cells.resize(box_width * box_height);
|
||||
set(size.row - 1, 0, "└", border_fg, base_bg, 0);
|
||||
for (uint32_t i = 1; i < size.col - 1; i++)
|
||||
set(size.row - 1, i, "─", border_fg, base_bg, 0);
|
||||
set(size.row - 1, size.col - 1, "┘", border_fg, base_bg, 0);
|
||||
cells.resize(size.col * size.row);
|
||||
}
|
||||
|
||||
void HoverBox::render(Coord pos) {
|
||||
int32_t start_row = (int32_t)pos.row - (int32_t)box_height;
|
||||
int32_t start_row = (int32_t)pos.row - (int32_t)size.row;
|
||||
if (start_row < 0)
|
||||
start_row = pos.row + 1;
|
||||
int32_t start_col = pos.col;
|
||||
if (start_col + box_width > cols) {
|
||||
start_col = cols - box_width;
|
||||
if (start_col + size.col > cols) {
|
||||
start_col = cols - size.col;
|
||||
if (start_col < 0)
|
||||
start_col = 0;
|
||||
}
|
||||
for (uint32_t r = 0; r < box_height; r++)
|
||||
for (uint32_t c = 0; c < box_width; c++)
|
||||
update(start_row + r, start_col + c, cells[r * box_width + c].utf8,
|
||||
cells[r * box_width + c].fg, cells[r * box_width + c].bg,
|
||||
cells[r * box_width + c].flags);
|
||||
for (uint32_t r = 0; r < size.row; r++)
|
||||
for (uint32_t c = 0; c < size.col; c++)
|
||||
update(start_row + r, start_col + c, cells[r * size.col + c].utf8,
|
||||
cells[r * size.col + c].fg, cells[r * size.col + c].bg,
|
||||
cells[r * size.col + c].flags);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user