Skip to content

Commit 0be03e1

Browse files
glepnirchrisbra
authored andcommitted
patch 9.1.0605: internal error with fuzzy completion
Problem: internal error with fuzzy completion (techntools) Solution: only fuzzy complete the pattern after directory separator (glepnir) fixes: #15287 closes: #15291 Signed-off-by: glepnir <[email protected]> Signed-off-by: Christian Brabandt <[email protected]>
1 parent b14c325 commit 0be03e1

File tree

4 files changed

+51
-10
lines changed

4 files changed

+51
-10
lines changed

src/insexpand.c

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3537,11 +3537,41 @@ get_next_filename_completion(void)
35373537
int in_fuzzy = ((get_cot_flags() & COT_FUZZY) != 0 && leader_len > 0);
35383538
char_u **sorted_matches;
35393539
int *fuzzy_indices_data;
3540+
char_u *last_sep = NULL;
3541+
size_t path_with_wildcard_len;
3542+
char_u *path_with_wildcard;
35403543

35413544
if (in_fuzzy)
35423545
{
3543-
vim_free(compl_pattern);
3544-
compl_pattern = vim_strsave((char_u *)"*");
3546+
last_sep = vim_strrchr(leader, PATHSEP);
3547+
if (last_sep == NULL)
3548+
{
3549+
// No path separator or separator is the last character,
3550+
// fuzzy match the whole leader
3551+
vim_free(compl_pattern);
3552+
compl_pattern = vim_strsave((char_u *)"*");
3553+
compl_patternlen = STRLEN(compl_pattern);
3554+
}
3555+
else if (*(last_sep + 1) == '\0')
3556+
in_fuzzy = FALSE;
3557+
else
3558+
{
3559+
// Split leader into path and file parts
3560+
int path_len = last_sep - leader + 1;
3561+
path_with_wildcard_len = path_len + 2;
3562+
path_with_wildcard = alloc(path_with_wildcard_len);
3563+
if (path_with_wildcard != NULL)
3564+
{
3565+
vim_strncpy(path_with_wildcard, leader, path_len);
3566+
vim_strcat(path_with_wildcard, (char_u *)"*", path_with_wildcard_len);
3567+
vim_free(compl_pattern);
3568+
compl_pattern = path_with_wildcard;
3569+
compl_patternlen = STRLEN(compl_pattern);
3570+
3571+
// Move leader to the file part
3572+
leader = last_sep + 1;
3573+
}
3574+
}
35453575
}
35463576

35473577
if (expand_wildcards(1, &compl_pattern, &num_matches, &matches,

src/search.c

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5222,15 +5222,16 @@ search_for_fuzzy_match(
52225222
if (whole_line)
52235223
current_pos.lnum += dir;
52245224

5225+
if (buf == curbuf)
5226+
circly_end = *start_pos;
5227+
else
5228+
{
5229+
circly_end.lnum = buf->b_ml.ml_line_count;
5230+
circly_end.col = 0;
5231+
circly_end.coladd = 0;
5232+
}
5233+
52255234
do {
5226-
if (buf == curbuf)
5227-
circly_end = *start_pos;
5228-
else
5229-
{
5230-
circly_end.lnum = buf->b_ml.ml_line_count;
5231-
circly_end.col = 0;
5232-
circly_end.coladd = 0;
5233-
}
52345235

52355236
// Check if looped around and back to start position
52365237
if (looped_around && EQUAL_POS(current_pos, circly_end))
@@ -5255,6 +5256,8 @@ search_for_fuzzy_match(
52555256
*pos = current_pos;
52565257
break;
52575258
}
5259+
else if (looped_around && current_pos.lnum == circly_end.lnum)
5260+
break;
52585261
}
52595262
else
52605263
{

src/testdir/test_ins_complete.vim

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2625,6 +2625,10 @@ func Test_complete_fuzzy_match()
26252625
call assert_equal('fobar', getline('.'))
26262626
call feedkeys("Sfob\<C-X>\<C-f>\<C-N>\<Esc>0", 'tx!')
26272627
call assert_equal('foobar', getline('.'))
2628+
call feedkeys("S../\<C-X>\<C-f>\<Esc>0", 'tx!')
2629+
call assert_match('../*', getline('.'))
2630+
call feedkeys("S../td\<C-X>\<C-f>\<Esc>0", 'tx!')
2631+
call assert_match('../testdir', getline('.'))
26282632

26292633
" can get completion from other buffer
26302634
set completeopt=fuzzy,menu,menuone
@@ -2639,6 +2643,8 @@ func Test_complete_fuzzy_match()
26392643
call assert_equal('Omnipotent', getline('.'))
26402644
call feedkeys("Somp\<C-P>\<C-P>\<Esc>0", 'tx!')
26412645
call assert_equal('Composite', getline('.'))
2646+
call feedkeys("S omp\<C-N>\<Esc>0", 'tx!')
2647+
call assert_equal(' completeness', getline('.'))
26422648

26432649
" fuzzy on whole line completion
26442650
call setline(1, ["world is on fire", "no one can save me but you", 'user can execute', ''])

src/version.c

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

705705
static int included_patches[] =
706706
{ /* Add new patch number below this line */
707+
/**/
708+
605,
707709
/**/
708710
604,
709711
/**/

0 commit comments

Comments
 (0)