mirror of
https://github.com/neovim/neovim.git
synced 2025-10-17 07:16:09 +00:00
vim-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 vim/vim#15296
fixes vim/vim#15295
fixes vim/vim#15294
closes: vim/vim#16032
f31cfa29bf
Co-authored-by: glepnir <glephunter@gmail.com>
This commit is contained in:
@@ -3620,11 +3620,18 @@ garray_T *fuzzy_match_str_with_pos(char *const str, const char *const pat)
|
||||
return match_positions;
|
||||
}
|
||||
|
||||
/// 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.
|
||||
static bool fuzzy_match_str_in_line(char **ptr, char *pat, int *len, pos_T *current_pos)
|
||||
/// 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.
|
||||
bool fuzzy_match_str_in_line(char **ptr, char *pat, int *len, pos_T *current_pos, int *score)
|
||||
{
|
||||
char *str = *ptr;
|
||||
char *strBegin = str;
|
||||
@@ -3649,14 +3656,16 @@ static bool fuzzy_match_str_in_line(char **ptr, char *pat, int *len, pos_T *curr
|
||||
*end = NUL;
|
||||
|
||||
// Perform fuzzy match
|
||||
int 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;
|
||||
}
|
||||
|
||||
@@ -3678,13 +3687,14 @@ static bool fuzzy_match_str_in_line(char **ptr, char *pat, int *len, pos_T *curr
|
||||
///
|
||||
/// Return true if a match is found, otherwise false.
|
||||
bool search_for_fuzzy_match(buf_T *buf, pos_T *pos, char *pattern, int dir, pos_T *start_pos,
|
||||
int *len, char **ptr, bool whole_line)
|
||||
int *len, char **ptr, int *score)
|
||||
{
|
||||
pos_T current_pos = *pos;
|
||||
pos_T circly_end;
|
||||
bool found_new_match = false;
|
||||
bool looped_around = false;
|
||||
|
||||
bool whole_line = ctrl_x_mode_whole_line();
|
||||
if (whole_line) {
|
||||
current_pos.lnum += dir;
|
||||
}
|
||||
@@ -3709,11 +3719,13 @@ bool search_for_fuzzy_match(buf_T *buf, pos_T *pos, char *pattern, int dir, pos_
|
||||
*ptr = ml_get_buf(buf, current_pos.lnum);
|
||||
// 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()) {
|
||||
if (strncmp(*ptr, pattern, (size_t)(*len)) == 0 && pattern[*len] == NUL) {
|
||||
@@ -4227,7 +4239,7 @@ search_line:
|
||||
const int 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;
|
||||
|
Reference in New Issue
Block a user