[NeoVim] Install nvim-cmp
This commit is contained in:
@@ -1,3 +1,5 @@
|
|||||||
|
local servers = { 'pyright', 'sumneko_lua', 'eslint', 'tsserver' }
|
||||||
|
|
||||||
-- Mappings.
|
-- Mappings.
|
||||||
-- See `:help vim.diagnostic.*` for documentation on any of the below functions
|
-- See `:help vim.diagnostic.*` for documentation on any of the below functions
|
||||||
local opts = { noremap=true, silent=true }
|
local opts = { noremap=true, silent=true }
|
||||||
@@ -32,15 +34,62 @@ local on_attach = function(client, bufnr)
|
|||||||
vim.keymap.set('n', '<space>f', vim.lsp.buf.formatting, bufopts)
|
vim.keymap.set('n', '<space>f', vim.lsp.buf.formatting, bufopts)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local capabilities = vim.lsp.protocol.make_client_capabilities()
|
||||||
|
capabilities = require('cmp_nvim_lsp').update_capabilities(capabilities)
|
||||||
|
|
||||||
-- Use a loop to conveniently call 'setup' on multiple servers and
|
-- Use a loop to conveniently call 'setup' on multiple servers and
|
||||||
-- map buffer local keybindings when the language server attaches
|
-- map buffer local keybindings when the language server attaches
|
||||||
local servers = { 'pyright', 'sumneko_lua' }
|
|
||||||
for _, lsp in pairs(servers) do
|
for _, lsp in pairs(servers) do
|
||||||
require('lspconfig')[lsp].setup {
|
require('lspconfig')[lsp].setup {
|
||||||
on_attach = on_attach,
|
on_attach = on_attach,
|
||||||
|
capabilities = capabilities,
|
||||||
flags = {
|
flags = {
|
||||||
-- This will be the default in neovim 0.7+
|
-- This will be the default in neovim 0.7+
|
||||||
debounce_text_changes = 150,
|
debounce_text_changes = 150,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- luasnip setup
|
||||||
|
local luasnip = require 'luasnip'
|
||||||
|
|
||||||
|
-- nvim-cmp setup
|
||||||
|
local cmp = require 'cmp'
|
||||||
|
cmp.setup {
|
||||||
|
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' }),
|
||||||
|
['<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' },
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|||||||
@@ -46,4 +46,11 @@ return require('packer').startup(function()
|
|||||||
|
|
||||||
use { 'sindrets/diffview.nvim', requires = 'nvim-lua/plenary.nvim' }
|
use { 'sindrets/diffview.nvim', requires = 'nvim-lua/plenary.nvim' }
|
||||||
|
|
||||||
|
use {
|
||||||
|
'hrsh7th/nvim-cmp',
|
||||||
|
'hrsh7th/cmp-nvim-lsp',
|
||||||
|
'saadparwaiz1/cmp_luasnip',
|
||||||
|
'L3MON4D3/LuaSnip'
|
||||||
|
}
|
||||||
|
|
||||||
end)
|
end)
|
||||||
|
|||||||
Reference in New Issue
Block a user