summaryrefslogtreecommitdiff
path: root/.config/nvim/lua/user/plugins/cmp.lua
diff options
context:
space:
mode:
Diffstat (limited to '.config/nvim/lua/user/plugins/cmp.lua')
-rw-r--r--.config/nvim/lua/user/plugins/cmp.lua19
1 files changed, 15 insertions, 4 deletions
diff --git a/.config/nvim/lua/user/plugins/cmp.lua b/.config/nvim/lua/user/plugins/cmp.lua
index 4bfe38e..81cd2ee 100644
--- a/.config/nvim/lua/user/plugins/cmp.lua
+++ b/.config/nvim/lua/user/plugins/cmp.lua
@@ -3,13 +3,14 @@ local has_words_before = function()
return col ~= 0 and vim.api.nvim_buf_get_lines(0, line - 1, line, true)[1]:sub(col, col):match '%s' == nil
end
+local luasnip = require 'luasnip'
local cmp = require 'cmp'
local lspkind = require 'lspkind'
-- Set completeopt to have a better completion experience
vim.o.completeopt = 'menuone,longest,preview'
-cmp.setup {
+cmp.setup({
experimental = {
ghost_text = true,
},
@@ -23,6 +24,11 @@ cmp.setup {
},
},
},
+ snippet = {
+ expand = function(args)
+ require('luasnip').lsp_expand(args.body)
+ end,
+ },
mapping = {
['<C-p>'] = cmp.mapping.select_prev_item(),
['<C-n>'] = cmp.mapping.select_next_item(),
@@ -35,7 +41,9 @@ cmp.setup {
select = false,
},
['<Tab>'] = cmp.mapping(function(fallback)
- if cmp.visible() then
+ if luasnip.expand_or_jumpable() then
+ luasnip.expand_or_jump()
+ elseif cmp.visible() then
cmp.select_next_item()
elseif has_words_before() then
cmp.complete()
@@ -44,7 +52,9 @@ cmp.setup {
end
end, { 'i', 's' }),
['<S-Tab>'] = cmp.mapping(function(fallback)
- if cmp.visible() then
+ if luasnip.jumpable(-1) then
+ luasnip.jump(-1)
+ elseif cmp.visible() then
cmp.select_prev_item()
else
fallback()
@@ -56,7 +66,8 @@ cmp.setup {
{ name = 'nvim_lsp' },
{ name = 'nvim_lsp_signature_help' },
{ name = 'nvim_lua' },
+ { name = 'luasnip' },
{ name = 'path' },
{ name = 'buffer' },
},
-}
+})