Completions bug fixes
This commit is contained in:
+10
-8
@@ -90,15 +90,17 @@ 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 * {
|
||||
uint32_t start = ts_node_start_byte(*node);
|
||||
uint32_t end = ts_node_end_byte(*node);
|
||||
if (start == end || end > editor->root->char_count)
|
||||
return nullptr;
|
||||
std::shared_lock lock(editor->knot_mtx);
|
||||
char *text = read(editor->root, start, end - start);
|
||||
*len = end - start;
|
||||
return text;
|
||||
};
|
||||
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);
|
||||
char *text = read(editor->root, start, end - start);
|
||||
std::string final = std::string(text, end - start);
|
||||
free(text);
|
||||
return final;
|
||||
};
|
||||
if (!ts_predicate(q, match, subject_fn))
|
||||
continue;
|
||||
for (uint32_t i = 0; i < match.capture_count; i++) {
|
||||
|
||||
+10
-5
@@ -1,6 +1,7 @@
|
||||
#include "config.h"
|
||||
#include "io/sysio.h"
|
||||
#include "ts/ts.h"
|
||||
#include <cstdint>
|
||||
|
||||
std::unordered_map<std::string, pcre2_code *> regex_cache;
|
||||
|
||||
@@ -114,8 +115,9 @@ TSQuery *load_query(const char *query_path, TSSetBase *set) {
|
||||
return q;
|
||||
}
|
||||
|
||||
bool ts_predicate(TSQuery *query, const TSQueryMatch &match,
|
||||
std::function<std::string(const TSNode *)> subject_fn) {
|
||||
bool ts_predicate(
|
||||
TSQuery *query, const TSQueryMatch &match,
|
||||
std::function<char *(const TSNode *, uint32_t *len)> subject_fn) {
|
||||
uint32_t step_count;
|
||||
const TSQueryPredicateStep *steps =
|
||||
ts_query_predicates_for_pattern(query, match.pattern_index, &step_count);
|
||||
@@ -149,11 +151,14 @@ bool ts_predicate(TSQuery *query, const TSQueryMatch &match,
|
||||
}
|
||||
const TSNode *node = find_capture_node(match, subject_id);
|
||||
pcre2_code *re = get_re(regex_txt);
|
||||
std::string subject = subject_fn(node);
|
||||
uint32_t len;
|
||||
char *subject = subject_fn(node, &len);
|
||||
if (!subject)
|
||||
return false;
|
||||
pcre2_match_data *md = pcre2_match_data_create_from_pattern(re, nullptr);
|
||||
int rc = pcre2_match(re, (PCRE2_SPTR)subject.c_str(), subject.size(), 0, 0,
|
||||
md, 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);
|
||||
return (command == "match?" ? ok : !ok);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user