summaryrefslogtreecommitdiff
path: root/nvim/.config
diff options
context:
space:
mode:
authorBobby Bingham <koorogi@koorogi.info>2022-07-02 20:38:57 -0500
committerBobby Bingham <koorogi@koorogi.info>2022-07-09 17:55:30 -0500
commit2e37e28cb0c7e9f4479229380d8202e7192c5f99 (patch)
tree994246fc6f5eca0242bb054674f0be2fac3fc8a9 /nvim/.config
parent53df8a59580f1f866ea377e75fe14880d8db8fbb (diff)
nvim: add autocomplete
Diffstat (limited to 'nvim/.config')
-rw-r--r--nvim/.config/nvim/lua/cmp_config.lua51
-rw-r--r--nvim/.config/nvim/lua/lsp_config.lua5
-rw-r--r--nvim/.config/nvim/lua/plugins.lua13
3 files changed, 69 insertions, 0 deletions
diff --git a/nvim/.config/nvim/lua/cmp_config.lua b/nvim/.config/nvim/lua/cmp_config.lua
new file mode 100644
index 0000000..fa1610f
--- /dev/null
+++ b/nvim/.config/nvim/lua/cmp_config.lua
@@ -0,0 +1,51 @@
+local cmp = require('cmp')
+
+cmp.setup({
+ snippet = {
+ -- REQUIRED - you must specify a snippet engine
+ expand = function(args)
+ vim.fn["vsnip#anonymous"](args.body) -- For `vsnip` users.
+ -- require('luasnip').lsp_expand(args.body) -- For `luasnip` users.
+ -- require('snippy').expand_snippet(args.body) -- For `snippy` users.
+ -- vim.fn["UltiSnips#Anon"](args.body) -- For `ultisnips` users.
+ end,
+ },
+ window = {
+ -- completion = cmp.config.window.bordered(),
+ -- documentation = cmp.config.window.bordered(),
+ },
+ mapping = cmp.mapping.preset.insert({
+ ['<C-b>'] = cmp.mapping.scroll_docs(-4),
+ ['<C-f>'] = cmp.mapping.scroll_docs(4),
+ ['<C-Space>'] = cmp.mapping.complete(),
+ ['<C-e>'] = cmp.mapping.abort(),
+ ['<CR>'] = cmp.mapping.confirm({ select = true }), -- Accept currently selected item. Set `select` to `false` to only confirm explicitly selected items.
+ }),
+ sources = cmp.config.sources({
+ { name = 'nvim_lsp' },
+ { name = 'vsnip' }, -- For vsnip users.
+ -- { name = 'luasnip' }, -- For luasnip users.
+ -- { name = 'ultisnips' }, -- For ultisnips users.
+ -- { name = 'snippy' }, -- For snippy users.
+ { name = 'path' },
+ })
+})
+
+-- Use buffer source for `/` (if you enabled `native_menu`, this won't work anymore).
+cmp.setup.cmdline('/', {
+ mapping = cmp.mapping.preset.cmdline(),
+ sources = {
+ { name = 'buffer' }
+ }
+})
+
+-- Use cmdline & path source for ':' (if you enabled `native_menu`, this won't work anymore).
+cmp.setup.cmdline(':', {
+ mapping = cmp.mapping.preset.cmdline(),
+ sources = cmp.config.sources({
+ { name = 'path' }
+ }, {
+ { name = 'cmdline' }
+ })
+})
+
diff --git a/nvim/.config/nvim/lua/lsp_config.lua b/nvim/.config/nvim/lua/lsp_config.lua
index 4bb64bf..55f4d6d 100644
--- a/nvim/.config/nvim/lua/lsp_config.lua
+++ b/nvim/.config/nvim/lua/lsp_config.lua
@@ -50,12 +50,17 @@ local on_attach = function(client, bufnr)
end
end
+-- The nvim-cmp almost supports LSP's capabilities so You should advertise it to LSP servers..
+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 = { 'tsserver', 'zls' }
for _, lsp in pairs(servers) do
lspconfig[lsp].setup({
on_attach = on_attach,
+ capabilities = capabilities,
flags = {
-- This will be the default in neovim 0.7+
debounce_text_changes = 150,
diff --git a/nvim/.config/nvim/lua/plugins.lua b/nvim/.config/nvim/lua/plugins.lua
index ae53f90..18d0fd0 100644
--- a/nvim/.config/nvim/lua/plugins.lua
+++ b/nvim/.config/nvim/lua/plugins.lua
@@ -39,11 +39,24 @@ return require('packer').startup(function()
requires = {
"jose-elias-alvarez/null-ls.nvim",
"jose-elias-alvarez/nvim-lsp-ts-utils",
+ "hrsh7th/cmp-nvim-lsp'",
},
config = function() require('lsp_config') end
}
use {
+ 'hrsh7th/nvim-cmp',
+ requires = {
+ 'hrsh7th/cmp-nvim-lsp',
+ 'hrsh7th/cmp-buffer',
+ 'hrsh7th/cmp-path',
+ 'hrsh7th/cmp-cmdline',
+ 'hrsh7th/vim-vsnip',
+ },
+ config = function() require('cmp_config') end
+ }
+
+ use {
'nvim-neo-tree/neo-tree.nvim',
requires = {
'nvim-lua/plenary.nvim',