From a19f0efee50426c447a074a71d24afc25a5cc22b Mon Sep 17 00:00:00 2001 From: kalmenn Date: Mon, 2 Dec 2024 14:31:37 +0100 Subject: [PATCH] refactor(completions): Make nvim-cmp's config more idiomatic --- lua/plugins/completions.lua | 34 +++++++++++++++++++--------------- 1 file changed, 19 insertions(+), 15 deletions(-) diff --git a/lua/plugins/completions.lua b/lua/plugins/completions.lua index 255e90a..e9bc21f 100644 --- a/lua/plugins/completions.lua +++ b/lua/plugins/completions.lua @@ -11,31 +11,35 @@ return { "L3MON4D3/LuaSnip", "saadparwaiz1/cmp_luasnip", }, - config = function() + opts = function() local cmp = require("cmp") - cmp.setup({ + return { + window = { + completion = cmp.config.window.bordered(), + }, snippet = { expand = function(args) require("luasnip").lsp_expand(args.body) end, }, - window = { - completion = cmp.config.window.bordered(), - -- documentation = cmp.config.window.bordered(), - }, - mapping = cmp.mapping.preset.insert({ - [""] = cmp.mapping.scroll_docs(-4), - [""] = cmp.mapping.scroll_docs(4), - [""] = cmp.mapping.abort(), - [""] = cmp.mapping.confirm({ select = false }), - }), - sources = cmp.config.sources({ + sources = { { name = "nvim_lsp", priority = 2 }, { name = "luasnip", priority = 1 }, { name = "buffer" }, - }), - }) + }, + } + end, + keys = { + { "", function() require("cmp").mapping.scroll_docs(-4) end }, + { "", function() require("cmp").mapping.scroll_docs(4) end }, + { "", function() require("cmp").mapping.abort() end }, + { "", function() require("cmp").mapping.confirm({ select = false }) end }, + }, + config = function(_, opts) + local cmp = require("cmp") + + cmp.setup(opts) vim.api.nvim_create_autocmd("BufRead", { group = vim.api.nvim_create_augroup("CmpSourceCargo", { clear = true }),