From a860c4b21450df3d1784ca1e6a9ebf5009f09225 Mon Sep 17 00:00:00 2001 From: ayamir Date: Tue, 16 May 2023 22:22:27 +0800 Subject: [PATCH] feat(cmp): reimplement comparators for completion entries (#746) * feat(cmp): update sort logic. * fixup! feat(cmp): update sort logic * fixup commit --------- Co-authored-by: Jint-lzxy <50296129+Jint-lzxy@users.noreply.github.com> --- lua/modules/configs/completion/cmp.lua | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/lua/modules/configs/completion/cmp.lua b/lua/modules/configs/completion/cmp.lua index 07c39c0f4..4331b363b 100644 --- a/lua/modules/configs/completion/cmp.lua +++ b/lua/modules/configs/completion/cmp.lua @@ -21,15 +21,6 @@ return function() } end - local cmp_window = require("cmp.utils.window") - - cmp_window.info_ = cmp_window.info - cmp_window.info = function(self) - local info = self:info_() - info.scrollable = false - return info - end - local compare = require("cmp.config.compare") compare.lsp_scores = function(entry1, entry2) local diff @@ -71,13 +62,14 @@ return function() end local cmp = require("cmp") - cmp.setup({ + preselect = cmp.PreselectMode.Item, window = { completion = { border = border("Normal"), max_width = 80, max_height = 20, + scrollbar = false, }, documentation = { border = border("CmpDocBorder"), @@ -89,12 +81,16 @@ return function() require("copilot_cmp.comparators").prioritize, require("copilot_cmp.comparators").score, -- require("cmp_tabnine.compare"), - compare.offset, + compare.offset, -- Items closer to cursor will have lower priority compare.exact, + -- compare.scopes, compare.lsp_scores, + compare.sort_text, + compare.score, + compare.recently_used, + -- compare.locality, -- Items closer to cursor will have higher priority, conflicts with `offset` require("cmp-under-comparator").under, compare.kind, - compare.sort_text, compare.length, compare.order, }, @@ -110,6 +106,9 @@ return function() return kind end, }, + matching = { + disallow_partial_fuzzy_matching = false, + }, -- You can set mappings if you want mapping = cmp.mapping.preset.insert({ [""] = cmp.mapping.confirm({ select = true, behavior = cmp.ConfirmBehavior.Replace }), @@ -144,7 +143,7 @@ return function() }, -- You should specify your *installed* sources. sources = { - { name = "nvim_lsp" }, + { name = "nvim_lsp", max_item_count = 350 }, { name = "nvim_lua" }, { name = "luasnip" }, { name = "path" },