Skip to content

Commit

Permalink
added a check to make sure the sorter doesn't get loaded twice
Browse files Browse the repository at this point in the history
  • Loading branch information
Sam-programs authored and Sam-programs committed Oct 14, 2023
1 parent 9e6381c commit ac2fc3a
Showing 1 changed file with 15 additions and 12 deletions.
27 changes: 15 additions & 12 deletions lua/nvim-autopairs/completion/cmp.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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 *
Expand All @@ -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
Expand All @@ -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
Expand Down

0 comments on commit ac2fc3a

Please sign in to comment.