Skip to content

Commit 585ee07

Browse files
committed
patch 8.2.4249: the timeout limit for spell suggestions is always 5000
Problem: The timeout limit for spell suggestions is always 5000 milli seconds. Solution: Add the "timeout" entry to 'spellsuggest'.
1 parent a0c4e2f commit 585ee07

File tree

4 files changed

+34
-5
lines changed

4 files changed

+34
-5
lines changed

runtime/doc/options.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7363,6 +7363,12 @@ A jump table for the options with a short description can be found at |Q_op|.
73637363
suggestions is never more than the value of 'lines'
73647364
minus two.
73657365

7366+
timeout:{millisec} Limit the time searching for suggestions to
7367+
{millisec} milli seconds. Applies to the following
7368+
methods. When omitted the limit is 5000. When
7369+
negative there is no limit. {only works when built
7370+
with the +reltime feature}
7371+
73667372
file:{filename} Read file {filename}, which must have two columns,
73677373
separated by a slash. The first column contains the
73687374
bad word, the second column the suggested good word.

src/spellsuggest.c

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,8 @@ typedef struct trystate_S
197197
#define PFD_PREFIXTREE 0xfe // walking through the prefix tree
198198
#define PFD_NOTSPECIAL 0xfd // highest value that's not special
199199

200+
static long spell_suggest_timeout = 5000;
201+
200202
static void spell_find_suggest(char_u *badptr, int badlen, suginfo_T *su, int maxcount, int banbadword, int need_cap, int interactive);
201203
#ifdef FEAT_EVAL
202204
static void spell_suggest_expr(suginfo_T *su, char_u *expr);
@@ -429,7 +431,10 @@ spell_check_sps(void)
429431
else if (STRCMP(buf, "double") == 0)
430432
f = SPS_DOUBLE;
431433
else if (STRNCMP(buf, "expr:", 5) != 0
432-
&& STRNCMP(buf, "file:", 5) != 0)
434+
&& STRNCMP(buf, "file:", 5) != 0
435+
&& (STRNCMP(buf, "timeout:", 8) != 0
436+
|| (!VIM_ISDIGIT(buf[8])
437+
&& !(buf[8] == '-' && VIM_ISDIGIT(buf[9])))))
433438
f = -1;
434439

435440
if (f == -1 || (sps_flags != 0 && f != 0))
@@ -842,6 +847,7 @@ spell_find_suggest(
842847
sps_copy = vim_strsave(p_sps);
843848
if (sps_copy == NULL)
844849
return;
850+
spell_suggest_timeout = 5000;
845851

846852
// Loop over the items in 'spellsuggest'.
847853
for (p = sps_copy; *p != NUL; )
@@ -864,6 +870,9 @@ spell_find_suggest(
864870
else if (STRNCMP(buf, "file:", 5) == 0)
865871
// Use list of suggestions in a file.
866872
spell_suggest_file(su, buf + 5);
873+
else if (STRNCMP(buf, "timeout:", 8) == 0)
874+
// Limit the time searching for suggestions.
875+
spell_suggest_timeout = atol((char *)buf + 8);
867876
else if (!did_intern)
868877
{
869878
// Use internal method once.
@@ -1325,9 +1334,10 @@ suggest_trie_walk(
13251334
}
13261335
}
13271336
#ifdef FEAT_RELTIME
1328-
// The loop may take an indefinite amount of time. Break out after five
1329-
// sectonds. TODO: add an option for the time limit.
1330-
profile_setlimit(5000, &time_limit);
1337+
// The loop may take an indefinite amount of time. Break out after some
1338+
// time.
1339+
if (spell_suggest_timeout > 0)
1340+
profile_setlimit(spell_suggest_timeout, &time_limit);
13311341
#endif
13321342

13331343
// Loop to find all suggestions. At each round we either:
@@ -2659,7 +2669,8 @@ suggest_trie_walk(
26592669
ui_breakcheck();
26602670
breakcheckcount = 1000;
26612671
#ifdef FEAT_RELTIME
2662-
if (profile_passed_limit(&time_limit))
2672+
if (spell_suggest_timeout > 0
2673+
&& profile_passed_limit(&time_limit))
26632674
got_int = TRUE;
26642675
#endif
26652676
}

src/testdir/test_spell.vim

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -446,6 +446,16 @@ func Test_spellsuggest_expr_errors()
446446
delfunc MySuggest3
447447
endfunc
448448

449+
func Test_spellsuggest_timeout()
450+
set spellsuggest=timeout:30
451+
set spellsuggest=timeout:-123
452+
set spellsuggest=timeout:999999
453+
call assert_fails('set spellsuggest=timeout', 'E474:')
454+
call assert_fails('set spellsuggest=timeout:x', 'E474:')
455+
call assert_fails('set spellsuggest=timeout:-x', 'E474:')
456+
call assert_fails('set spellsuggest=timeout:--9', 'E474:')
457+
endfunc
458+
449459
func Test_spellinfo()
450460
new
451461
let runtime = substitute($VIMRUNTIME, '\\', '/', 'g')

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -750,6 +750,8 @@ static char *(features[]) =
750750

751751
static int included_patches[] =
752752
{ /* Add new patch number below this line */
753+
/**/
754+
4249,
753755
/**/
754756
4248,
755757
/**/

0 commit comments

Comments
 (0)