patch 9.1.1178: not possible to generate completion candidates using fuzzy matching
Problem: not possible to generate completion candidates using fuzzy
matching
Solution: add the 'completefuzzycollect' option for (some) ins-completion
modes (glepnir)
fixes #15296
fixes #15295
fixes #15294
closes: #16032
Signed-off-by: glepnir <glephunter@gmail.com>
Signed-off-by: Christian Brabandt <cb@256bit.org>
diff --git a/src/search.c b/src/search.c
index 3519c32..67082a7 100644
--- a/src/search.c
+++ b/src/search.c
@@ -53,7 +53,6 @@
static void fuzzy_match_str_sort(fuzmatch_str_T *fm, int sz);
static int fuzzy_match_func_compare(const void *s1, const void *s2);
static void fuzzy_match_func_sort(fuzmatch_str_T *fm, int sz);
-static int fuzzy_match_str_in_line(char_u **ptr, char_u *pat, int *len, pos_T *current_pos);
#define SEARCH_STAT_DEF_TIMEOUT 40L
#define SEARCH_STAT_DEF_MAX_COUNT 99
@@ -3867,7 +3866,7 @@
add_r = ins_compl_add_infercase(aux, i, p_ic,
curr_fname == curbuf->b_fname ? NULL : curr_fname,
- dir, cont_s_ipos);
+ dir, cont_s_ipos, 0);
if (add_r == OK)
// if dir was BACKWARD then honor it just once
dir = FORWARD;
@@ -5221,20 +5220,31 @@
}
/*
- * This function searches for a fuzzy match of the pattern `pat` within the
- * line pointed to by `*ptr`. It splits the line into words, performs fuzzy
- * matching on each word, and returns the length and position of the first
- * matched word.
+ * This function splits the line pointed to by `*ptr` into words and performs
+ * a fuzzy match for the pattern `pat` on each word. It iterates through the
+ * line, moving `*ptr` to the start of each word during the process.
+ *
+ * If a match is found:
+ * - `*ptr` points to the start of the matched word.
+ * - `*len` is set to the length of the matched word.
+ * - `*score` contains the match score.
+ *
+ * If no match is found, `*ptr` is updated to point beyond the last word
+ * or to the end of the line.
*/
- static int
-fuzzy_match_str_in_line(char_u **ptr, char_u *pat, int *len, pos_T *current_pos)
+ int
+fuzzy_match_str_in_line(
+ char_u **ptr,
+ char_u *pat,
+ int *len,
+ pos_T *current_pos,
+ int *score)
{
char_u *str = *ptr;
char_u *strBegin = str;
char_u *end = NULL;
char_u *start = NULL;
int found = FALSE;
- int result;
char save_end;
if (str == NULL || pat == NULL)
@@ -5253,15 +5263,16 @@
*end = NUL;
// Perform fuzzy match
- result = fuzzy_match_str(start, pat);
+ *score = fuzzy_match_str(start, pat);
*end = save_end;
- if (result > 0)
+ if (*score > 0)
{
*len = (int)(end - start);
- current_pos->col += (int)(end - strBegin);
found = TRUE;
*ptr = start;
+ if (current_pos)
+ current_pos->col += (int)(end - strBegin);
break;
}
@@ -5292,13 +5303,14 @@
pos_T *start_pos,
int *len,
char_u **ptr,
- int whole_line)
+ int *score)
{
pos_T current_pos = *pos;
pos_T circly_end;
int found_new_match = FALSE;
int looped_around = FALSE;
+ int whole_line = ctrl_x_mode_whole_line();
if (whole_line)
current_pos.lnum += dir;
@@ -5324,13 +5336,15 @@
*ptr = ml_get_buf(buf, current_pos.lnum, FALSE);
// If ptr is end of line is reached, move to next line
// or previous line based on direction
- if (**ptr != NUL)
+ if (*ptr != NULL && **ptr != NUL)
{
if (!whole_line)
{
*ptr += current_pos.col;
- // Try to find a fuzzy match in the current line starting from current position
- found_new_match = fuzzy_match_str_in_line(ptr, pattern, len, ¤t_pos);
+ // Try to find a fuzzy match in the current line starting
+ // from current position
+ found_new_match = fuzzy_match_str_in_line(ptr, pattern,
+ len, ¤t_pos, score);
if (found_new_match)
{
if (ctrl_x_mode_normal())