summaryrefslogtreecommitdiff
path: root/src/spellsuggest.c
diff options
context:
space:
mode:
authorBram Moolenaar <Bram@vim.org>2022-01-29 11:22:17 +0000
committerBram Moolenaar <Bram@vim.org>2022-01-29 11:22:17 +0000
commit585ee07cfef307b2fc828537e0d31fdc22d7e79f (patch)
tree7c39c5284f81ce21a3b5919c6ad0c6de3171ecbe /src/spellsuggest.c
parenta0c4e2f2d7aa164d9d7692702c752ea063bd3a8c (diff)
downloadvim-git-585ee07cfef307b2fc828537e0d31fdc22d7e79f.tar.gz
patch 8.2.4249: the timeout limit for spell suggestions is always 5000v8.2.4249
Problem: The timeout limit for spell suggestions is always 5000 milli seconds. Solution: Add the "timeout" entry to 'spellsuggest'.
Diffstat (limited to 'src/spellsuggest.c')
-rw-r--r--src/spellsuggest.c21
1 files changed, 16 insertions, 5 deletions
diff --git a/src/spellsuggest.c b/src/spellsuggest.c
index e54b6fdc8..3cd45352f 100644
--- a/src/spellsuggest.c
+++ b/src/spellsuggest.c
@@ -197,6 +197,8 @@ typedef struct trystate_S
#define PFD_PREFIXTREE 0xfe // walking through the prefix tree
#define PFD_NOTSPECIAL 0xfd // highest value that's not special
+static long spell_suggest_timeout = 5000;
+
static void spell_find_suggest(char_u *badptr, int badlen, suginfo_T *su, int maxcount, int banbadword, int need_cap, int interactive);
#ifdef FEAT_EVAL
static void spell_suggest_expr(suginfo_T *su, char_u *expr);
@@ -429,7 +431,10 @@ spell_check_sps(void)
else if (STRCMP(buf, "double") == 0)
f = SPS_DOUBLE;
else if (STRNCMP(buf, "expr:", 5) != 0
- && STRNCMP(buf, "file:", 5) != 0)
+ && STRNCMP(buf, "file:", 5) != 0
+ && (STRNCMP(buf, "timeout:", 8) != 0
+ || (!VIM_ISDIGIT(buf[8])
+ && !(buf[8] == '-' && VIM_ISDIGIT(buf[9])))))
f = -1;
if (f == -1 || (sps_flags != 0 && f != 0))
@@ -842,6 +847,7 @@ spell_find_suggest(
sps_copy = vim_strsave(p_sps);
if (sps_copy == NULL)
return;
+ spell_suggest_timeout = 5000;
// Loop over the items in 'spellsuggest'.
for (p = sps_copy; *p != NUL; )
@@ -864,6 +870,9 @@ spell_find_suggest(
else if (STRNCMP(buf, "file:", 5) == 0)
// Use list of suggestions in a file.
spell_suggest_file(su, buf + 5);
+ else if (STRNCMP(buf, "timeout:", 8) == 0)
+ // Limit the time searching for suggestions.
+ spell_suggest_timeout = atol((char *)buf + 8);
else if (!did_intern)
{
// Use internal method once.
@@ -1325,9 +1334,10 @@ suggest_trie_walk(
}
}
#ifdef FEAT_RELTIME
- // The loop may take an indefinite amount of time. Break out after five
- // sectonds. TODO: add an option for the time limit.
- profile_setlimit(5000, &time_limit);
+ // The loop may take an indefinite amount of time. Break out after some
+ // time.
+ if (spell_suggest_timeout > 0)
+ profile_setlimit(spell_suggest_timeout, &time_limit);
#endif
// Loop to find all suggestions. At each round we either:
@@ -2659,7 +2669,8 @@ suggest_trie_walk(
ui_breakcheck();
breakcheckcount = 1000;
#ifdef FEAT_RELTIME
- if (profile_passed_limit(&time_limit))
+ if (spell_suggest_timeout > 0
+ && profile_passed_limit(&time_limit))
got_int = TRUE;
#endif
}