diff --git a/README.md b/README.md index 79dca1b..ba8e3e4 100644 --- a/README.md +++ b/README.md @@ -237,7 +237,7 @@ The source specific keyword_length for override. The source specific maximum item count. -#### sources[number].group (type: number) +#### sources[number].group_index (type: number) The source group index. diff --git a/lua/cmp/config/sources.lua b/lua/cmp/config/sources.lua index e0ee8dc..cfb09c0 100644 --- a/lua/cmp/config/sources.lua +++ b/lua/cmp/config/sources.lua @@ -2,7 +2,7 @@ return function(...) local sources = {} for i, group in ipairs({ ... }) do for _, source in ipairs(group) do - source.group = i + source.group_index = i table.insert(sources, source) end end diff --git a/lua/cmp/view.lua b/lua/cmp/view.lua index 2082c30..b785c3b 100644 --- a/lua/cmp/view.lua +++ b/lua/cmp/view.lua @@ -50,17 +50,17 @@ view.open = function(self, ctx, sources) while true do group_index = group_index + 1 - local group = vim.tbl_filter(function(s) - return (s:get_config().group or 1) == group_index + local source_group = vim.tbl_filter(function(s) + return (s:get_config().group_index or 1) == group_index end, sources) - if #group == 0 then + if #source_group == 0 then break end -- check the source triggered by character local has_triggered_by_symbol_source = false - for _, s in ipairs(group) do + for _, s in ipairs(source_group) do if #s:get_entries(ctx) > 0 then if s.is_triggered_by_symbol then has_triggered_by_symbol_source = true @@ -71,11 +71,11 @@ view.open = function(self, ctx, sources) -- create filtered entries. local offset = ctx.cursor.col - for i, s in ipairs(group) do + for i, s in ipairs(source_group) do if s.offset <= offset then if not has_triggered_by_symbol_source or s.is_triggered_by_symbol then -- source order priority bonus. - local priority = s:get_config().priority or ((#group - (i - 1)) * config.get().sorting.priority_weight) + local priority = s:get_config().priority or ((#source_group - (i - 1)) * config.get().sorting.priority_weight) for _, e in ipairs(s:get_entries(ctx)) do e.score = e.score + priority