Improve group handling
This commit is contained in:
@@ -241,8 +241,6 @@ The source specific maximum item count.
|
|||||||
|
|
||||||
The source group index.
|
The source group index.
|
||||||
|
|
||||||
This option must be sequential order.
|
|
||||||
|
|
||||||
You can call built-in utility like `cmp.config.sources({ { name = 'a' } }, { { name = 'b' } })`.
|
You can call built-in utility like `cmp.config.sources({ { name = 'a' } }, { { name = 'b' } })`.
|
||||||
|
|
||||||
#### preselect (type: cmp.PreselectMode)
|
#### preselect (type: cmp.PreselectMode)
|
||||||
|
|||||||
@@ -120,6 +120,6 @@ cmp.ItemField.Menu = 'menu'
|
|||||||
---@field public keyword_pattern string
|
---@field public keyword_pattern string
|
||||||
---@field public keyword_length number
|
---@field public keyword_length number
|
||||||
---@field public max_item_count number
|
---@field public max_item_count number
|
||||||
---@field public group number
|
---@field public group_index number
|
||||||
|
|
||||||
return cmp
|
return cmp
|
||||||
|
|||||||
@@ -45,18 +45,23 @@ end
|
|||||||
---@param ctx cmp.Context
|
---@param ctx cmp.Context
|
||||||
---@param sources cmp.Source[]
|
---@param sources cmp.Source[]
|
||||||
view.open = function(self, ctx, sources)
|
view.open = function(self, ctx, sources)
|
||||||
local group_index = 0
|
local source_group_map = {}
|
||||||
local entries = {}
|
for _, s in ipairs(sources) do
|
||||||
while true do
|
local group_index = s:get_config().group_index or 0
|
||||||
group_index = group_index + 1
|
if not source_group_map[group_index] then
|
||||||
|
source_group_map[group_index] = {}
|
||||||
local source_group = vim.tbl_filter(function(s)
|
|
||||||
return (s:get_config().group_index or 1) == group_index
|
|
||||||
end, sources)
|
|
||||||
|
|
||||||
if #source_group == 0 then
|
|
||||||
break
|
|
||||||
end
|
end
|
||||||
|
table.insert(source_group_map[group_index], s)
|
||||||
|
end
|
||||||
|
|
||||||
|
local group_indexes = vim.tbl_keys(source_group_map)
|
||||||
|
table.sort(group_indexes, function(a, b)
|
||||||
|
return a ~= b and (a < b) or nil
|
||||||
|
end)
|
||||||
|
|
||||||
|
local entries = {}
|
||||||
|
for _, group_index in ipairs(group_indexes) do
|
||||||
|
local source_group = source_group_map[group_index] or {}
|
||||||
|
|
||||||
-- check the source triggered by character
|
-- check the source triggered by character
|
||||||
local has_triggered_by_symbol_source = false
|
local has_triggered_by_symbol_source = false
|
||||||
|
|||||||
Reference in New Issue
Block a user