Fix autocomplete bug when local filtering is used
This commit is contained in:
@@ -53,7 +53,8 @@ void completion_request(Editor *editor) {
|
|||||||
Coord hook = editor->cursor;
|
Coord hook = editor->cursor;
|
||||||
word_boundaries(editor, editor->cursor, &hook.col, nullptr, nullptr, nullptr);
|
word_boundaries(editor, editor->cursor, &hook.col, nullptr, nullptr, nullptr);
|
||||||
editor->completion.hook = hook;
|
editor->completion.hook = hook;
|
||||||
editor->completion.active = true;
|
editor->completion.complete = false;
|
||||||
|
editor->completion.active = false;
|
||||||
editor->completion.items.clear();
|
editor->completion.items.clear();
|
||||||
editor->completion.visible.clear();
|
editor->completion.visible.clear();
|
||||||
editor->completion.select = 0;
|
editor->completion.select = 0;
|
||||||
@@ -71,9 +72,15 @@ void completion_request(Editor *editor) {
|
|||||||
if (result.is_array()) {
|
if (result.is_array()) {
|
||||||
items_json = result.get<std::vector<json>>();
|
items_json = result.get<std::vector<json>>();
|
||||||
session.complete = true;
|
session.complete = true;
|
||||||
|
if (items_json.empty())
|
||||||
|
return;
|
||||||
|
editor->completion.active = true;
|
||||||
} else if (result.is_object() && result.contains("items")) {
|
} else if (result.is_object() && result.contains("items")) {
|
||||||
auto &list = result;
|
auto &list = result;
|
||||||
items_json = list["items"].get<std::vector<json>>();
|
items_json = list["items"].get<std::vector<json>>();
|
||||||
|
if (items_json.empty())
|
||||||
|
return;
|
||||||
|
editor->completion.active = true;
|
||||||
session.complete = !list.value("isIncomplete", false);
|
session.complete = !list.value("isIncomplete", false);
|
||||||
if (list.contains("itemDefaults") && list["itemDefaults"].is_object()) {
|
if (list.contains("itemDefaults") && list["itemDefaults"].is_object()) {
|
||||||
auto &defs = list["itemDefaults"];
|
auto &defs = list["itemDefaults"];
|
||||||
@@ -246,8 +253,7 @@ void handle_completion(Editor *editor, KeyEvent event) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (editor->completion.items.empty())
|
if (!editor->completion.items.empty()) {
|
||||||
return;
|
|
||||||
const auto &item = editor->completion.items[editor->completion.select];
|
const auto &item = editor->completion.items[editor->completion.select];
|
||||||
const std::vector<char> &end_chars =
|
const std::vector<char> &end_chars =
|
||||||
item.end_chars.empty() ? editor->lsp->end_chars : item.end_chars;
|
item.end_chars.empty() ? editor->lsp->end_chars : item.end_chars;
|
||||||
@@ -257,6 +263,7 @@ void handle_completion(Editor *editor, KeyEvent event) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
if ((ch >= 'a' && ch <= 'z') || (ch >= 'A' && ch <= 'Z') ||
|
if ((ch >= 'a' && ch <= 'z') || (ch >= 'A' && ch <= 'Z') ||
|
||||||
(ch >= '0' && ch <= '9') || ch == '_') {
|
(ch >= '0' && ch <= '9') || ch == '_') {
|
||||||
if (editor->completion.active) {
|
if (editor->completion.active) {
|
||||||
@@ -269,7 +276,7 @@ void handle_completion(Editor *editor, KeyEvent event) {
|
|||||||
completion_request(editor);
|
completion_request(editor);
|
||||||
}
|
}
|
||||||
} else if (ch == CTRL('\\')) {
|
} else if (ch == CTRL('\\')) {
|
||||||
if (editor->completion.active && editor->completion.visible.size()) {
|
if (editor->completion.active && !editor->completion.visible.empty()) {
|
||||||
complete_accept(editor);
|
complete_accept(editor);
|
||||||
} else {
|
} else {
|
||||||
editor->completion.trigger = 1;
|
editor->completion.trigger = 1;
|
||||||
@@ -294,6 +301,9 @@ void handle_completion(Editor *editor, KeyEvent event) {
|
|||||||
else
|
else
|
||||||
completion_request(editor);
|
completion_request(editor);
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
editor->completion.trigger = 3;
|
||||||
|
completion_request(editor);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
editor->completion.active = false;
|
editor->completion.active = false;
|
||||||
@@ -362,7 +372,21 @@ void complete_accept(Editor *editor) {
|
|||||||
if (!editor->completion.active || editor->completion.box.hidden)
|
if (!editor->completion.active || editor->completion.box.hidden)
|
||||||
return;
|
return;
|
||||||
auto &item = editor->completion.items[editor->completion.select];
|
auto &item = editor->completion.items[editor->completion.select];
|
||||||
// TODO: support snippets here
|
// TODO: support snippets here maybe?
|
||||||
|
int delta_col = 0;
|
||||||
|
TextEdit &e = item.edits[0];
|
||||||
|
if (e.end.row == editor->cursor.row) {
|
||||||
|
delta_col = editor->cursor.col - e.end.col;
|
||||||
|
e.end.col = editor->cursor.col;
|
||||||
|
for (size_t i = 1; i < item.edits.size(); ++i) {
|
||||||
|
TextEdit &e = item.edits[i];
|
||||||
|
if (e.start.row == editor->cursor.row) {
|
||||||
|
e.start.col += delta_col;
|
||||||
|
if (e.end.row == editor->cursor.row)
|
||||||
|
e.end.col += delta_col;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
apply_lsp_edits(editor, item.edits, true);
|
apply_lsp_edits(editor, item.edits, true);
|
||||||
editor->completion.active = false;
|
editor->completion.active = false;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user