Lsp completion logic

This commit is contained in:
2026-01-04 03:27:17 +00:00
parent ac04754318
commit a905e333fc
24 changed files with 624 additions and 136 deletions

View File

@@ -7,6 +7,7 @@ void Bar::render() {
uint32_t row = screen.row - 2;
uint32_t col = 0;
uint32_t width = screen.col;
UNUSED(width);
uint32_t color = 0;
uint32_t black = 0x0b0e14;
uint32_t grey = 0x33363c;
@@ -80,7 +81,7 @@ void Bar::handle(KeyEvent event) {
cursor--;
break;
case KEY_RIGHT:
if (cursor < command.length())
if (cursor < (uint32_t)command.length())
cursor++;
break;
case KEY_UP:

5
src/ui/completionbox.cc Normal file
View File

@@ -0,0 +1,5 @@
#include "ui/completionbox.h"
void CompletionBox::render_update() {}
void CompletionBox::render(Coord pos) {}

View File

@@ -3,9 +3,8 @@
void DiagnosticBox::clear() {
warnings.clear();
cells.clear();
box_width = 0;
box_height = 0;
}
size = {0, 0};
};
void DiagnosticBox::render_first() {
if (warnings.empty())
@@ -18,11 +17,11 @@ void DiagnosticBox::render_first() {
longest_line = MAX(longest_line, (uint32_t)see_also.length() + 4);
}
uint32_t content_width = MIN(longest_line, 150u);
box_width = content_width + 2;
cells.assign(box_width * 25, {" ", 0, 0, 0, 0, 0});
size.col = content_width + 2;
cells.assign(size.col * 25, {" ", 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 base_bg = 0;
uint32_t border_fg = 0x82AAFF;
@@ -116,35 +115,35 @@ void DiagnosticBox::render_first() {
};
idx++;
}
box_height = 2 + r;
size.row = 2 + r;
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 DiagnosticBox::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);
}

View File

@@ -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);
}