Completions bug fixes
This commit is contained in:
@@ -34,6 +34,8 @@ struct CompletionSession {
|
||||
std::optional<char> trigger_char;
|
||||
uint8_t trigger = 0;
|
||||
CompletionBox box;
|
||||
HoverBox hover;
|
||||
uint32_t doc = UINT32_MAX;
|
||||
|
||||
CompletionSession() : box(this) {}
|
||||
};
|
||||
|
||||
@@ -4,9 +4,7 @@
|
||||
#include "utils/utils.h"
|
||||
|
||||
struct TextEdit {
|
||||
// NOTE: start.col is in utf16 index and not clusters or utf8
|
||||
Coord start;
|
||||
// NOTE: end.col is in utf16 index and not clusters or utf8
|
||||
Coord end;
|
||||
std::string text;
|
||||
};
|
||||
|
||||
@@ -18,6 +18,8 @@
|
||||
#define EXTRA_META 4
|
||||
#define INDENT_WIDTH 2
|
||||
|
||||
// autocomplete lua// Bracket closing / tab on enter
|
||||
|
||||
struct Editor {
|
||||
std::string filename;
|
||||
std::string uri;
|
||||
@@ -95,7 +97,7 @@ uint32_t leading_indent(const char *line, uint32_t len);
|
||||
uint32_t get_indent(Editor *editor, Coord cursor);
|
||||
bool closing_after_cursor(const char *line, uint32_t len, uint32_t col);
|
||||
void editor_lsp_handle(Editor *editor, json msg);
|
||||
void apply_lsp_edits(Editor *editor, std::vector<TextEdit> edits);
|
||||
void apply_lsp_edits(Editor *editor, std::vector<TextEdit> edits, bool move);
|
||||
void completion_resolve_doc(Editor *editor);
|
||||
void complete_accept(Editor *editor);
|
||||
void complete_next(Editor *editor);
|
||||
@@ -116,4 +118,56 @@ inline void apply_hook_deletion(Editor *editor, uint32_t removal_start,
|
||||
hook -= removal_end - removal_start + 1;
|
||||
}
|
||||
|
||||
inline static void utf8_normalize_edit(Editor *editor, TextEdit *edit) {
|
||||
std::shared_lock lock(editor->knot_mtx);
|
||||
if (edit->start.row > editor->root->line_count) {
|
||||
edit->start.row = editor->root->line_count;
|
||||
edit->start.col = UINT32_MAX;
|
||||
}
|
||||
if (edit->end.row > editor->root->line_count) {
|
||||
edit->end.row = editor->root->line_count;
|
||||
edit->end.col = UINT32_MAX;
|
||||
}
|
||||
LineIterator *it = begin_l_iter(editor->root, edit->start.row);
|
||||
if (!it)
|
||||
return;
|
||||
uint32_t len;
|
||||
char *line = next_line(it, &len);
|
||||
if (!line) {
|
||||
free(it->buffer);
|
||||
free(it);
|
||||
return;
|
||||
}
|
||||
if (edit->start.col < len)
|
||||
edit->start.col = utf16_offset_to_utf8(line, edit->start.col);
|
||||
else
|
||||
edit->start.col = len;
|
||||
if (edit->end.row == edit->start.row) {
|
||||
if (edit->end.col < len)
|
||||
edit->end.col = utf16_offset_to_utf8(line, edit->end.col);
|
||||
else
|
||||
edit->end.col = len;
|
||||
free(it->buffer);
|
||||
free(it);
|
||||
return;
|
||||
}
|
||||
free(it->buffer);
|
||||
free(it);
|
||||
it = begin_l_iter(editor->root, edit->end.row);
|
||||
if (!it)
|
||||
return;
|
||||
line = next_line(it, &len);
|
||||
if (!line) {
|
||||
free(it->buffer);
|
||||
free(it);
|
||||
return;
|
||||
}
|
||||
if (edit->end.col < len)
|
||||
edit->end.col = utf16_offset_to_utf8(line, edit->end.col);
|
||||
else
|
||||
edit->end.col = len;
|
||||
free(it->buffer);
|
||||
free(it);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -35,6 +35,9 @@ struct LSPInstance {
|
||||
bool allow_hover = false;
|
||||
bool allow_completion = false;
|
||||
bool allow_resolve = false;
|
||||
bool allow_formatting = false;
|
||||
bool allow_formatting_on_type = false;
|
||||
std::vector<char> format_chars;
|
||||
std::vector<char> trigger_chars;
|
||||
std::vector<char> end_chars;
|
||||
uint32_t last_id = 0;
|
||||
@@ -53,6 +56,8 @@ static json client_capabilities = {
|
||||
{"textDocument",
|
||||
{{"publishDiagnostics", {{"relatedInformation", true}}},
|
||||
{"hover", {{"contentFormat", {"markdown", "plaintext"}}}},
|
||||
{"formatting", {{"dynamicRegistration", false}}},
|
||||
{"onTypeFormatting", {{"dynamicRegistration", false}}},
|
||||
{"completion",
|
||||
{{"completionItem",
|
||||
{{"commitCharactersSupport", true},
|
||||
|
||||
@@ -11,8 +11,9 @@ extern std::unordered_map<std::string, pcre2_code *> regex_cache;
|
||||
|
||||
TSQuery *load_query(const char *query_path, TSSetBase *set);
|
||||
void ts_collect_spans(Editor *editor);
|
||||
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);
|
||||
void clear_regex_cache();
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user