From af946739afbf2a0728452d736b0a8bde7efa461e Mon Sep 17 00:00:00 2001 From: pommicket Date: Sat, 17 Jun 2023 18:38:55 +0100 Subject: ignore duplicate autocomplete suggestions for phantom --- README.md | 1 + control | 2 +- ide-autocomplete.c | 32 ++++++++++++++++++++++---------- main.c | 2 +- ted.h | 2 +- 5 files changed, 26 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index 6fbf58d..2b6a165 100644 --- a/README.md +++ b/README.md @@ -318,6 +318,7 @@ Then, open windows\_installer\\ted\\ted.sln, and build. 2.2r1 Minor bug fixes 2023 Mar 27 2.3 `:matching-bracket`, various minor improvements 2023 May 11 2.3.1 Bugfixes, better undo chaining, highlight TODOs in comments. 2023 May 22 +2.3.2 Misc bugfixes 2023 Jun 17 ## License diff --git a/control b/control index 464db3b..af26cb6 100644 --- a/control +++ b/control @@ -1,5 +1,5 @@ Package: ted -Version: 2.3.1 +Version: 2.3.2 Section: text Priority: optional Architecture: amd64 diff --git a/ide-autocomplete.c b/ide-autocomplete.c index 3d5e24c..b8898d5 100644 --- a/ide-autocomplete.c +++ b/ide-autocomplete.c @@ -322,7 +322,10 @@ void autocomplete_process_lsp_response(Ted *ted, const LSPResponse *response) { for (size_t i = 0; i < ncompletions; ++i) { const LSPCompletionItem *lsp_completion = &completion->items[i]; const char *new_text = lsp_response_string(response, lsp_completion->text_edit.new_text); - if (str_has_prefix(new_text, word_at_cursor)) { + if (str_has_prefix(new_text, word_at_cursor) && ( + // ignore completions with duplicate text + !candidate || !streq(candidate, new_text) + )) { candidate = new_text; ++ncandidates; if (ncandidates >= 2) break; @@ -398,8 +401,8 @@ void autocomplete_open(Ted *ted, uint32_t trigger) { ac->cursor = 0; autocomplete_find_completions(ted, trigger, false); - switch (arr_len(ac->completions)) { - case 0: + + if (arr_len(ac->completions) == 0) { if (autocomplete_using_lsp(ted)) { ac->open = true; } else if (settings->regenerate_tags_if_not_found && !regenerated) { @@ -409,16 +412,25 @@ void autocomplete_open(Ted *ted, uint32_t trigger) { } else { autocomplete_no_suggestions(ted); } - break; - case 1: + return; + } + + bool multiple_completions = false; + for (u32 i = 1; i < arr_len(ac->completions); ++i) { + if (!streq(ac->completions[i].text, ac->completions[0].text)) { + multiple_completions = true; + break; + } + } + + if (!multiple_completions) { autocomplete_complete(ted, ac->completions[0]); // (^ this calls autocomplete_close) - break; - default: - // open autocomplete menu - ac->open = true; - break; + return; } + + // open autocomplete menu + ac->open = true; } static void autocomplete_find_phantom(Ted *ted) { diff --git a/main.c b/main.c index eb883a1..d56aa2e 100644 --- a/main.c +++ b/main.c @@ -1,6 +1,5 @@ /* TODO: -- select sole completion if all completions' textEdits are identical (e.g. SyntaxCharT___ in ted) FUTURE FEATURES: - autodetect indentation (tabs vs spaces) - font setting & support for multiple fonts to cover more characters @@ -131,6 +130,7 @@ static void error_signal_handler(int signum, siginfo_t *info, void *context) { Ted *ted = error_signal_handler_ted; if (ted) { FILE *log = ted->log; + if (log) { fprintf(log, "Signal %d: %s\n", signum, strsignal(signum)); fprintf(log, "errno = %d\n", info->si_errno); diff --git a/ted.h b/ted.h index abfe991..cbc85a7 100644 --- a/ted.h +++ b/ted.h @@ -28,7 +28,7 @@ extern "C" { #include "sdl-inc.h" /// Version number -#define TED_VERSION "2.3.1" +#define TED_VERSION "2.3.2" /// Version string #define TED_VERSION_FULL "ted v. " TED_VERSION /// Maximum path size ted handles. -- cgit v1.2.3