Add snippet engine for cmp

This commit is contained in:
Daniel Flanagan 2022-03-16 00:53:49 -05:00
parent d357b591c9
commit 3a13cbc38d
Signed by: lytedev
GPG key ID: 5B2020A0F9921EF4

View file

@ -4,6 +4,11 @@ if #vim.fn.glob(packer_install_path) == 0 then
vim.api.nvim_command'packadd packer.nvim' vim.api.nvim_command'packadd packer.nvim'
end end
local has_words_before = function()
local line, col = unpack(vim.api.nvim_win_get_cursor(0))
return col ~= 0 and vim.api.nvim_buf_get_lines(0, line - 1, line, true)[1]:sub(col, col):match("%s") == nil
end
local packer = require'packer' local packer = require'packer'
packer.startup(function() packer.startup(function()
local plugins = { local plugins = {
@ -45,21 +50,38 @@ packer.startup(function()
'nvim-lua/plenary.nvim', 'nvim-lua/plenary.nvim',
} }
}, },
{
'nvim-telescope/telescope-fzf-native.nvim',
run = 'make',
},
{
'tzachar/cmp-fuzzy-path',
requires = {'hrsh7th/nvim-cmp', 'tzachar/fuzzy.nvim'},
},
-- TODO: add keymap <leader>ig for toggling these -- TODO: add keymap <leader>ig for toggling these
'lukas-reineke/indent-blankline.nvim', -- indentation guide lines 'lukas-reineke/indent-blankline.nvim', -- indentation guide lines
'L3MON4D3/LuaSnip',
'neovim/nvim-lspconfig', -- language server configuration helper 'neovim/nvim-lspconfig', -- language server configuration helper
'williamboman/nvim-lsp-installer', -- plugin containing installation commands for many language servers 'williamboman/nvim-lsp-installer', -- plugin containing installation commands for many language servers
'hrsh7th/cmp-nvim-lsp', -- add lsp to completion engine 'hrsh7th/cmp-nvim-lsp', -- add lsp to completion engine
'hrsh7th/cmp-buffer', -- add buffer information to completion engine 'hrsh7th/cmp-buffer', -- add buffer information to completion engine
'hrsh7th/cmp-path', -- add filesystem information to complete enging 'hrsh7th/cmp-path', -- add filesystem information to complete enging
'hrsh7th/cmp-cmdline', -- add completion for vim commands 'hrsh7th/cmp-cmdline', -- add completion for vim commands
'saadparwaiz1/cmp_luasnip',
{ {
-- completion engine -- completion engine
'hrsh7th/nvim-cmp', 'hrsh7th/nvim-cmp',
config = function() config = function()
local cmp = require'cmp' local cmp = require'cmp'
local luasnip = require'luasnip'
cmp.setup{ cmp.setup{
snippet = {
expand = function(args)
luasnip.lsp_expand(args.body)
end,
},
mapping = { mapping = {
['<C-b>'] = cmp.mapping(cmp.mapping.scroll_docs(-4), { 'i', 'c' }), ['<C-b>'] = cmp.mapping(cmp.mapping.scroll_docs(-4), { 'i', 'c' }),
['<C-f>'] = cmp.mapping(cmp.mapping.scroll_docs(4), { 'i', 'c' }), ['<C-f>'] = cmp.mapping(cmp.mapping.scroll_docs(4), { 'i', 'c' }),
@ -70,16 +92,41 @@ packer.startup(function()
c = cmp.mapping.close(), c = cmp.mapping.close(),
}, },
['<CR>'] = cmp.mapping.confirm{select = true}, -- Accept currently selected item. Set `select` to `false` to only confirm explicitly selected items. ['<CR>'] = cmp.mapping.confirm{select = true}, -- Accept currently selected item. Set `select` to `false` to only confirm explicitly selected items.
["<Tab>"] = cmp.mapping(function(fallback)
if cmp.visible() then
cmp.select_next_item()
elseif luasnip.expand_or_jumpable() then
luasnip.expand_or_jump()
elseif has_words_before() then
cmp.complete()
else
fallback()
end
end, { "i", "s" }),
["<S-Tab>"] = cmp.mapping(function(fallback)
if cmp.visible() then
cmp.select_prev_item()
elseif luasnip.jumpable(-1) then
luasnip.jump(-1)
else
fallback()
end
end, { "i", "s" }),
}, },
sources = cmp.config.sources{ sources = cmp.config.sources({
{ name = 'nvim_lsp' }, { name = 'nvim_lsp' },
{ name = 'luasnip' },
}, {
{ name = 'buffer' }, { name = 'buffer' },
}, { name = 'path' },
{ name = 'fuzzy_path' },
}),
} }
cmp.setup.cmdline('/', { cmp.setup.cmdline('/', {
sources = { sources = {
{name = 'buffer'}, {name = 'buffer'},
{name = 'fuzzy_path'},
} }
}) })