Skip to content

Commit 59e1d7f

Browse files
girishjichrisbra
authored andcommitted
patch 9.1.1625: Autocompletion slow with include- and tag-completion
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: #17966 Signed-off-by: Girish Palya <[email protected]> Signed-off-by: Christian Brabandt <[email protected]>
1 parent 639d93f commit 59e1d7f

7 files changed

Lines changed: 23 additions & 22 deletions

File tree

src/ex_docmd.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9432,8 +9432,8 @@ exec_normal(int was_typed, int use_vpeekc, int may_use_terminal_loop UNUSED)
94329432
ex_checkpath(exarg_T *eap)
94339433
{
94349434
find_pattern_in_path(NULL, 0, 0, FALSE, FALSE, CHECK_PATH, 1L,
9435-
eap->forceit ? ACTION_SHOW_ALL : ACTION_SHOW,
9436-
(linenr_T)1, (linenr_T)MAXLNUM, eap->forceit);
9435+
eap->forceit ? ACTION_SHOW_ALL : ACTION_SHOW,
9436+
(linenr_T)1, (linenr_T)MAXLNUM, eap->forceit, FALSE);
94379437
}
94389438

94399439
#if defined(FEAT_QUICKFIX)
@@ -9501,9 +9501,9 @@ ex_findpat(exarg_T *eap)
95019501
}
95029502
if (!eap->skip)
95039503
find_pattern_in_path(eap->arg, 0, (int)STRLEN(eap->arg),
9504-
whole, !eap->forceit,
9505-
*eap->cmd == 'd' ? FIND_DEFINE : FIND_ANY,
9506-
n, action, eap->line1, eap->line2, eap->forceit);
9504+
whole, !eap->forceit,
9505+
*eap->cmd == 'd' ? FIND_DEFINE : FIND_ANY, n, action,
9506+
eap->line1, eap->line2, eap->forceit, FALSE);
95079507
}
95089508
#endif
95099509

src/insexpand.c

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2042,8 +2042,7 @@ ins_compl_files(
20422042
leader_len = (int)ins_compl_leader_len();
20432043
}
20442044

