From 27d3e45df61d6695357219dc72a71d41aac385e6 Mon Sep 17 00:00:00 2001 From: Folke Lemaitre Date: Wed, 28 Jun 2023 11:24:54 +0200 Subject: [PATCH] refactor(cmp): move comparator config to cmp spec --- lua/lazyvim/plugins/coding.lua | 2 ++ lua/lazyvim/plugins/extras/coding/copilot.lua | 23 ++----------------- 2 files changed, 4 insertions(+), 21 deletions(-) diff --git a/lua/lazyvim/plugins/coding.lua b/lua/lazyvim/plugins/coding.lua index 41085ad2..ca43111d 100644 --- a/lua/lazyvim/plugins/coding.lua +++ b/lua/lazyvim/plugins/coding.lua @@ -44,6 +44,7 @@ return { opts = function() vim.api.nvim_set_hl(0, "CmpGhostText", { link = "Comment", default = true }) local cmp = require("cmp") + local defaults = require("cmp.config.default")() return { completion = { completeopt = "menu,menuone,noinsert", @@ -86,6 +87,7 @@ return { hl_group = "CmpGhostText", }, }, + sorting = defaults.sorting, } end, }, diff --git a/lua/lazyvim/plugins/extras/coding/copilot.lua b/lua/lazyvim/plugins/extras/coding/copilot.lua index 764537f4..bed0d4e9 100644 --- a/lua/lazyvim/plugins/extras/coding/copilot.lua +++ b/lua/lazyvim/plugins/extras/coding/copilot.lua @@ -70,28 +70,9 @@ return { }, ---@param opts cmp.ConfigSchema opts = function(_, opts) - local cmp = require("cmp") - table.insert(opts.sources, 1, { name = "copilot", group_index = 2 }) - - opts.sorting = { - priority_weight = 2, - comparators = { - require("copilot_cmp.comparators").prioritize, - - -- Below is the default comparitor list and order for nvim-cmp - cmp.config.compare.offset, - -- cmp.config.compare.scopes, --this is commented in nvim-cmp too - cmp.config.compare.exact, - cmp.config.compare.score, - cmp.config.compare.recently_used, - cmp.config.compare.locality, - cmp.config.compare.kind, - cmp.config.compare.sort_text, - cmp.config.compare.length, - cmp.config.compare.order, - }, - } + opts.sorting = opts.sorting or require("cmp.config.default")().sorting + table.insert(opts.sorting.comparators, 1, require("copilot_cmp.comparators").prioritize) end, }, }