nvim: got friendly snippets working

This commit is contained in:
Daniel Lundin 2022-01-09 22:29:09 +01:00
parent e7f78f287a
commit 6943f77d30

View file

@ -5,7 +5,7 @@ return require('packer').startup(function()
use 'wbthomason/packer.nvim' use 'wbthomason/packer.nvim'
use 'ray-x/lsp_signature.nvim' use 'ray-x/lsp_signature.nvim'
use 'jose-elias-alvarez/nvim-lsp-ts-utils' use 'jose-elias-alvarez/nvim-lsp-ts-utils'
use 'L3MON4D3/LuaSnip' use 'rafamadriz/friendly-snippets'
use { use {
'b3nj5m1n/kommentary', 'b3nj5m1n/kommentary',
@ -20,6 +20,13 @@ return require('packer').startup(function()
end end
} }
use {
'L3MON4D3/LuaSnip',
config = function()
require("luasnip/loaders/from_vscode").lazy_load()
end
}
use { use {
'hrsh7th/nvim-cmp', 'hrsh7th/nvim-cmp',
requires = { requires = {
@ -28,11 +35,17 @@ return require('packer').startup(function()
'hrsh7th/cmp-buffer', 'hrsh7th/cmp-buffer',
'hrsh7th/cmp-path', 'hrsh7th/cmp-path',
'hrsh7th/cmp-cmdline', 'hrsh7th/cmp-cmdline',
'L3MON4D3/LuaSnip',
'saadparwaiz1/cmp_luasnip', 'saadparwaiz1/cmp_luasnip',
}, },
config = function() config = function()
local cmp = require'cmp' local cmp = require'cmp'
-- local cmp = require('hrsh7th/nvim-cmp') local luasnip = require'luasnip'
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
cmp.setup({ cmp.setup({
@ -50,25 +63,34 @@ return require('packer').startup(function()
}), }),
}, },
documentation = {
border = 'rounded'
},
snippet = { snippet = {
expand = function(args) expand = function(args)
require('luasnip').lsp_expand(args.body) luasnip.lsp_expand(args.body)
end, end,
}, },
mapping = { mapping = {
['<C-p>'] = cmp.mapping(cmp.mapping.select_prev_item(), { 'i', 'c' }),
['<C-n>'] = cmp.mapping(cmp.mapping.select_next_item(), { 'i', 'c' }),
["<C-d>"] = cmp.mapping.scroll_docs(-4), ["<C-d>"] = cmp.mapping.scroll_docs(-4),
["<C-u>"] = cmp.mapping.scroll_docs(4), ["<C-u>"] = cmp.mapping.scroll_docs(4),
["<C-e>"] = cmp.mapping.close(), ['<C-e>'] = cmp.mapping({
["<CR>"] = cmp.mapping.confirm({ i = cmp.mapping.abort(),
select = false, c = cmp.mapping.close(),
}), }),
['<CR>'] = cmp.mapping(cmp.mapping.confirm({ select = false }), { 'i', 'c' }),
['<C-y>'] = cmp.mapping(cmp.mapping.confirm({ select = false }), { 'i', 'c' }),
['<C-Space>'] = cmp.mapping(cmp.mapping.complete(), { 'i', 'c' }), ['<C-Space>'] = cmp.mapping(cmp.mapping.complete(), { 'i', 'c' }),
["<Tab>"] = cmp.mapping(function(fallback) ["<Tab>"] = cmp.mapping(function(fallback)
if cmp.visible() then if cmp.visible() then
cmp.select_next_item() cmp.select_next_item()
elseif luasnip.expand_or_jumpable() then elseif luasnip.expand_or_locally_jumpable() then
luasnip.expand_or_jump() luasnip.expand_or_jump()
elseif has_words_before() then elseif has_words_before() then
cmp.complete() cmp.complete()
@ -93,7 +115,10 @@ return require('packer').startup(function()
priority = 1, priority = 1,
}, },
{ name = 'luasnip' }, {
name = 'luasnip',
priority = 4,
},
{ {
name = 'tmux', name = 'tmux',
priority = 2, priority = 2,