comparison src/spellsuggest.c @ 27441:674240fcf6de v8.2.4249

patch 8.2.4249: the timeout limit for spell suggestions is always 5000 Commit: https://github.com/vim/vim/commit/585ee07cfef307b2fc828537e0d31fdc22d7e79f Author: Bram Moolenaar <Bram@vim.org> Date: Sat Jan 29 11:22:17 2022 +0000 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'.
author Bram Moolenaar <Bram@vim.org>
date Sat, 29 Jan 2022 12:30:02 +0100
parents d0096a7f8d96
children b7ed275ef02f
comparison
equal deleted inserted replaced
27440:1118a65c9bc7 27441:674240fcf6de
194 194
195 // special values ts_prefixdepth 195 // special values ts_prefixdepth
196 #define PFD_NOPREFIX 0xff // not using prefixes 196 #define PFD_NOPREFIX 0xff // not using prefixes
197 #define PFD_PREFIXTREE 0xfe // walking through the prefix tree 197 #define PFD_PREFIXTREE 0xfe // walking through the prefix tree
198 #define PFD_NOTSPECIAL 0xfd // highest value that's not special 198 #define PFD_NOTSPECIAL 0xfd // highest value that's not special
199
200 static long spell_suggest_timeout = 5000;
199 201
200 static void spell_find_suggest(char_u *badptr, int badlen, suginfo_T *su, int maxcount, int banbadword, int need_cap, int interactive); 202 static void spell_find_suggest(char_u *badptr, int badlen, suginfo_T *su, int maxcount, int banbadword, int need_cap, int interactive);
201 #ifdef FEAT_EVAL 203 #ifdef FEAT_EVAL
202 static void spell_suggest_expr(suginfo_T *su, char_u *expr); 204 static void spell_suggest_expr(suginfo_T *su, char_u *expr);
203 #endif 205 #endif
427 else if (STRCMP(buf, "fast") == 0) 429 else if (STRCMP(buf, "fast") == 0)
428 f = SPS_FAST; 430 f = SPS_FAST;
429 else if (STRCMP(buf, "double") == 0) 431 else if (STRCMP(buf, "double") == 0)
430 f = SPS_DOUBLE; 432 f = SPS_DOUBLE;
431 else if (STRNCMP(buf, "expr:", 5) != 0 433 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])))))
433 f = -1; 438 f = -1;
434 439
435 if (f == -1 || (sps_flags != 0 && f != 0)) 440 if (f == -1 || (sps_flags != 0 && f != 0))
436 { 441 {
437 sps_flags = SPS_BEST; 442 sps_flags = SPS_BEST;
840 845
841 // Make a copy of 'spellsuggest', because the expression may change it. 846 // Make a copy of 'spellsuggest', because the expression may change it.
842 sps_copy = vim_strsave(p_sps); 847 sps_copy = vim_strsave(p_sps);
843 if (sps_copy == NULL) 848 if (sps_copy == NULL)
844 return; 849 return;
850 spell_suggest_timeout = 5000;
845 851
846 // Loop over the items in 'spellsuggest'. 852 // Loop over the items in 'spellsuggest'.
847 for (p = sps_copy; *p != NUL; ) 853 for (p = sps_copy; *p != NUL; )
848 { 854 {
849 copy_option_part(&p, buf, MAXPATHL, ","); 855 copy_option_part(&p, buf, MAXPATHL, ",");
862 #endif 868 #endif
863 } 869 }
864 else if (STRNCMP(buf, "file:", 5) == 0) 870 else if (STRNCMP(buf, "file:", 5) == 0)
865 // Use list of suggestions in a file. 871 // Use list of suggestions in a file.
866 spell_suggest_file(su, buf + 5); 872 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);
867 else if (!did_intern) 876 else if (!did_intern)
868 { 877 {
869 // Use internal method once. 878 // Use internal method once.
870 spell_suggest_intern(su, interactive); 879 spell_suggest_intern(su, interactive);
871 if (sps_flags & SPS_DOUBLE) 880 if (sps_flags & SPS_DOUBLE)
1323 sp->ts_prefixdepth = PFD_NOPREFIX; 1332 sp->ts_prefixdepth = PFD_NOPREFIX;
1324 sp->ts_state = STATE_START; 1333 sp->ts_state = STATE_START;
1325 } 1334 }
1326 } 1335 }
1327 #ifdef FEAT_RELTIME 1336 #ifdef FEAT_RELTIME
1328 // The loop may take an indefinite amount of time. Break out after five 1337 // The loop may take an indefinite amount of time. Break out after some
1329 // sectonds. TODO: add an option for the time limit. 1338 // time.
1330 profile_setlimit(5000, &time_limit); 1339 if (spell_suggest_timeout > 0)
1340 profile_setlimit(spell_suggest_timeout, &time_limit);
1331 #endif 1341 #endif
1332 1342
1333 // Loop to find all suggestions. At each round we either: 1343 // Loop to find all suggestions. At each round we either:
1334 // - For the current state try one operation, advance "ts_curi", 1344 // - For the current state try one operation, advance "ts_curi",
1335 // increase "depth". 1345 // increase "depth".
2657 if (--breakcheckcount == 0) 2667 if (--breakcheckcount == 0)
2658 { 2668 {
2659 ui_breakcheck(); 2669 ui_breakcheck();
2660 breakcheckcount = 1000; 2670 breakcheckcount = 1000;
2661 #ifdef FEAT_RELTIME 2671 #ifdef FEAT_RELTIME
2662 if (profile_passed_limit(&time_limit)) 2672 if (spell_suggest_timeout > 0
2673 && profile_passed_limit(&time_limit))
2663 got_int = TRUE; 2674 got_int = TRUE;
2664 #endif 2675 #endif
2665 } 2676 }
2666 } 2677 }
2667 } 2678 }