summaryrefslogtreecommitdiff
path: root/autocomplete.c
diff options
context:
space:
mode:
authorpommicket <pommicket@gmail.com>2022-12-23 14:55:24 -0500
committerpommicket <pommicket@gmail.com>2022-12-23 14:55:24 -0500
commit214dae3a7b58077436ffd173ae9fe8f2a6d9b97b (patch)
tree3fda7c1f935eff6ce9e9f647e148296af725e819 /autocomplete.c
parentdbab768e4d0be378e65399f32f26edb4756533ce (diff)
wait before showing "Loading..." for autocomplete
Diffstat (limited to 'autocomplete.c')
-rw-r--r--autocomplete.c11
1 files changed, 10 insertions, 1 deletions
diff --git a/autocomplete.c b/autocomplete.c
index 020a2e3..adfda6f 100644
--- a/autocomplete.c
+++ b/autocomplete.c
@@ -189,6 +189,7 @@ static void autocomplete_open(Ted *ted, char32_t trigger_character) {
ted->cursor_error_time = 0;
ac->last_pos = (BufferPos){0,0};
ac->cursor = 0;
+ ac->open_time = ted->frame_time;
autocomplete_find_completions(ted, trigger_character);
switch (arr_len(ac->completions)) {
@@ -254,6 +255,14 @@ static void autocomplete_frame(Ted *ted) {
menu_height = 200.f;
}
+ if (ac->waiting_for_lsp && ncompletions == 0) {
+ struct timespec now = ted->frame_time;
+ if (timespec_sub(now, ac->open_time) < 0.2) {
+ // don't show "Loading..." unless we've actually been loading for a bit of time
+ return;
+ }
+ }
+
if (!ac->waiting_for_lsp && ncompletions == 0) {
// no completions. close menu.
autocomplete_close(ted);
@@ -347,7 +356,7 @@ static void autocomplete_frame(Ted *ted) {
state.min_x = x + padding; state.min_y = y; state.max_x = x + menu_width - padding; state.max_y = y + menu_height;
rgba_u32_to_floats(colors[COLOR_TEXT], state.color);
- if (ac->waiting_for_lsp) {
+ if (ac->waiting_for_lsp && ncompletions == 0) {
state.x = x + padding; state.y = y;
text_utf8_with_state(font, &state, "Loading...");
} else {