From c609feeb4af7f0c5d28c2818dc7d237eeb6781d7 Mon Sep 17 00:00:00 2001 From: Kyren223 Date: Mon, 8 Jul 2024 22:45:55 +0300 Subject: Neovim: mostly finished configuring completions, maybe some extra addons in the future --- .config/nvim/lua/custom/completion.lua | 30 +++++++++++++++++++++--------- 1 file changed, 21 insertions(+), 9 deletions(-) (limited to '.config/nvim/lua/custom/completion.lua') diff --git a/.config/nvim/lua/custom/completion.lua b/.config/nvim/lua/custom/completion.lua index 04ae172..507d807 100644 --- a/.config/nvim/lua/custom/completion.lua +++ b/.config/nvim/lua/custom/completion.lua @@ -1,5 +1,6 @@ require('custom.snippets.lua') local luasnip = require('luasnip') +local lspkind = require('lspkind') local cmp = require('cmp') -- Enable paretheses for function completions @@ -36,21 +37,24 @@ cmp.setup({ enabled = is_enabled, completion = { completeopt = 'menu,menuone,noinsert' }, sources = cmp.config.sources({ - { name = 'nvim_lsp' }, - { name = 'luasnip' }, + { name = 'nvim_lsp' }, -- for lsp + { name = 'luasnip' }, -- for snippets { name = 'lazydev', group_index = 0 }, -- for lazydev.nvim { name = 'path' }, -- for filesystem - }), - + }, {}), snippet = { expand = function(args) luasnip.lsp_expand(args.body) end, }, window = { - -- TODO: Decide if I like borders or not - completion = cmp.config.window.bordered(), documentation = cmp.config.window.bordered(), + completion = { + border = 'rounded', + winhighlight = 'Normal:Pmenu,FloatBorder:Pmenu,Search:None', + col_offset = -3, + side_padding = 0, + }, }, mapping = cmp.mapping.preset.insert({ [''] = tab(true), @@ -60,10 +64,18 @@ cmp.setup({ [''] = cmp.mapping.scroll_docs(-4), [''] = cmp.mapping.scroll_docs(4), [''] = cmp.mapping.abort(), - -- NOTE: Select makes it so it doesn't put the text in the buffer (like Insert or defualt does) - -- Ex: typing "p" and then select "private" will not write "private" in your buffer, but keep it "p" - -- Only after accepting the suggestion then it'll become "private" [''] = cmp.mapping.select_next_item({ behavior = cmp.SelectBehavior.Select }), [''] = cmp.mapping.select_prev_item({ behavior = cmp.SelectBehavior.Select }), }), + ---@diagnostic disable-next-line: missing-fields + formatting = { + fields = { 'kind', 'abbr', 'menu' }, + format = function(entry, vim_item) + local kind = lspkind.cmp_format({ mode = 'symbol_text', maxwidth = 50 })(entry, vim_item) + local strings = vim.split(kind.kind, '%s', { trimempty = true }) + kind.kind = ' ' .. (strings[1] or '') .. ' ' -- left (icon) + kind.menu = ' ' .. (strings[2] or '') .. '' -- right (text) + return kind + end, + }, }) -- cgit v1.3.1