Skip to content

Commit 5875500

Browse files
committed
add all
1 parent c0e2e39 commit 5875500

File tree

3 files changed

+52
-2
lines changed

3 files changed

+52
-2
lines changed

autoload/easycomplete/sources/buf.vim

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ function! s:GetBufKeywordsList(typing)
9898
" 性能测试:分检出 84238 个单词
9999
" lua: 0.021
100100
" vim: 0.147
101-
if easycomplete#util#HasLua()
101+
if g:env_is_nvim
102102
let local_kwlist = s:lua_toolkit.get_buf_keywords(lines)
103103
else
104104
for line in lines
@@ -111,7 +111,7 @@ function! s:GetBufKeywordsList(typing)
111111
endif
112112
endfor
113113
" call easycomplete#util#StartRecord()
114-
if easycomplete#util#HasLua()
114+
if g:env_is_nvim
115115
" 匹配首字符
116116
" 58424 → 3623 0.010739
117117
" 匹配前三个起始字符

autoload/easycomplete/util.vim

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
""" 常用的工具函数
22
scriptencoding utf-8
3+
let s:lua_toolkit = g:env_is_nvim ? v:lua.require("easycomplete") : v:null
34

45
" get file extention {{{
56
function! easycomplete#util#extention()
@@ -903,6 +904,10 @@ endfunction
903904
"popup 菜单内关键词去重,只做buff、dict和lsp里的keyword去重
904905
"snippet 不去重
905906
function! easycomplete#util#distinct(menu_list)
907+
if g:env_is_nvim
908+
let result_items = s:lua_toolkit.distinct_keywords(a:menu_list)
909+
return result_items
910+
endif
906911
if empty(a:menu_list) || len(a:menu_list) == 0
907912
return []
908913
endif

lua/easycomplete.lua

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,4 +201,49 @@ function EasyComplete.filter(match_list, needle)
201201
return result
202202
end
203203

204+
-- 假设 s:GetItemWord(item) 在 Lua 中对应 item.word
205+
local function get_item_word(item)
206+
return item.word or ""
207+
end
208+
209+
function EasyComplete.distinct_keywords(menu_list)
210+
if not menu_list or #menu_list == 0 then
211+
return {}
212+
end
213+
214+
local result_items = vim.deepcopy(menu_list)
215+
local buf_list = {}
216+
217+
-- 第一步:收集所有来自 'buf' 的 word
218+
for _, item in ipairs(menu_list) do
219+
local plugin_name = item.plugin_name or ""
220+
if plugin_name == "buf" then
221+
table.insert(buf_list, item.word)
222+
end
223+
end
224+
225+
-- 第二步:如果 word 被 buf 包含,且是 buf 类型,则从结果中移除
226+
for _, item in ipairs(menu_list) do
227+
local plugin_name = item.plugin_name or ""
228+
if plugin_name == "buf" or plugin_name == "snips" then
229+
goto continue
230+
end
231+
232+
local word = get_item_word(item)
233+
if vim.tbl_contains(buf_list, word) then
234+
-- 过滤掉 result_items 中 plugin_name == "buf" 且 word 相同的项
235+
for i = #result_items, 1, -1 do
236+
local it = result_items[i]
237+
if (it.plugin_name == "buf") and (it.word == word) then
238+
table.remove(result_items, i)
239+
end
240+
end
241+
end
242+
243+
::continue::
244+
end
245+
246+
return result_items
247+
end
248+
204249
return EasyComplete

0 commit comments

Comments
 (0)