summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--autocomplete.c11
-rw-r--r--main.c2
-rw-r--r--ted.h6
-rw-r--r--time.c7
4 files changed, 23 insertions, 3 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 {
diff --git a/main.c b/main.c
index 7460e2b..661f4e9 100644
--- a/main.c
+++ b/main.c
@@ -1,6 +1,5 @@
/*
@TODO:
-- only show "Loading..." if it's taking some time (prevent flash)
- dont do completion if provides_completion = false
- scroll through completions
- LSP setting
@@ -691,6 +690,7 @@ int main(int argc, char **argv) {
while (!ted->quit) {
double frame_start = time_get_seconds();
+ ted->frame_time = time_get();
SDL_Event event;
Uint8 const *keyboard_state = SDL_GetKeyboardState(NULL);
diff --git a/ted.h b/ted.h
index cbcc466..ddd2695 100644
--- a/ted.h
+++ b/ted.h
@@ -382,6 +382,10 @@ typedef struct {
// which trigger character invoked this (0 if autocomplete was manually invoked)
char32_t trigger_char;
+ // when autocomplete menu was opened
+ // (this is used to figure out when we should display "Loading...")
+ struct timespec open_time;
+
Autocompletion *completions; // dynamic array of all completions
u32 *suggested; // dynamic array of completions to be suggested (indices into completions)
BufferPos last_pos; // position of cursor last time completions were generated. if this changes, we need to recompute completions.
@@ -391,6 +395,8 @@ typedef struct {
typedef struct Ted {
struct LSP *test_lsp; // @TODO: something better
+ // current time, as of the start of this frame
+ struct timespec frame_time;
SDL_Window *window;
Font *font_bold;
diff --git a/time.c b/time.c
index 57ec9dc..7e82f0d 100644
--- a/time.c
+++ b/time.c
@@ -38,7 +38,12 @@ static struct timespec timespec_max(struct timespec a, struct timespec b) {
static double timespec_to_seconds(struct timespec ts) {
return (double)ts.tv_sec
- + (double)ts.tv_nsec * 0.000000001;
+ + (double)ts.tv_nsec * 1e-9;
+}
+
+static double timespec_sub(struct timespec a, struct timespec b) {
+ return (double)(a.tv_sec - b.tv_sec)
+ + (double)(a.tv_nsec - b.tv_nsec) * 1e-9;
}
static struct timespec time_get(void) {