diff --git a/README.md b/README.md index 922015d..e524f8a 100644 --- a/README.md +++ b/README.md @@ -230,6 +230,11 @@ The source name. The source customization options. It is defined by each source. +#### sources[number].priority (type: number|nil) + +The manually specified source priority. +If you don't specifies it, The source priority will determine by the default algorithm (see `sorting.priority_weight`). + #### sources[number].keyword_pattern (type: string) The source specific keyword_pattern for override. diff --git a/lua/cmp/menu.lua b/lua/cmp/menu.lua index 4f74292..f2d3d56 100644 --- a/lua/cmp/menu.lua +++ b/lua/cmp/menu.lua @@ -89,7 +89,7 @@ menu.update = function(self, ctx, sources) 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 = (#sources - (i - 1)) * config.get().sorting.priority_weight + local priority = s:get_config().priority or ((#sources - (i - 1)) * config.get().sorting.priority_weight) for _, e in ipairs(s:get_entries(ctx)) do e.score = e.score + priority diff --git a/lua/cmp/types/cmp.lua b/lua/cmp/types/cmp.lua index aa68f2a..c79386c 100644 --- a/lua/cmp/types/cmp.lua +++ b/lua/cmp/types/cmp.lua @@ -100,6 +100,7 @@ cmp.PreselectMode.None = 'none' ---@class cmp.SourceConfig ---@field public name string ---@field public opts table +---@field public priority number|nil ---@field public keyword_pattern string ---@field public keyword_length number ---@field public max_item_count number