Completions bug fixes

This commit is contained in:
2026-01-10 07:56:40 +00:00
parent e9da17eb34
commit b2a64f219f
21 changed files with 400 additions and 193 deletions

View File

@@ -1,8 +1,6 @@
#include "ui/completionbox.h"
#include "editor/completions.h"
#include "utils/utils.h"
#include <cstdint>
#include <string>
std::string item_kind_name(uint8_t kind) {
switch (kind) {
@@ -76,11 +74,11 @@ void CompletionBox::render_update() {
if (i >= session->items.size())
continue;
auto &item = session->items[i];
max_label_len = std::max(max_label_len, (uint32_t)item.label.size());
max_label_len = MAX(max_label_len, (uint32_t)item.label.size());
if (item.detail)
max_detail_len = std::max(max_detail_len, (uint32_t)item.detail->size());
max_detail_len = MAX(max_detail_len, (uint32_t)item.detail->size());
max_kind_len =
std::max(max_kind_len, (uint32_t)item_kind_name(item.kind).size());
MAX(max_kind_len, (uint32_t)item_kind_name(item.kind).size());
}
size.row = session->visible.size() + 2;
size.col = 2 + 2 + max_label_len + 1 + max_detail_len + 2 + max_kind_len + 1;
@@ -91,7 +89,7 @@ void CompletionBox::render_update() {
cells[r * size.col + c] = {std::string(text), 0, fg, bg, flags, 0};
};
uint32_t border_fg = 0x82AAFF;
uint32_t sel_bg = 0xFFFF00;
uint32_t sel_bg = 0x174225;
set(0, 0, "", border_fg, 0, 0);
for (uint32_t c = 1; c < size.col - 1; c++)
set(0, c, "", border_fg, 0, 0);
@@ -99,7 +97,7 @@ void CompletionBox::render_update() {
for (uint32_t row_idx = 0; row_idx < session->visible.size(); row_idx++) {
uint32_t r = row_idx + 1;
auto &item = session->items[session->visible[row_idx]];
uint32_t bg = (session->visible[row_idx] == session->select) ? sel_bg : 0;
uint32_t bg = (session->visible[row_idx] == session->select) ? sel_bg : 1;
uint32_t fg = 0xFFFFFF;
set(r, 0, "", border_fg, 0, 0);
uint32_t c = 1;
@@ -134,7 +132,7 @@ void CompletionBox::render_update() {
}
void CompletionBox::render(Coord pos) {
if (hidden)
if (hidden || session->visible.empty())
return;
std::shared_lock lock(mtx);
int32_t start_row = (int32_t)pos.row - (int32_t)size.row;
@@ -152,4 +150,23 @@ void CompletionBox::render(Coord pos) {
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);
if (session->items.size() > session->select &&
session->items[session->select].documentation &&
*session->items[session->select].documentation != "") {
if (session->doc != session->select) {
session->doc = session->select;
session->hover.clear();
session->hover.text = *session->items[session->select].documentation;
session->hover.is_markup = true;
session->hover.render_first();
} else {
if ((int32_t)position.col - (int32_t)session->hover.size.col > 0) {
session->hover.render({position.row + session->hover.size.row,
position.col - session->hover.size.col});
} else {
session->hover.render(
{position.row + session->hover.size.row, position.col + size.col});
}
}
}
}

View File

@@ -44,12 +44,13 @@ void HoverBox::render_first(bool scroll) {
TSQueryCursor *cursor = ts_query_cursor_new();
ts_query_cursor_exec(cursor, ts.query, ts_tree_root_node(ts.tree));
TSQueryMatch match;
auto subject_fn = [&](const TSNode *node, uint32_t *len) -> char * {
uint32_t start = ts_node_start_byte(*node);
uint32_t end = ts_node_end_byte(*node);
*len = end - start;
return text.data() + start;
};
while (ts_query_cursor_next_match(cursor, &match)) {
auto subject_fn = [&](const TSNode *node) -> std::string {
uint32_t start = ts_node_start_byte(*node);
uint32_t end = ts_node_end_byte(*node);
return text.substr(start, end - start);
};
if (!ts_predicate(ts.query, match, subject_fn))
continue;
for (uint32_t i = 0; i < match.capture_count; i++) {
@@ -75,11 +76,6 @@ void HoverBox::render_first(bool scroll) {
ts_tree_root_node(inj_ts.tree));
TSQueryMatch inj_match;
while (ts_query_cursor_next_match(inj_cursor, &inj_match)) {
auto subject_fn = [&](const TSNode *node) -> std::string {
uint32_t start = ts_node_start_byte(*node);
uint32_t end = ts_node_end_byte(*node);
return text.substr(start, end - start);
};
if (!ts_predicate(inj_ts.query, inj_match, subject_fn))
continue;
for (uint32_t i = 0; i < inj_match.capture_count; i++) {