aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCody Hiar <cody@hiar.ca>2021-11-16 21:31:30 -0700
committerCody Hiar <cody@hiar.ca>2021-11-16 21:31:30 -0700
commit14ced6b533d2ba9fef79711400eeffdb8983ff17 (patch)
tree60781c5dabf72ffcedeb05cab70a2f9b05eaccab
parentbefa7238acd46e49c9fe16025eaecbba98c20b84 (diff)
lsp tab completion
-rw-r--r--init.lua52
1 files changed, 44 insertions, 8 deletions
diff --git a/init.lua b/init.lua
index a3bb5ed..e7ee22f 100644
--- a/init.lua
+++ b/init.lua
@@ -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 {