@@ -1157,62 +1157,17 @@ function! easycomplete#util#CompleteMenuFilter(all_menu, word, maxlength)
11571157 let word = substitute (word, " \\ ." , " \\\\\\\\ ." , " g" )
11581158 endif
11591159 if exists (' *matchfuzzy' )
1160- let fullmatch_result = [] " 完全匹配
1161- let firstchar_result = [] " 首字母匹配
1162- let fuzzymatching = []
11631160 let all_items = a: all_menu
11641161 " TODO here vim 里针对 g: 的匹配有 hack,word 前面减了两个字符,导致abbr
11651162 " 和 word 不是一一对应的,通过word fuzzy 匹配的位置无法正确应用在 abbr 上
11661163 " 这里只 hack 了 vim,其他类型的文件未测试
11671164 let key_name = (&filetype == " vim" ) ? " abbr" : " word"
11681165 let matching_res = all_items- >matchfuzzypos (word, {' key' : key_name})
1169- let fuzzymatching = matching_res[0 ]
1170- let fuzzy_position = matching_res[1 ]
1171- let fuzzy_scores = matching_res[2 ]
1172- let fuzzymatch_result = []
1173- if g: env_is_nvim && has (" nvim-0.6.1" )
1174- let count_i = 0
1175- while count_i < len (fuzzymatching)
1176- let abbr = get (fuzzymatching[count_i], " abbr" , " " )
1177- if empty (abbr)
1178- let fuzzymatching[count_i][" abbr" ] = fuzzymatching[count_i][" word" ]
1179- let abbr = fuzzymatching[count_i][" word" ]
1180- endif
1181- let abbr = easycomplete#util#parseAbbr (abbr)
1182- let fuzzymatching[count_i][" abbr" ] = abbr
1183- let p = fuzzy_position[count_i]
1184- let fuzzymatching[count_i][" abbr_marked" ] = s: ReplaceMent (abbr, p , " §" )
1185- let fuzzymatching[count_i][" marked_position" ] = p
1186- let fuzzymatching[count_i][" score" ] = fuzzy_scores[count_i]
1187-
1188- " 进行初步分检
1189- if stridx (toupper (fuzzymatching[count_i][" word" ]), toupper (word)) == 0
1190- " 完全匹配,放在fullmatch_result
1191- call add (fullmatch_result, fuzzymatching[count_i])
1192- elseif fuzzymatching[count_i][" word" ][0 ] == word[0 ]
1193- " 首字母匹配,放在firstchar_result
1194- call add (firstchar_result, fuzzymatching[count_i])
1195- else
1196- " 否则就是fuzzymatch的结果,放在 fuzzymatch_result 中
1197- call add (fuzzymatch_result, fuzzymatching[count_i])
1198- endif
1199- let count_i += 1
1200- endwhile
1201- if has (' nvim-0.7' )
1202- " 对 fuzzymatch_result 进行排序,TODO 似乎没有必要
1203- " call sort(fuzzymatch_result, {a, b -> b['score'] - a['score'] })
1204- endif
1205- endif
1206- if len (easycomplete#GetStuntMenuItems ()) == 0 && g: easycomplete_first_complete_hit == 1
1207- " 对fuzzymatch_result 进行长度排序
1208- call sort (fuzzymatch_result, " easycomplete#util#SortTextComparatorByLength" )
1209- endif
12101166 if g: env_is_nvim
1211- let filtered_menu = fullmatch_result + firstchar_result + fuzzymatch_result
1167+ return s: util_toolkit . complete_menu_filter (matching_res, word)
12121168 else
1213- let filtered_menu = fuzzymatching
1169+ return s: CompleteMenuFilterVim (matching_res, word)
12141170 endif
1215- return filtered_menu
12161171 else " for nvim(<=0.5.0)
12171172 " 完整匹配
12181173 let original_matching_menu = []
@@ -1287,6 +1242,57 @@ function! easycomplete#util#CompleteMenuFilter(all_menu, word, maxlength)
12871242 endif
12881243endfunction
12891244
1245+ function ! s: CompleteMenuFilterVim (matching_res, word)
1246+ let matching_res = a: matching_res
1247+ let word = a: word
1248+ let fullmatch_result = [] " 完全匹配
1249+ let firstchar_result = [] " 首字母匹配
1250+ let fuzzymatching = []
1251+ let fuzzymatching = matching_res[0 ]
1252+ let fuzzy_position = matching_res[1 ]
1253+ let fuzzy_scores = matching_res[2 ]
1254+ let fuzzymatch_result = []
1255+ if g: env_is_nvim && has (" nvim-0.6.1" )
1256+ let count_i = 0
1257+ while count_i < len (fuzzymatching)
1258+ let abbr = get (fuzzymatching[count_i], " abbr" , " " )
1259+ if empty (abbr)
1260+ let fuzzymatching[count_i][" abbr" ] = fuzzymatching[count_i][" word" ]
1261+ let abbr = fuzzymatching[count_i][" word" ]
1262+ endif
1263+ let abbr = easycomplete#util#parseAbbr (abbr)
1264+ let fuzzymatching[count_i][" abbr" ] = abbr
1265+ let p = fuzzy_position[count_i]
1266+ let fuzzymatching[count_i][" abbr_marked" ] = s: ReplaceMent (abbr, p , " §" )
1267+ let fuzzymatching[count_i][" marked_position" ] = p
1268+ let fuzzymatching[count_i][" score" ] = fuzzy_scores[count_i]
1269+
1270+ " 进行初步分检
1271+ if stridx (toupper (fuzzymatching[count_i][" word" ]), toupper (word)) == 0
1272+ " 完全匹配,放在fullmatch_result
1273+ call add (fullmatch_result, fuzzymatching[count_i])
1274+ elseif fuzzymatching[count_i][" word" ][0 ] == word[0 ]
1275+ " 首字母匹配,放在firstchar_result
1276+ call add (firstchar_result, fuzzymatching[count_i])
1277+ else
1278+ " 否则就是fuzzymatch的结果,放在 fuzzymatch_result 中
1279+ call add (fuzzymatch_result, fuzzymatching[count_i])
1280+ endif
1281+ let count_i += 1
1282+ endwhile
1283+ endif
1284+ if len (easycomplete#GetStuntMenuItems ()) == 0 && g: easycomplete_first_complete_hit == 1
1285+ " 对fuzzymatch_result 进行长度排序
1286+ call sort (fuzzymatch_result, " easycomplete#util#SortTextComparatorByLength" )
1287+ endif
1288+ if g: env_is_nvim
1289+ let filtered_menu = fullmatch_result + firstchar_result + fuzzymatch_result
1290+ else
1291+ let filtered_menu = fuzzymatching
1292+ endif
1293+ return filtered_menu
1294+ endfunction
1295+
12901296function ! easycomplete#util#ls (path )
12911297 let result_list = []
12921298 let is_win = has (' win32' ) || has (' win64' )
0 commit comments