vim-patch:9.1.1625: Autocompletion slow with include- and tag-completion (#35318)

Problem:  Autocompletion slow with include- and tag-completion
Solution: Refactor ins_compl_interrupted() to also check for timeout,
          further refactor code to skip outputting message when
          performing autocompletion (Girish Palya).

Running `vim *` in `vim/src` was slower than expected when
'autocomplete' was enabled. Include-file and tag-file completion
sources were not subject to the timeout check, causing unnecessary
delays.

So apply the timeout check to these sources as well, improving
autocompletion responsiveness, refactor find_pattern_in_path() to take
an additional "silent" argument, to suppress any messages.

closes: vim/vim#17966

59e1d7f353

Co-authored-by: Girish Palya <girishji@gmail.com>
This commit is contained in:
zeertzjq
2025-08-13 07:14:49 +08:00
committed by GitHub
parent 76a383bb7b
commit 50ceac4054
5 changed files with 15 additions and 20 deletions

View File

@@ -7070,7 +7070,7 @@ static void ex_checkpath(exarg_T *eap)
{
find_pattern_in_path(NULL, 0, 0, false, false, CHECK_PATH, 1,
eap->forceit ? ACTION_SHOW_ALL : ACTION_SHOW,
1, (linenr_T)MAXLNUM, eap->forceit);
1, (linenr_T)MAXLNUM, eap->forceit, false);
}
/// ":psearch"
@@ -7128,8 +7128,8 @@ static void ex_findpat(exarg_T *eap)
}
if (!eap->skip) {
find_pattern_in_path(eap->arg, 0, strlen(eap->arg), whole, !eap->forceit,
*eap->cmd == 'd' ? FIND_DEFINE : FIND_ANY,
n, action, eap->line1, eap->line2, eap->forceit);
*eap->cmd == 'd' ? FIND_DEFINE : FIND_ANY, n, action,
eap->line1, eap->line2, eap->forceit, false);
}
}

View File

@@ -1885,7 +1885,7 @@ static void ins_compl_files(int count, char **files, bool thesaurus, int flags,
char *leader = in_fuzzy_collect ? ins_compl_leader() : NULL;
int leader_len = in_fuzzy_collect ? (int)ins_compl_leader_len() : 0;
for (int i = 0; i < count && !got_int && !compl_interrupted && !compl_time_slice_expired; i++) {
for (int i = 0; i < count && !got_int && !ins_compl_interrupted(); i++) {
FILE *fp = os_fopen(files[i], "r"); // open dictionary file
if (flags != DICT_EXACT && !shortmess(SHM_COMPLETIONSCAN) && !compl_autocomplete) {
msg_hist_off = true; // reset in msg_trunc()
@@ -1901,8 +1901,7 @@ static void ins_compl_files(int count, char **files, bool thesaurus, int flags,
// Read dictionary file line by line.
// Check each line for a match.
while (!got_int && !compl_interrupted && !compl_time_slice_expired
&& !vim_fgets(buf, LSIZE, fp)) {
while (!got_int && !ins_compl_interrupted() && !vim_fgets(buf, LSIZE, fp)) {
char *ptr = buf;
if (regmatch != NULL) {
while (vim_regexec(regmatch, buf, (colnr_T)(ptr - buf))) {
@@ -2087,7 +2086,7 @@ void ins_compl_init_get_longest(void)
/// Returns true when insert completion is interrupted.
bool ins_compl_interrupted(void)
{
return compl_interrupted;
return compl_interrupted || compl_time_slice_expired;
}
/// Returns true if the <Enter> key selects a match in the completion popup
@@ -3387,11 +3386,7 @@ void f_complete_check(typval_T *argvars, typval_T *rettv, EvalFuncData fptr)
RedrawingDisabled = 0;
ins_compl_check_keys(0, true);
if (compl_autocomplete && compl_time_slice_expired) {
rettv->vval.v_number = true;
} else {
rettv->vval.v_number = ins_compl_interrupted();
}
RedrawingDisabled = saved;
}
@@ -3852,7 +3847,7 @@ static void get_next_include_file_completion(int compl_type)
((compl_type == CTRL_X_PATH_DEFINES
&& !(compl_cont_status & CONT_SOL))
? FIND_DEFINE : FIND_ANY),
1, ACTION_EXPAND, 1, MAXLNUM, false);
1, ACTION_EXPAND, 1, MAXLNUM, false, compl_autocomplete);
}
/// Get the next set of words matching "compl_pattern" in dictionary or

View File

@@ -4237,7 +4237,7 @@ static void nv_brackets(cmdarg_T *cap)
? curwin->w_cursor.lnum + 1
: 1),
MAXLNUM,
false);
false, false);
xfree(ptr);
curwin->w_set_curswant = true;
}

View File

@@ -3852,9 +3852,10 @@ static char *get_line_and_copy(linenr_T lnum, char *buf)
/// @param start_lnum first line to start searching
/// @param end_lnum last line for searching
/// @param forceit If true, always switch to the found path
/// @param silent Do not print messages when ACTION_EXPAND
void find_pattern_in_path(char *ptr, Direction dir, size_t len, bool whole, bool skip_comments,
int type, int count, int action, linenr_T start_lnum, linenr_T end_lnum,
int forceit)
bool forceit, bool silent)
{
SearchedFile *files; // Stack of included files
SearchedFile *bigger; // When we need more space
@@ -4082,7 +4083,7 @@ void find_pattern_in_path(char *ptr, Direction dir, size_t len, bool whole, bool
files[depth].name = curr_fname = new_fname;
files[depth].lnum = 0;
files[depth].matched = false;
if (action == ACTION_EXPAND) {
if (action == ACTION_EXPAND && !shortmess(SHM_COMPLETIONSCAN) && !silent) {
msg_hist_off = true; // reset in msg_trunc()
vim_snprintf(IObuff, IOSIZE,
_("Scanning included file: %s"),
@@ -4411,8 +4412,7 @@ exit_matched:
msg(_("No included files"), 0);
}
}
} else if (!found
&& action != ACTION_EXPAND) {
} else if (!found && action != ACTION_EXPAND && !silent) {
if (got_int || ins_compl_interrupted()) {
emsg(_(e_interr));
} else if (type == FIND_DEFINE) {

View File

@@ -640,8 +640,8 @@ wingotofile:
// Make a copy, if the line was changed it will be freed.
ptr = xmemdupz(ptr, len);
find_pattern_in_path(ptr, 0, len, true, Prenum == 0,
type, Prenum1, ACTION_SPLIT, 1, MAXLNUM, false);
find_pattern_in_path(ptr, 0, len, true, Prenum == 0, type,
Prenum1, ACTION_SPLIT, 1, MAXLNUM, false, false);
xfree(ptr);
curwin->w_set_curswant = true;
break;