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 ++++++++++++++++++-------- .config/nvim/lua/custom/lsp.lua | 3 --- .config/nvim/lua/custom/plugins/completion.lua | 5 ++--- .config/nvim/lua/custom/plugins/lsp.lua | 5 +---- 4 files changed, 24 insertions(+), 19 deletions(-) (limited to '.config/nvim/lua/custom') 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, + }, }) diff --git a/.config/nvim/lua/custom/lsp.lua b/.config/nvim/lua/custom/lsp.lua index 929014d..2acbed1 100644 --- a/.config/nvim/lua/custom/lsp.lua +++ b/.config/nvim/lua/custom/lsp.lua @@ -56,9 +56,6 @@ vim.api.nvim_create_autocmd('LspAttach', { local bufnr = args.buf local client = assert(vim.lsp.get_client_by_id(args.data.client_id), 'must have valid client') - -- TODO: Check if I need this line - -- vim.opt_local.omnifunc = "v:lua.vim.lsp.omnifunc" - local settings = servers[client.name] if type(settings) ~= 'table' then ---@diagnostic disable-next-line: cast-local-type diff --git a/.config/nvim/lua/custom/plugins/completion.lua b/.config/nvim/lua/custom/plugins/completion.lua index 5e0f2ef..a1835ad 100644 --- a/.config/nvim/lua/custom/plugins/completion.lua +++ b/.config/nvim/lua/custom/plugins/completion.lua @@ -3,9 +3,8 @@ return { lazy = false, priority = 100, dependencies = { - -- 'onsails/lspkind.nvim', - -- 'hrsh7th/cmp-path', - -- 'hrsh7th/cmp-buffer', + 'onsails/lspkind.nvim', -- icons for completion type + 'hrsh7th/cmp-path', -- complete filepaths 'hrsh7th/cmp-nvim-lsp', -- lsp source for nvim-cmp 'saadparwaiz1/cmp_luasnip', -- snippets source for nvim-cmp { 'L3MON4D3/LuaSnip', build = 'make install_jsregexp' }, -- snippets plugin diff --git a/.config/nvim/lua/custom/plugins/lsp.lua b/.config/nvim/lua/custom/plugins/lsp.lua index e555ace..8972299 100644 --- a/.config/nvim/lua/custom/plugins/lsp.lua +++ b/.config/nvim/lua/custom/plugins/lsp.lua @@ -12,10 +12,7 @@ return { opts = { library = { { path = 'luvit-meta/library', words = { 'vim%.uv' } } } }, }, - -- FIXME: Starts with a black blackground - -- Desired behaviour is same color as background or transparent - -- Progress ui - { 'j-hui/fidget.nvim', opts = {} }, + { 'j-hui/fidget.nvim', opts = { notification = { window = { winblend = 0 } } } }, -- AUtoformatting -- 'stevear/conform.nvim', -- cgit v1.3.1