From 2f70f5ac8389b7990b8888a9bde4e90174542cdf Mon Sep 17 00:00:00 2001 From: Price Hiller Date: Wed, 20 Nov 2024 13:04:06 -0600 Subject: [PATCH] refactor(nvim): improve sorting of cmp comparators --- .../.config/nvim/lua/plugins/configs/cmp.lua | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/users/price/dots/.config/nvim/lua/plugins/configs/cmp.lua b/users/price/dots/.config/nvim/lua/plugins/configs/cmp.lua index 3a400e07..dee540d4 100644 --- a/users/price/dots/.config/nvim/lua/plugins/configs/cmp.lua +++ b/users/price/dots/.config/nvim/lua/plugins/configs/cmp.lua @@ -68,6 +68,7 @@ return { local cmp = require("cmp") local str = require("cmp.utils.str") local compare = cmp.config.compare + local cmp_types = require("cmp.types") local luasnip = require("luasnip") -- Load Snippets @@ -107,7 +108,7 @@ return { "--max-depth 4", }, }, - { name = "zsh", max_item_count = 5 }, + { name = "zsh", max_item_count = 3 }, { name = "npm", keyword_length = 2 }, } @@ -284,13 +285,18 @@ return { sorting = { priority_weight = 2, comparators = { - compare.locality, - compare.recently_used, - compare.score, require("cmp_fuzzy_buffer.compare"), + compare.locality, compare.offset, compare.exact, - -- Copied from cmp-under-comparator + compare.score, + compare.recently_used, + compare.kind, + compare.length, + compare.order, + --- Copied from cmp-under-comparator + ---@param entry1 cmp.Entry + ---@param entry2 cmp.Entry function(entry1, entry2) local _, entry1_under = entry1.completion_item.label:find("^_+") local _, entry2_under = entry2.completion_item.label:find("^_+") @@ -349,7 +355,6 @@ return { cmp.setup.cmdline(":", { mapping = cmp.mapping.preset.cmdline(), sources = cmp.config.sources({ - { name = "cmdline_history", max_item_count = 3 }, { name = "cmdline", option = { @@ -359,6 +364,7 @@ return { }, priority = 100, }, + { name = "cmdline_history", max_item_count = 3 }, }), }) end,