Bug Fixes and optimizations

This commit is contained in:
2026-01-10 17:15:09 +00:00
parent b2a64f219f
commit 2c1e69181a
12 changed files with 329 additions and 88 deletions

View File

@@ -103,4 +103,8 @@ void editor_worker(Editor *editor) {
}
lock2.unlock();
hover_diagnostic(editor);
if (editor->completion.active && editor->completion.hover_dirty) {
editor->completion.hover.render_first();
editor->completion.hover_dirty = false;
}
}

View File

@@ -90,7 +90,8 @@ void ts_collect_spans(Editor *editor) {
ts_query_cursor_exec(cursor, q, ts_tree_root_node(item.tsset->tree));
std::unordered_map<std::string, PendingRanges> pending_injections;
TSQueryMatch match;
auto subject_fn = [&](const TSNode *node, uint32_t *len) -> char * {
auto subject_fn = [&](const TSNode *node, uint32_t *len,
bool *allocated) -> char * {
uint32_t start = ts_node_start_byte(*node);
uint32_t end = ts_node_end_byte(*node);
if (start == end || end > editor->root->char_count)
@@ -98,6 +99,7 @@ void ts_collect_spans(Editor *editor) {
std::shared_lock lock(editor->knot_mtx);
char *text = read(editor->root, start, end - start);
*len = end - start;
*allocated = true;
return text;
};
while (ts_query_cursor_next_match(cursor, &match)) {

View File

@@ -117,7 +117,8 @@ TSQuery *load_query(const char *query_path, TSSetBase *set) {
bool ts_predicate(
TSQuery *query, const TSQueryMatch &match,
std::function<char *(const TSNode *, uint32_t *len)> subject_fn) {
std::function<char *(const TSNode *, uint32_t *len, bool *allocated)>
subject_fn) {
uint32_t step_count;
const TSQueryPredicateStep *steps =
ts_query_predicates_for_pattern(query, match.pattern_index, &step_count);
@@ -152,13 +153,15 @@ bool ts_predicate(
const TSNode *node = find_capture_node(match, subject_id);
pcre2_code *re = get_re(regex_txt);
uint32_t len;
char *subject = subject_fn(node, &len);
bool allocated;
char *subject = subject_fn(node, &len, &allocated);
if (!subject)
return false;
pcre2_match_data *md = pcre2_match_data_create_from_pattern(re, nullptr);
int rc = pcre2_match(re, (PCRE2_SPTR)subject, len, 0, 0, md, nullptr);
pcre2_match_data_free(md);
bool ok = (rc >= 0);
free(subject);
if (allocated)
free(subject);
return (command == "match?" ? ok : !ok);
}

View File

@@ -152,13 +152,14 @@ void CompletionBox::render(Coord pos) {
cells[r * size.col + c].flags);
if (session->items.size() > session->select &&
session->items[session->select].documentation &&
*session->items[session->select].documentation != "") {
*session->items[session->select].documentation != "" &&
!session->hover_dirty) {
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();
session->hover_dirty = true;
} else {
if ((int32_t)position.col - (int32_t)session->hover.size.col > 0) {
session->hover.render({position.row + session->hover.size.row,

View File

@@ -44,10 +44,12 @@ 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 * {
auto subject_fn = [&](const TSNode *node, uint32_t *len,
bool *allocated) -> char * {
uint32_t start = ts_node_start_byte(*node);
uint32_t end = ts_node_end_byte(*node);
*len = end - start;
*allocated = false;
return text.data() + start;
};
while (ts_query_cursor_next_match(cursor, &match)) {