diff options
Diffstat (limited to 'common/config/nvim/lua/plugins/cmp.lua')
| -rwxr-xr-x | common/config/nvim/lua/plugins/cmp.lua | 67 |
1 files changed, 67 insertions, 0 deletions
diff --git a/common/config/nvim/lua/plugins/cmp.lua b/common/config/nvim/lua/plugins/cmp.lua new file mode 100755 index 0000000..7de04ad --- /dev/null +++ b/common/config/nvim/lua/plugins/cmp.lua @@ -0,0 +1,67 @@ +local M = {} + +--- Setup and configure nvim-cmp +-- This function initializes and configures the completion plugin +-- @return boolean True if setup was successful, false otherwise +function M.setup() + -- Check Neovim version + local nvim_version = vim.version() + if nvim_version.major == 0 and nvim_version.minor < 5 then + return false + end + + -- Try to load required modules + local cmp = pcall(require, 'cmp') and require('cmp') + if not cmp then + return false + end + + local luasnip_ok, luasnip = pcall(require, 'luasnip') + if not luasnip_ok then + vim.notify("luasnip not found, some features may be limited", vim.log.levels.WARN) + end + + -- Setup nvim-cmp + cmp.setup({ + snippet = { + expand = function(args) + if luasnip_ok then luasnip.lsp_expand(args.body) end + end, + }, + mapping = cmp.mapping.preset.insert({ + ['<C-Space>'] = cmp.mapping.complete(), + ['<CR>'] = cmp.mapping.confirm({ select = true }), + ['<Tab>'] = cmp.mapping.select_next_item(), + ['<S-Tab>'] = cmp.mapping.select_prev_item(), + }), + sources = cmp.config.sources({ + { name = 'nvim_lsp' }, + { name = 'luasnip' }, + { name = 'buffer' }, + }), +}) + +vim.cmd([[ + highlight! link CmpItemMenu Comment + " gray + highlight! CmpItemAbbrDeprecated guibg=NONE gui=strikethrough guifg=#808080 + " blue + highlight! CmpItemAbbrMatch guibg=NONE guifg=#569CD6 + highlight! CmpItemAbbrMatchFuzzy guibg=NONE guifg=#569CD6 + " light blue + highlight! CmpItemKindVariable guibg=NONE guifg=#9CDCFE + highlight! CmpItemKindInterface guibg=NONE guifg=#9CDCFE + highlight! CmpItemKindText guibg=NONE guifg=#9CDCFE + " pink + highlight! CmpItemKindFunction guibg=NONE guifg=#C586C0 + highlight! CmpItemKindMethod guibg=NONE guifg=#C586C0 + " front + highlight! CmpItemKindKeyword guibg=NONE guifg=#D4D4D4 + highlight! CmpItemKindProperty guibg=NONE guifg=#D4D4D4 + highlight! CmpItemKindUnit guibg=NONE guifg=#D4D4D4 + ]]) + + return true +end + +return M |