2045-
for (i = 0; i < count && !got_int && !compl_interrupted
2046-
&& !compl_time_slice_expired; i++)
2045+
for (i = 0; i < count && !got_int && !ins_compl_interrupted(); i++)
20472046
{
20482047
fp = mch_fopen((char *)files[i], "r"); // open dictionary file
20492048
if (flags != DICT_EXACT && !shortmess(SHM_COMPLETIONSCAN)
@@ -2060,7 +2059,7 @@ ins_compl_files(
20602059

20612060
// Read dictionary file line by line.
20622061
// Check each line for a match.
2063-
while (!got_int && !compl_interrupted && !compl_time_slice_expired
2062+
while (!got_int && !ins_compl_interrupted()
20642063
&& !vim_fgets(buf, LSIZE, fp))
20652064
{
20662065
ptr = buf;
@@ -2297,7 +2296,7 @@ ins_compl_init_get_longest(void)
22972296
int
22982297
ins_compl_interrupted(void)
22992298
{
2300-
return compl_interrupted;
2299+
return compl_interrupted || compl_time_slice_expired;
23012300
}
23022301

23032302
/*
@@ -3841,10 +3840,7 @@ f_complete_check(typval_T *argvars UNUSED, typval_T *rettv)
38413840
RedrawingDisabled = 0;
38423841

38433842
ins_compl_check_keys(0, TRUE);
3844-
if (compl_autocomplete && compl_time_slice_expired)
3845-
rettv->vval.v_number = TRUE;
3846-
else
3847-
rettv->vval.v_number = ins_compl_interrupted();
3843+
rettv->vval.v_number = ins_compl_interrupted();
38483844

38493845
RedrawingDisabled = save_RedrawingDisabled;
38503846
}
@@ -4462,7 +4458,7 @@ get_next_include_file_completion(int compl_type)
44624458
(compl_type == CTRL_X_PATH_DEFINES
44634459
&& !(compl_cont_status & CONT_SOL))
44644460
? FIND_DEFINE : FIND_ANY, 1L, ACTION_EXPAND,
4465-
(linenr_T)1, (linenr_T)MAXLNUM, FALSE);
4461+
(linenr_T)1, (linenr_T)MAXLNUM, FALSE, compl_autocomplete);
44664462
}
44674463
#endif
44684464

src/normal.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4478,7 +4478,7 @@ nv_brackets(cmdarg_T *cap)
44784478
SAFE_islower(cap->nchar) ? ACTION_SHOW : ACTION_GOTO,
44794479
cap->cmdchar == ']' ? curwin->w_cursor.lnum + 1 : (linenr_T)1,
44804480
(linenr_T)MAXLNUM,
4481-
FALSE);
4481+
FALSE, FALSE);
44824482
vim_free(ptr);
44834483
curwin->w_set_curswant = TRUE;
44844484
}

src/proto/search.pro

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ int check_linecomment(char_u *line);
3333
void showmatch(int c);
3434
int current_search(long count, int forward);
3535
int linewhite(linenr_T lnum);
36-
void find_pattern_in_path(char_u *ptr, int dir, int len, int whole, int skip_comments, int type, long count, int action, linenr_T start_lnum, linenr_T end_lnum, int forceit);
36+
void find_pattern_in_path(char_u *ptr, int dir, int len, int whole, int skip_comments, int type, long count, int action, linenr_T start_lnum, linenr_T end_lnum, int forceit, int silent);
3737
spat_T *get_spat(int idx);
3838
int get_spat_last_idx(void);
3939
void f_searchcount(typval_T *argvars, typval_T *rettv);

src/search.c

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3406,7 +3406,8 @@ find_pattern_in_path(
34063406
int action, // What to do when we find it
34073407
linenr_T start_lnum, // first line to start searching
34083408
linenr_T end_lnum, // last line for searching
3409-
int forceit) // If true, always switch to the found path
3409+
int forceit, // If true, always switch to the found path
3410+
int silent) // Do not print messages when ACTION_EXPAND
34103411
{
34113412
SearchedFile *files; // Stack of included files
34123413
SearchedFile *bigger; // When we need more space
@@ -3680,7 +3681,8 @@ find_pattern_in_path(
36803681
files[depth].name = curr_fname = new_fname;
36813682
files[depth].lnum = 0;
36823683
files[depth].matched = FALSE;
3683-
if (action == ACTION_EXPAND)
3684+
if (action == ACTION_EXPAND
3685+
&& !shortmess(SHM_COMPLETIONSCAN) && !silent)
36843686
{
36853687
msg_hist_off = TRUE; // reset in msg_trunc_attr()
36863688
vim_snprintf((char*)IObuff, IOSIZE,
@@ -3909,8 +3911,8 @@ find_pattern_in_path(
39093911
else if (action == ACTION_SHOW)
39103912
{
39113913
show_pat_in_path(line, type, did_show, action,
3912-
(depth == -1) ? NULL : files[depth].fp,
3913-
(depth == -1) ? &lnum : &files[depth].lnum, 1L);
3914+
(depth == -1) ? NULL : files[depth].fp,
3915+
(depth == -1) ? &lnum : &files[depth].lnum, 1L);
39143916
did_show = TRUE;
39153917
}
39163918
else
@@ -4060,7 +4062,7 @@ find_pattern_in_path(
40604062
msg(_("No included files"));
40614063
}
40624064
}
4063-
else if (!found && action != ACTION_EXPAND)
4065+
else if (!found && action != ACTION_EXPAND && !silent)
40644066
{
40654067
if (got_int || ins_compl_interrupted())
40664068
emsg(_(e_interrupted));

src/version.c

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

720720
static int included_patches[] =
721721
{ /* Add new patch number below this line */
722+
/**/
723+
1625,
722724
/**/
723725
1624,
724726
/**/

src/window.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -698,7 +698,8 @@ do_window(
698698

699699
find_pattern_in_path(ptr, 0, len, TRUE,
700700
Prenum == 0 ? TRUE : FALSE, type,
701-
Prenum1, ACTION_SPLIT, (linenr_T)1, (linenr_T)MAXLNUM, FALSE);
701+
Prenum1, ACTION_SPLIT, (linenr_T)1, (linenr_T)MAXLNUM,
702+
FALSE, FALSE);
702703
vim_free(ptr);
703704
curwin->w_set_curswant = TRUE;
704705
break;

0 commit comments

Comments
 (0)