diff options
Diffstat (limited to 'nvim/lua/plugins/cmp.lua')
| -rw-r--r-- | nvim/lua/plugins/cmp.lua | 104 |
1 files changed, 67 insertions, 37 deletions
diff --git a/nvim/lua/plugins/cmp.lua b/nvim/lua/plugins/cmp.lua index 923cb09..24c1c47 100644 --- a/nvim/lua/plugins/cmp.lua +++ b/nvim/lua/plugins/cmp.lua @@ -1,39 +1,69 @@ -local cmp = require'cmp' -cmp.setup{ - snippet = { - -- REQUIRED - you must specify a snippet engine - expand = function(args) - vim.fn["vsnip#anonymous"](args.body) -- For `vsnip` users. - -- require('luasnip').lsp_expand(args.body) -- For `luasnip` users. - -- require('snippy').expand_snippet(args.body) -- For `snippy` users. - -- vim.fn["UltiSnips#Anon"](args.body) -- For `ultisnips` users. - -- vim.snippet.expand(args.body) -- For native neovim snippets (Neovim v0.10+) - - -- For `mini.snippets` users: - -- local insert = MiniSnippets.config.expand.insert or MiniSnippets.default_insert - -- insert({ body = args.body }) -- Insert at cursor - -- cmp.resubscribe({ "TextChangedI", "TextChangedP" }) - -- require("cmp.config").set_onetime({ sources = {} }) - end, +return { + "hrsh7th/nvim-cmp", + dependencies = { + "hrsh7th/cmp-nvim-lsp", + "hrsh7th/cmp-buffer", + "hrsh7th/cmp-path", + "saadparwaiz1/cmp_luasnip", + { + "L3MON4D3/LuaSnip", + lazy = true, + version = "v2.*", + build = "make install_jsregexp", + opts = { + history = true, + delete_check_events = "TextChanged", + }, + dependencies = { "rafamadriz/friendly-snippets" }, + config = function() + require("plugins.snippets") + end, + }, }, - window = { - completion = cmp.config.window.bordered(), - documentation = cmp.config.window.bordered(), - }, - mapping = cmp.mapping.preset.insert({ - ['<C-b>'] = cmp.mapping.scroll_docs(-4), - ['<C-f>'] = cmp.mapping.scroll_docs(4), - ['<C-Space>'] = cmp.mapping.complete(), - ['<C-e>'] = cmp.mapping.abort(), - ['<CR>'] = cmp.mapping.confirm({ select = true }), -- Accept currently selected item. Set `select` to `false` to only confirm explicitly selected items. - }), - sources = cmp.config.sources({ - { name = 'nvim_lsp' }, - { name = 'vsnip' }, -- For vsnip users. - -- { name = 'luasnip' }, -- For luasnip users. - -- { name = 'ultisnips' }, -- For ultisnips users. - -- { name = 'snippy' }, -- For snippy users. - }, { - { name = 'buffer' }, - }) + config = function() + local cmp = require("cmp") + local source_mapping = { + buffer = "[Buffer]", + nvim_lsp = "[LSP]", + nvim_lua = "[Lua]", + path = "[Path]", + } + cmp.setup({ + mapping = cmp.mapping.preset.insert({ + ["<CR>"] = cmp.mapping.confirm({ select = true }), + ["<Tab>"] = cmp.mapping(function(fallback) + if require("luasnip").expand_or_jumpable() then + require("luasnip").expand_or_jump() + else + fallback() + end + end, { "i", "s" }), + ["<S-Tab>"] = cmp.mapping(function(fallback) + if require("luasnip").jumpable(-1) then + require("luasnip").jump(-1) + else + fallback() + end + end, { "i", "s" }), + }), + snippet = { + expand = function(args) + require("luasnip").lsp_expand(args.body) + end, + }, + formatting = { + format = function(entry, vim_item) + vim_item.menu = source_mapping[entry.source.name] or "[Unknown]" + return vim_item + end, + }, + sources = cmp.config.sources({ + { name = "nvim_lsp", priority = 1000 }, + { name = "luasnip", priority = 750 }, + { name = "path", priority = 500 }, + }, { + { name = "buffer" }, + }), + }) + end, } |
