From bab5a727ef63da2fcfcdc2a2064c9368945119d5 Mon Sep 17 00:00:00 2001 From: CharlesChiuGit Date: Thu, 27 Jun 2024 11:41:33 +0800 Subject: [PATCH 1/2] migrate(cmp): `cmp_nvim_lsp` capabilities API update --- lua/modules/configs/completion/mason-lspconfig.lua | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lua/modules/configs/completion/mason-lspconfig.lua b/lua/modules/configs/completion/mason-lspconfig.lua index c345c7f78..567ff9f94 100644 --- a/lua/modules/configs/completion/mason-lspconfig.lua +++ b/lua/modules/configs/completion/mason-lspconfig.lua @@ -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 From 5c793ef591018317bccf974771c6251b9b1f8adc Mon Sep 17 00:00:00 2001 From: CharlesChiuGit Date: Sun, 30 Jun 2024 11:49:05 +0000 Subject: [PATCH 2/2] feat(cmp): make `` safer --- lua/modules/configs/completion/cmp.lua | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/lua/modules/configs/completion/cmp.lua b/lua/modules/configs/completion/cmp.lua index 0c84b0199..d9676a107 100644 --- a/lua/modules/configs/completion/cmp.lua +++ b/lua/modules/configs/completion/cmp.lua @@ -127,7 +127,6 @@ return function() }, -- You can set mappings if you want mapping = cmp.mapping.preset.insert({ - [""] = cmp.mapping.confirm({ select = false, behavior = cmp.ConfirmBehavior.Replace }), [""] = cmp.mapping.select_prev_item(), [""] = cmp.mapping.select_next_item(), [""] = cmp.mapping.scroll_docs(-4), @@ -151,6 +150,17 @@ return function() fallback() end end, { "i", "s" }), + [""] = 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)