diff --git a/.config/nvim/lua/lspconfig/settings.lua b/.config/nvim/lua/lspconfig/settings.lua index 81ea519..6b81f93 100644 --- a/.config/nvim/lua/lspconfig/settings.lua +++ b/.config/nvim/lua/lspconfig/settings.lua @@ -1,3 +1,5 @@ +local servers = { 'pyright', 'sumneko_lua', 'eslint', 'tsserver' } + -- Mappings. -- See `:help vim.diagnostic.*` for documentation on any of the below functions local opts = { noremap=true, silent=true } @@ -32,15 +34,62 @@ local on_attach = function(client, bufnr) vim.keymap.set('n', 'f', vim.lsp.buf.formatting, bufopts) 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 -- map buffer local keybindings when the language server attaches -local servers = { 'pyright', 'sumneko_lua' } for _, lsp in pairs(servers) do require('lspconfig')[lsp].setup { on_attach = on_attach, + capabilities = capabilities, flags = { -- This will be the default in neovim 0.7+ debounce_text_changes = 150, } } 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({ + [''] = cmp.mapping.scroll_docs(-4), + [''] = cmp.mapping.scroll_docs(4), + [''] = cmp.mapping.complete(), + [''] = cmp.mapping.confirm { + behavior = cmp.ConfirmBehavior.Replace, + select = true, + }, + [''] = 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' }), + [''] = 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' }, + }, +} diff --git a/.config/nvim/lua/plugins.lua b/.config/nvim/lua/plugins.lua index f87a6f3..b07d87a 100644 --- a/.config/nvim/lua/plugins.lua +++ b/.config/nvim/lua/plugins.lua @@ -46,4 +46,11 @@ return require('packer').startup(function() use { 'sindrets/diffview.nvim', requires = 'nvim-lua/plenary.nvim' } + use { + 'hrsh7th/nvim-cmp', + 'hrsh7th/cmp-nvim-lsp', + 'saadparwaiz1/cmp_luasnip', + 'L3MON4D3/LuaSnip' + } + end)