From b0b0ed3359731b547eca3908c991ca16813b1e42 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 | 32 +++++++++++++++++--------------- 1 file changed, 17 insertions(+), 15 deletions(-) diff --git a/lua/plugins/completions.lua b/lua/plugins/completions.lua index 255e90a..b0f7518 100644 --- a/lua/plugins/completions.lua +++ b/lua/plugins/completions.lua @@ -11,31 +11,33 @@ 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 }, + }, + init = function() + local cmp = require("cmp") vim.api.nvim_create_autocmd("BufRead", { group = vim.api.nvim_create_augroup("CmpSourceCargo", { clear = true }),