Fixed insertion of snippets

This commit is contained in:
Nikurasu 2023-02-19 13:10:56 +01:00
parent 58df3fd422
commit 99bf9b422b
No known key found for this signature in database

View file

@ -1,4 +1,5 @@
-- install packer if not already there
local is_bootstrap = false
local install_path = vim.fn.stdpath 'data' .. '/site/pack/packer/start/packer.nvim'
if vim.fn.empty(vim.fn.glob(install_path)) > 0 then
is_bootstrap = true
@ -13,7 +14,7 @@ require('packer').startup(function(use)
use 'nvim-treesitter/nvim-treesitter'
use {
'hrsh7th/nvim-cmp',
requires = { 'hrsh7th/cmp-nvim-lsp', 'hrsh7th/cmp-buffer', 'hrsh7th/cmp-cmdline', 'hrsh7th/cmp-path', 'hrsh7th/cmp-nvim-lua', 'onsails/lspkind.nvim' }
requires = { 'hrsh7th/cmp-nvim-lsp', 'hrsh7th/cmp-buffer', 'hrsh7th/cmp-cmdline', 'hrsh7th/cmp-path', 'hrsh7th/cmp-nvim-lua', 'onsails/lspkind.nvim', 'L3MON4D3/LuaSnip', 'saadparwaiz1/cmp_luasnip' }
}
if is_bootstrap then
require('packer').sync()
@ -46,6 +47,10 @@ local lsp_flags = {
}
local capabilities = vim.lsp.protocol.make_client_capabilities()
-- capabilities.textDocument.completion.completionItem.snippetSupport = true
capabilities = require('cmp_nvim_lsp').default_capabilities(capabilities)
-- lsp configs
require('lspconfig')['tsserver'].setup{
on_attach = on_attach,
@ -62,6 +67,12 @@ require('lspconfig')['gopls'].setup{
flags = lsp_flags
}
require('lspconfig')['emmet_ls'].setup{
on_attach = on_attach,
flags = lsp_flags,
capabilities = capabilities
}
-- TreeSitter Config
require('nvim-treesitter.configs').setup{
ensure_installed = {'go', 'vim', 'typescript', 'help', 'lua', 'javascript', 'python'},
@ -73,24 +84,48 @@ require('nvim-treesitter.configs').setup{
-- autocompletion
local cmp = require 'cmp'
local lspkind = require 'lspkind'
local luasnip = require 'luasnip'
luasnip.config.setup {}
cmp.setup {
sources = {
{ name = 'nvim_lsp' },
{ name = 'buffer' },
{ name = 'cmdline' },
{ name = 'path' },
{ name = 'nvim-lua' }
},
formatting = {
format = lspkind.cmp_format()
},
snippet = {
expand = function(args)
luasnip.lsp_expand(args.body)
end,
},
mapping = cmp.mapping.preset.insert {
['<C-d>'] = cmp.mapping.scroll_docs(-4),
['<C-f>'] = cmp.mapping.scroll_docs(4),
['<C-Space>'] = cmp.mapping.complete {},
['<CR>'] = cmp.mapping.confirm {
behavior = cmp.ConfirmBehavior.Replace,
select = true,
},
['<Tab>'] = cmp.mapping(function(fallback)
if cmp.visible() then
cmp.select_next_item()
elseif luasnip.expand_or_jumpable() then
luasnip.expand_or_jump()
else
fallback()
end
end, {'i', 's'})
}
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 = {
{ name = 'nvim_lsp' },
{ name = 'luasnip' },
},
}