From ac2fc3a4c15887bb68db4bd310f2f81537791ffb Mon Sep 17 00:00:00 2001 From: Sam-programs Date: Sat, 14 Oct 2023 13:44:17 +0300 Subject: [PATCH] added a check to make sure the sorter doesn't get loaded twice --- lua/nvim-autopairs/completion/cmp.lua | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/lua/nvim-autopairs/completion/cmp.lua b/lua/nvim-autopairs/completion/cmp.lua index 7900a81f..22332221 100644 --- a/lua/nvim-autopairs/completion/cmp.lua +++ b/lua/nvim-autopairs/completion/cmp.lua @@ -51,9 +51,9 @@ M.on_confirm_done = function(opts) return function(evt) if evt.commit_character then - return + return end - + local entry = evt.entry local commit_character = entry:get_commit_characters() local bufnr = vim.api.nvim_get_current_buf() @@ -62,11 +62,11 @@ M.on_confirm_done = function(opts) -- Without options and fallback if not opts.filetypes[filetype] and not opts.filetypes["*"] then - return + return end if opts.filetypes[filetype] == false then - return + return end -- If filetype is nil then use * @@ -84,6 +84,7 @@ M.on_confirm_done = function(opts) end end +local loaded_cpp_sort = false M.cpp_pairs = function() local cmp_config = require('cmp.config') local cmp_comparetors = cmp_config.get().sorting.comparators @@ -103,15 +104,17 @@ M.cpp_pairs = function() end return nil end - - cmp.setup({ - sorting = { - comparators = { - cpp_sort_cmp, - unpack(cmp_comparetors), + if loaded_cpp_sort == false then + cmp.setup({ + sorting = { + comparators = { + cpp_sort_cmp, + unpack(cmp_comparetors), + } } - } - }) + }) + loaded_cpp_sort = true + end return function(evt) if not (vim.o.filetype == "c" or vim.o.filetype == "cpp") then return