feat(cmp): added custom comparator to prioritize AI sources like copilot and codeium
This commit is contained in:
3 files changed
+22
-3
No files matched your search
@@ -45,6 +45,26 @@ return {
|
||||
vim.api.nvim_set_hl(0, "CmpGhostText", { link = "Comment", default = true })
|
||||
local cmp = require("cmp")
|
||||
local defaults = require("cmp.config.default")()
|
||||
|
||||
-- LazyVim extension to prioritise certain sources
|
||||
defaults.sorting.primary = {}
|
||||
|
||||
---@param entry Cmp.Entry
|
||||
local function is_primary(entry)
|
||||
local config = require("cmp.config").global
|
||||
return vim.tbl_contains(config.sorting.primary or {}, entry.source:get_debug_name())
|
||||
end
|
||||
|
||||
table.insert(defaults.sorting.comparators, 1, function(a, b)
|
||||
local aa = is_primary(a)
|
||||
local bb = is_primary(b)
|
||||
if aa and not bb then
|
||||
return true
|
||||
end
|
||||
if not aa and bb then
|
||||
return false
|
||||
end
|
||||
end)
|
||||
return {
|
||||
completion = {
|
||||
completeopt = "menu,menuone,noinsert",
|
||||
|
||||
@@ -18,7 +18,7 @@ return {
|
||||
---@param opts cmp.ConfigSchema
|
||||
opts = function(_, opts)
|
||||
table.insert(opts.sources, 1, { name = "codeium", group_index = 1 })
|
||||
opts.sorting = opts.sorting or require("cmp.config.default")().sorting
|
||||
table.insert(opts.sorting.primary, "codeium")
|
||||
end,
|
||||
},
|
||||
}
|
||||
@@ -71,8 +71,7 @@ return {
|
||||
---@param opts cmp.ConfigSchema
|
||||
opts = function(_, opts)
|
||||
table.insert(opts.sources, 1, { name = "copilot", group_index = 1 })
|
||||
opts.sorting = opts.sorting or require("cmp.config.default")().sorting
|
||||
table.insert(opts.sorting.comparators, 1, require("copilot_cmp.comparators").prioritize)
|
||||
table.insert(opts.sorting.primary, "copilot")
|
||||
end,
|
||||
},
|
||||
}
|
||||
Reference in new issue
Block a user