Skip to content

Commit

Permalink
fix: cmp snippets source selecting issue (#1309)
Browse files Browse the repository at this point in the history
* migrate(cmp): `cmp_nvim_lsp` capabilities API update

* feat(cmp): make `<CR>` safer
  • Loading branch information
CharlesChiuGit authored Jul 1, 2024
1 parent 07a165b commit b1406ca
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
12 changes: 11 additions & 1 deletion lua/modules/configs/completion/cmp.lua
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,6 @@ return function()
},
-- You can set mappings if you want
mapping = cmp.mapping.preset.insert({
["<CR>"] = cmp.mapping.confirm({ select = false, behavior = cmp.ConfirmBehavior.Replace }),
["<C-p>"] = cmp.mapping.select_prev_item(),
["<C-n>"] = cmp.mapping.select_next_item(),
["<C-d>"] = cmp.mapping.scroll_docs(-4),
Expand All @@ -151,6 +150,17 @@ return function()
fallback()
end
end, { "i", "s" }),
["<CR>"] = cmp.mapping({
i = function(fallback)
if cmp.visible() and cmp.get_active_entry() then
cmp.confirm({ behavior = cmp.ConfirmBehavior.Insert, select = false })
else
fallback()
end
end,
s = cmp.mapping.confirm({ select = true }),
c = cmp.mapping.confirm({ behavior = cmp.ConfirmBehavior.Insert, select = true }),
}),
}),
snippet = {
expand = function(args)
Expand Down
6 changes: 5 additions & 1 deletion lua/modules/configs/completion/mason-lspconfig.lua
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,11 @@ M.setup = function()
})

local opts = {
capabilities = require("cmp_nvim_lsp").default_capabilities(vim.lsp.protocol.make_client_capabilities()),
capabilities = vim.tbl_deep_extend(
"force",
vim.lsp.protocol.make_client_capabilities(),
require("cmp_nvim_lsp").default_capabilities()
),
}
---A handler to setup all servers defined under `completion/servers/*.lua`
---@param lsp_name string
Expand Down

0 comments on commit b1406ca

Please sign in to comment.