comparison src/quickfix.c @ 24547:192058cad081 v8.2.2813

patch 8.2.2813: cannot grep using fuzzy matching Commit: https://github.com/vim/vim/commit/bb01a1ef3a093cdb36877ba73474719c531dc8cb Author: Yegappan Lakshmanan <yegappan@yahoo.com> Date: Mon Apr 26 21:17:52 2021 +0200 patch 8.2.2813: cannot grep using fuzzy matching Problem: Cannot grep using fuzzy matching. Solution: Add the "f" flag to :vimgrep. (Yegappan Lakshmanan, closes https://github.com/vim/vim/issues/8152)
author Bram Moolenaar <Bram@vim.org>
date Mon, 26 Apr 2021 21:30:04 +0200
parents e1643a1aa1a0
children 3a3d5ee00574
comparison
equal deleted inserted replaced
24546:eb6c05ae77f9 24547:192058cad081
5910 static int 5910 static int
5911 vgr_match_buflines( 5911 vgr_match_buflines(
5912 qf_list_T *qfl, 5912 qf_list_T *qfl,
5913 char_u *fname, 5913 char_u *fname,
5914 buf_T *buf, 5914 buf_T *buf,
5915 char_u *spat,
5915 regmmatch_T *regmatch, 5916 regmmatch_T *regmatch,
5916 long *tomatch, 5917 long *tomatch,
5917 int duplicate_name, 5918 int duplicate_name,
5918 int flags) 5919 int flags)
5919 { 5920 {
5920 int found_match = FALSE; 5921 int found_match = FALSE;
5921 long lnum; 5922 long lnum;
5922 colnr_T col; 5923 colnr_T col;
5924 int pat_len = STRLEN(spat);
5923 5925
5924 for (lnum = 1; lnum <= buf->b_ml.ml_line_count && *tomatch > 0; ++lnum) 5926 for (lnum = 1; lnum <= buf->b_ml.ml_line_count && *tomatch > 0; ++lnum)
5925 { 5927 {
5926 col = 0; 5928 col = 0;
5927 while (vim_regexec_multi(regmatch, curwin, buf, lnum, 5929 if (!(flags & VGR_FUZZY))
5928 col, NULL, NULL) > 0) 5930 {
5929 { 5931 // Regular expression match
5930 // Pass the buffer number so that it gets used even for a 5932 while (vim_regexec_multi(regmatch, curwin, buf, lnum,
5931 // dummy buffer, unless duplicate_name is set, then the 5933 col, NULL, NULL) > 0)
5932 // buffer will be wiped out below.
5933 if (qf_add_entry(qfl,
5934 NULL, // dir
5935 fname,
5936 NULL,
5937 duplicate_name ? 0 : buf->b_fnum,
5938 ml_get_buf(buf,
5939 regmatch->startpos[0].lnum + lnum, FALSE),
5940 regmatch->startpos[0].lnum + lnum,
5941 regmatch->startpos[0].col + 1,
5942 FALSE, // vis_col
5943 NULL, // search pattern
5944 0, // nr
5945 0, // type
5946 TRUE // valid
5947 ) == QF_FAIL)
5948 { 5934 {
5949 got_int = TRUE; 5935 // Pass the buffer number so that it gets used even for a
5950 break; 5936 // dummy buffer, unless duplicate_name is set, then the
5937 // buffer will be wiped out below.
5938 if (qf_add_entry(qfl,
5939 NULL, // dir
5940 fname,
5941 NULL,
5942 duplicate_name ? 0 : buf->b_fnum,
5943 ml_get_buf(buf,
5944 regmatch->startpos[0].lnum + lnum, FALSE),
5945 regmatch->startpos[0].lnum + lnum,
5946 regmatch->startpos[0].col + 1,
5947 FALSE, // vis_col
5948 NULL, // search pattern
5949 0, // nr
5950 0, // type
5951 TRUE // valid
5952 ) == QF_FAIL)
5953 {
5954 got_int = TRUE;
5955 break;
5956 }
5957 found_match = TRUE;
5958 if (--*tomatch == 0)
5959 break;
5960 if ((flags & VGR_GLOBAL) == 0
5961 || regmatch->endpos[0].lnum > 0)
5962 break;
5963 col = regmatch->endpos[0].col
5964 + (col == regmatch->endpos[0].col);
5965 if (col > (colnr_T)STRLEN(ml_get_buf(buf, lnum, FALSE)))
5966 break;
5951 } 5967 }
5952 found_match = TRUE; 5968 }
5953 if (--*tomatch == 0) 5969 else
5954 break; 5970 {
5955 if ((flags & VGR_GLOBAL) == 0 5971 char_u *str = ml_get_buf(buf, lnum, FALSE);
5956 || regmatch->endpos[0].lnum > 0) 5972 int score;
5957 break; 5973 int_u matches[MAX_FUZZY_MATCHES];
5958 col = regmatch->endpos[0].col 5974 int_u sz = sizeof(matches) / sizeof(matches[0]);
5959 + (col == regmatch->endpos[0].col); 5975
5960 if (col > (colnr_T)STRLEN(ml_get_buf(buf, lnum, FALSE))) 5976 // Fuzzy string match
5961 break; 5977 while (fuzzy_match(str + col, spat, FALSE, &score, matches, sz) > 0)
5978 {
5979 // Pass the buffer number so that it gets used even for a
5980 // dummy buffer, unless duplicate_name is set, then the
5981 // buffer will be wiped out below.
5982 if (qf_add_entry(qfl,
5983 NULL, // dir
5984 fname,
5985 NULL,
5986 duplicate_name ? 0 : buf->b_fnum,
5987 str,
5988 lnum,
5989 matches[0] + col + 1,
5990 FALSE, // vis_col
5991 NULL, // search pattern
5992 0, // nr
5993 0, // type
5994 TRUE // valid
5995 ) == QF_FAIL)
5996 {
5997 got_int = TRUE;
5998 break;
5999 }
6000 found_match = TRUE;
6001 if (--*tomatch == 0)
6002 break;
6003 if ((flags & VGR_GLOBAL) == 0)
6004 break;
6005 col = matches[pat_len - 1] + col + 1;
6006 if (col > (colnr_T)STRLEN(str))
6007 break;
6008 }
5962 } 6009 }
5963 line_breakcheck(); 6010 line_breakcheck();
5964 if (got_int) 6011 if (got_int)
5965 break; 6012 break;
5966 } 6013 }
6161 else 6208 else
6162 { 6209 {
6163 // Try for a match in all lines of the buffer. 6210 // Try for a match in all lines of the buffer.
6164 // For ":1vimgrep" look for first match only. 6211 // For ":1vimgrep" look for first match only.
6165 found_match = vgr_match_buflines(qf_get_curlist(qi), 6212 found_match = vgr_match_buflines(qf_get_curlist(qi),
6166 fname, buf, &cmd_args->regmatch, 6213 fname, buf, cmd_args->spat, &cmd_args->regmatch,
6167 &cmd_args->tomatch, duplicate_name, cmd_args->flags); 6214 &cmd_args->tomatch, duplicate_name, cmd_args->flags);
6168 6215
6169 if (using_dummy) 6216 if (using_dummy)
6170 { 6217 {
6171 if (found_match && *first_match_buf == NULL) 6218 if (found_match && *first_match_buf == NULL)