diff options
author | zeertzjq <zeertzjq@outlook.com> | 2022-08-14 19:11:36 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-08-14 19:11:36 +0800 |
commit | b1faf5f0b92356c5abb434cbb978c1db34f89c4a (patch) | |
tree | 6180d8b5d36e09b6874e3075110f87f1fa05dcda | |
parent | c77cce615b1bdacd60f98ba5f41540535d142a1f (diff) | |
download | rneovim-b1faf5f0b92356c5abb434cbb978c1db34f89c4a.tar.gz rneovim-b1faf5f0b92356c5abb434cbb978c1db34f89c4a.tar.bz2 rneovim-b1faf5f0b92356c5abb434cbb978c1db34f89c4a.zip |
vim-patch:8.2.4249: the timeout limit for spell suggestions is always 5000 (#19769)
Problem: The timeout limit for spell suggestions is always 5000 milli
seconds.
Solution: Add the "timeout" entry to 'spellsuggest'.
https://github.com/vim/vim/commit/585ee07cfef307b2fc828537e0d31fdc22d7e79f
-rw-r--r-- | runtime/doc/options.txt | 5 | ||||
-rw-r--r-- | src/nvim/spellsuggest.c | 22 | ||||
-rw-r--r-- | src/nvim/testdir/test_spell.vim | 10 |
3 files changed, 32 insertions, 5 deletions
diff --git a/runtime/doc/options.txt b/runtime/doc/options.txt index 614c6aec60..579c76d57e 100644 --- a/runtime/doc/options.txt +++ b/runtime/doc/options.txt @@ -5876,6 +5876,11 @@ A jump table for the options with a short description can be found at |Q_op|. suggestions is never more than the value of 'lines' minus two. + timeout:{millisec} Limit the time searching for suggestions to + {millisec} milli seconds. Applies to the following + methods. When omitted the limit is 5000. When + negative there is no limit. + file:{filename} Read file {filename}, which must have two columns, separated by a slash. The first column contains the bad word, the second column the suggested good word. diff --git a/src/nvim/spellsuggest.c b/src/nvim/spellsuggest.c index fe648bbbca..b4a9bed437 100644 --- a/src/nvim/spellsuggest.c +++ b/src/nvim/spellsuggest.c @@ -200,6 +200,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; + #ifdef INCLUDE_GENERATED_DECLARATIONS # include "spellsuggest.c.generated.h" #endif @@ -375,7 +377,10 @@ int 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 + || (!ascii_isdigit(buf[8]) + && !(buf[8] == '-' && ascii_isdigit(buf[9]))))) { f = -1; } @@ -473,6 +478,7 @@ void spell_suggest(int count) // Make a copy of current line since autocommands may free the line. line = vim_strsave(get_cursor_line_ptr()); + spell_suggest_timeout = 5000; // Get the list of suggestions. Limit to 'lines' - 2 or the number in // 'spellsuggest', whatever is smaller. @@ -769,6 +775,9 @@ static void spell_find_suggest(char_u *badptr, int badlen, suginfo_T *su, int ma } 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. spell_suggest_intern(su, interactive); @@ -1174,9 +1183,12 @@ static void suggest_trie_walk(suginfo_T *su, langp_T *lp, char_u *fword, bool so } } - // The loop may take an indefinite amount of time. Break out after five - // sectonds. TODO(vim): add an option for the time limit. - proftime_T time_limit = profile_setlimit(5000); + // The loop may take an indefinite amount of time. Break out after some + // time. + proftime_T time_limit; + if (spell_suggest_timeout > 0) { + time_limit = profile_setlimit(spell_suggest_timeout); + } // Loop to find all suggestions. At each round we either: // - For the current state try one operation, advance "ts_curi", @@ -2310,7 +2322,7 @@ static void suggest_trie_walk(suginfo_T *su, langp_T *lp, char_u *fword, bool so if (--breakcheckcount == 0) { os_breakcheck(); breakcheckcount = 1000; - if (profile_passed_limit(time_limit)) { + if (spell_suggest_timeout > 0 && profile_passed_limit(time_limit)) { got_int = true; } } diff --git a/src/nvim/testdir/test_spell.vim b/src/nvim/testdir/test_spell.vim index 7744c5bcca..8ab8204b10 100644 --- a/src/nvim/testdir/test_spell.vim +++ b/src/nvim/testdir/test_spell.vim @@ -474,6 +474,16 @@ func Test_spellsuggest_option_expr() bwipe! endfunc +func Test_spellsuggest_timeout() + set spellsuggest=timeout:30 + set spellsuggest=timeout:-123 + set spellsuggest=timeout:999999 + call assert_fails('set spellsuggest=timeout', 'E474:') + call assert_fails('set spellsuggest=timeout:x', 'E474:') + call assert_fails('set spellsuggest=timeout:-x', 'E474:') + call assert_fails('set spellsuggest=timeout:--9', 'E474:') +endfunc + func Test_spellinfo() throw 'skipped: Nvim does not support enc=latin1' new |