feat: Added luasnip completions
chore: Moved completion configuration to its own file
This commit is contained in:
parent
521c3c332d
commit
702183612a
|
|
@ -0,0 +1,72 @@
|
|||
local cmp = require("cmp")
|
||||
|
||||
cmp.setup({
|
||||
snippet = {
|
||||
-- REQUIRED - you must specify a snippet engine
|
||||
expand = function(args)
|
||||
require('luasnip').lsp_expand(args.body) -- For `luasnip` users.
|
||||
--vim.snippet.expand(args.body) -- For native neovim snippets (Neovim v0.10+)
|
||||
end,
|
||||
},
|
||||
window = {
|
||||
-- completion = cmp.config.window.bordered(),
|
||||
-- documentation = cmp.config.window.bordered(),
|
||||
},
|
||||
mapping = cmp.mapping.preset.insert({
|
||||
['<C-p>'] = cmp.mapping.select_prev_item(cmp_select),
|
||||
['<C-n>'] = cmp.mapping.select_next_item(cmp_select),
|
||||
['<C-y>'] = cmp.mapping.confirm({ select = true }),
|
||||
['<C-Space>'] = cmp.mapping.complete(),
|
||||
}),
|
||||
sources = cmp.config.sources({
|
||||
{ name = 'nvim_lsp' },
|
||||
{ name = 'luasnip' }, -- For luasnip users.
|
||||
{ name = 'buffer' },
|
||||
{
|
||||
name = 'path',
|
||||
option = {
|
||||
pathMappings = {
|
||||
['@'] = '${folder}/src',
|
||||
-- ['/'] = '${folder}/src/public/',
|
||||
-- ['~@'] = '${folder}/src',
|
||||
-- ['/images'] = '${folder}/src/images',
|
||||
-- ['/components'] = '${folder}/src/components',
|
||||
},
|
||||
},
|
||||
},
|
||||
}),
|
||||
completion = {
|
||||
completeopt = 'menu,menuone,noinsert',
|
||||
},
|
||||
})
|
||||
|
||||
-- Use buffer source for `/` and `?` (if you enabled `native_menu`, this won't work anymore).
|
||||
cmp.setup.cmdline({ '/', '?' }, {
|
||||
mapping = cmp.mapping.preset.cmdline(),
|
||||
sources = {
|
||||
{ name = 'buffer' }
|
||||
}
|
||||
})
|
||||
|
||||
cmp.setup.cmdline(':', {
|
||||
mapping = cmp.mapping.preset.cmdline(),
|
||||
sources = cmp.config.sources(
|
||||
{
|
||||
{ name = 'path' }
|
||||
},
|
||||
{
|
||||
{
|
||||
name = 'cmdline',
|
||||
option = {
|
||||
ignore_cmds = { 'Man', '!' }
|
||||
}
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
-- Set up lspconfig.
|
||||
local capabilities = require('cmp_nvim_lsp').default_capabilities()
|
||||
-- Replace <YOUR_LSP_SERVER> with each lsp server you've enabled.
|
||||
--require('lspconfig')['<YOUR_LSP_SERVER>'].setup {
|
||||
-- capabilities = capabilities
|
||||
--}
|
||||
|
|
@ -1,34 +1,5 @@
|
|||
require("mason").setup()
|
||||
|
||||
local cmp = require('cmp')
|
||||
local cmp_select = {behavior = cmp.SelectBehavior.Select}
|
||||
cmp.setup({
|
||||
snippet = {
|
||||
expand = function(args)
|
||||
require('luasnip').lsp_expand(args.body)
|
||||
end,
|
||||
},
|
||||
mapping = cmp.mapping.preset.insert({
|
||||
['<C-p>'] = cmp.mapping.select_prev_item(cmp_select),
|
||||
['<C-n>'] = cmp.mapping.select_next_item(cmp_select),
|
||||
['<C-y>'] = cmp.mapping.confirm({ select = true }),
|
||||
['<C-Space>'] = cmp.mapping.complete(),
|
||||
}),
|
||||
sources = cmp.config.sources(
|
||||
{
|
||||
{ name = 'nvim_lsp' },
|
||||
{ name = 'luasnip' }
|
||||
},
|
||||
{
|
||||
{ name = 'buffer' },
|
||||
{ name = 'path' },
|
||||
{ name = 'cmdline' }
|
||||
}),
|
||||
completion = {
|
||||
completeopt = 'menu,menuone,noinsert',
|
||||
},
|
||||
})
|
||||
|
||||
vim.lsp.enable("lua_ls")
|
||||
vim.lsp.config("lua_ls", {
|
||||
on_init = function(client)
|
||||
|
|
|
|||
|
|
@ -37,6 +37,12 @@ require("lazy").setup({
|
|||
{ -- LSP Configuration tool
|
||||
'neovim/nvim-lspconfig'
|
||||
},
|
||||
{ -- Snippet engine?
|
||||
"L3MON4D3/LuaSnip",
|
||||
version = "v2.4", -- Replace <CurrentMajor> by the latest released major (first number of latest release)
|
||||
-- install jsregexp (optional!).
|
||||
build = "make install_jsregexp"
|
||||
},
|
||||
{ -- Code completion
|
||||
'hrsh7th/nvim-cmp'
|
||||
},
|
||||
|
|
|
|||
Loading…
Reference in New Issue