diff options
author | Cody Hiar <cody@hiar.ca> | 2021-11-16 21:31:30 -0700 |
---|---|---|
committer | Cody Hiar <cody@hiar.ca> | 2021-11-16 21:31:30 -0700 |
commit | 14ced6b533d2ba9fef79711400eeffdb8983ff17 (patch) | |
tree | 60781c5dabf72ffcedeb05cab70a2f9b05eaccab | |
parent | befa7238acd46e49c9fe16025eaecbba98c20b84 (diff) |
lsp tab completion
-rw-r--r-- | init.lua | 52 |
1 files changed, 44 insertions, 8 deletions
@@ -194,6 +194,10 @@ return require('packer').startup(function() } use { "neovim/nvim-lspconfig", + requires = { + {'hrsh7th/nvim-cmp'}, + {'hrsh7th/cmp-nvim-lsp'}, + }, config = function() nvim_lsp = require('lspconfig') -- Use an on_attach function to only map the following keys @@ -223,21 +227,60 @@ return require('packer').startup(function() buf_set_keymap('n', ']d', '<cmd>lua vim.lsp.diagnostic.goto_next()<CR>', opts) buf_set_keymap('n', '<space>q', '<cmd>lua vim.lsp.diagnostic.set_loclist()<CR>', opts) buf_set_keymap('n', '<space>f', '<cmd>lua vim.lsp.buf.formatting()<CR>', opts) - end -- Use a loop to conveniently call 'setup' on multiple servers and -- map buffer local keybindings when the language server attaches -- local servers = { 'pyls', 'rust_analyzer', 'tsserver' } local servers = { 'pyright', 'bashls' } + -- Add additional capabilities supported by nvim-cmp + local capabilities = vim.lsp.protocol.make_client_capabilities() + capabilities = require('cmp_nvim_lsp').update_capabilities(capabilities) + -- Setup language servers for _, lsp in ipairs(servers) do nvim_lsp[lsp].setup { on_attach = on_attach, flags = { debounce_text_changes = 150, }, + capabilities = capabilities, } end + -- Set completeopt to have a better completion experience + vim.o.completeopt = 'menuone,noselect' + -- nvim-cmp setup + local cmp = require 'cmp' + cmp.setup { + mapping = { + ['<C-p>'] = cmp.mapping.select_prev_item(), + ['<C-n>'] = cmp.mapping.select_next_item(), + ['<C-d>'] = cmp.mapping.scroll_docs(-4), + ['<C-f>'] = cmp.mapping.scroll_docs(4), + ['<C-Space>'] = cmp.mapping.complete(), + ['<C-e>'] = cmp.mapping.close(), + ['<CR>'] = cmp.mapping.confirm { + behavior = cmp.ConfirmBehavior.Replace, + select = true, + }, + ['<Tab>'] = function(fallback) + if cmp.visible() then + cmp.select_next_item() + else + fallback() + end + end, + ['<S-Tab>'] = function(fallback) + if cmp.visible() then + cmp.select_prev_item() + else + fallback() + end + end, + }, + sources = { + { name = 'nvim_lsp' }, + }, + } end, } use 'nvim-treesitter/playground' @@ -377,13 +420,6 @@ return require('packer').startup(function() require'hop'.setup { keys = 'etovxqpdygfblzhckisuran' } end } - use { - 'ervandew/supertab', - config = function() - -- Default to scrolling down the list - vim.g.SuperTabDefaultCompletionType = "<c-n>" - end - } -- The treesitter for nix doesn't do indents use 'LnL7/vim-nix' use { |