aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoreug-vs <eugene@eug-vs.xyz>2021-10-22 12:04:55 +0300
committereug-vs <eugene@eug-vs.xyz>2021-10-22 12:05:23 +0300
commitbe7acfd660f449027f87ed1c2aaa8a60b2ec27aa (patch)
treef4ef44c5fcba8079b9b2468560aaea56dc38e316
parent164e584a7ff91842a4d4ac3f7641323102f3e786 (diff)
downloaddotfiles-be7acfd660f449027f87ed1c2aaa8a60b2ec27aa.tar.gz
feat(nvim): migrate to nvim-cmp
-rw-r--r--nvim/.config/nvim/init.vim2
-rw-r--r--nvim/.config/nvim/lua/completion.lua100
-rw-r--r--nvim/.config/nvim/lua/lsp-config.lua10
-rw-r--r--nvim/.config/nvim/lua/lsp-saga.lua11
-rw-r--r--nvim/.config/nvim/lua/plugins.lua16
5 files changed, 64 insertions, 75 deletions
diff --git a/nvim/.config/nvim/init.vim b/nvim/.config/nvim/init.vim
index ef19b42..1206cd5 100644
--- a/nvim/.config/nvim/init.vim
+++ b/nvim/.config/nvim/init.vim
@@ -41,6 +41,7 @@ set path=.,**
set wildmenu
set wildignore+=**/node_modules/**,**/build/**,**/dist/**,**/__pycache__/**
set wildmode=longest,list,full
+set completeopt=menu,menuone,noselect
" Easier window navigation
nnoremap <c-h> <C-w>h
@@ -73,7 +74,6 @@ source ~/.config/nvim/startify.vim
source ~/.config/nvim/vimwiki.vim
lua require('lsp-config')
-lua require('lsp-saga')
lua require('completion')
lua require('treesitter')
lua require('filetree')
diff --git a/nvim/.config/nvim/lua/completion.lua b/nvim/.config/nvim/lua/completion.lua
index 3bca660..2e925db 100644
--- a/nvim/.config/nvim/lua/completion.lua
+++ b/nvim/.config/nvim/lua/completion.lua
@@ -1,61 +1,41 @@
--- Compe setup
-require'compe'.setup {
- enabled = true;
- autocomplete = true;
- debug = false;
- min_length = 1;
- preselect = 'enable';
- throttle_time = 80;
- source_timeout = 200;
- incomplete_delay = 400;
- max_abbr_width = 100;
- max_kind_width = 100;
- max_menu_width = 100;
- documentation = true;
+local cmp = require'cmp'
+local lspkind = require 'lspkind'
+local luasnip = require 'luasnip'
+lspkind.init()
- source = {
- path = true;
- nvim_lsp = true;
- };
-}
-
-local t = function(str)
- return vim.api.nvim_replace_termcodes(str, true, true, true)
-end
-
-local check_back_space = function()
- local col = vim.fn.col('.') - 1
- if col == 0 or vim.fn.getline('.'):sub(col, col):match('%s') then
- return true
- else
- return false
- end
-end
-
--- Use (s-)tab to:
---- move to prev/next item in completion menuone
---- jump to prev/next snippet's placeholder
-_G.tab_complete = function()
- if vim.fn.pumvisible() == 1 then
- return t "<C-n>"
- elseif check_back_space() then
- return t "<Tab>"
- else
- return vim.fn['compe#complete']()
- end
-end
-_G.s_tab_complete = function()
- if vim.fn.pumvisible() == 1 then
- return t "<C-p>"
- else
- return t "<S-Tab>"
- end
-end
-
-vim.opt.completeopt = { "menuone", "noselect" }
-vim.api.nvim_set_keymap("i", "<Tab>", "v:lua.tab_complete()", {expr = true})
-vim.api.nvim_set_keymap("s", "<Tab>", "v:lua.tab_complete()", {expr = true})
-vim.api.nvim_set_keymap("i", "<S-Tab>", "v:lua.s_tab_complete()", {expr = true})
-vim.api.nvim_set_keymap("s", "<S-Tab>", "v:lua.s_tab_complete()", {expr = true})
-vim.api.nvim_set_keymap('i', '<c-space>', 'compe#complete()', { expr = true })
-vim.api.nvim_set_keymap('i', '<cr>', 'compe#confirm({ "keys": "\\<Plug>delimitMateCR", "mode": "" })', { expr = true })
+cmp.setup({
+ snippet = {
+ expand = function(args)
+ require('luasnip').lsp_expand(args.body)
+ end,
+ },
+ mapping = {
+ ['<C-Space>'] = cmp.mapping.complete(),
+ ['<C-e>'] = cmp.mapping.close(),
+ ['<CR>'] = cmp.mapping.confirm({
+ behavior = cmp.ConfirmBehavior.Insert,
+ select = true,
+ }),
+ },
+ sources = {
+ { name = 'nvim_lsp' },
+ { name = 'nvim_lua' },
+ { name = 'path' },
+ { name = 'luasnip' },
+ { name = 'buffer', keyword_length = 5 },
+ },
+ formatting = {
+ format = lspkind.cmp_format {
+ with_text = true,
+ menu = {
+ buffer = '[buf]',
+ nvim_lsp = '[LSP]',
+ nvim_lua = '[api]',
+ luasnip = '[snip]',
+ },
+ },
+ },
+ experimental = {
+ ghost_text = true,
+ }
+})
diff --git a/nvim/.config/nvim/lua/lsp-config.lua b/nvim/.config/nvim/lua/lsp-config.lua
index 4d55fc0..a7c28c5 100644
--- a/nvim/.config/nvim/lua/lsp-config.lua
+++ b/nvim/.config/nvim/lua/lsp-config.lua
@@ -17,6 +17,8 @@ local on_attach = function(client, bufnr)
buf_set_keymap('n', 'gD', '<cmd>lua vim.lsp.buf.type_definition()<CR>', opts)
buf_set_keymap('n', 'gi', '<cmd>lua vim.lsp.buf.implementation()<CR>', opts)
buf_set_keymap('n', 'gr', '<cmd>lua vim.lsp.buf.references()<CR>', opts)
+ buf_set_keymap('n', 'K', '<cmd>lua vim.lsp.buf.hover()<CR>', opts)
+ buf_set_keymap('n', '<C-k>', '<cmd>lua vim.lsp.buf.signature_help()<CR>', opts)
buf_set_keymap('n', '<leader>rn', '<cmd>lua vim.lsp.buf.rename()<CR>', opts)
buf_set_keymap('n', '<leader>ca', '<cmd>lua vim.lsp.buf.code_action()<CR>', opts)
end
@@ -25,28 +27,35 @@ local flags = {
debounce_text_changes = 150,
}
+local capabilities = vim.lsp.protocol.make_client_capabilities()
+capabilities = require('cmp_nvim_lsp').update_capabilities(capabilities)
+
-- Typescript
nvim_lsp.tsserver.setup {
on_attach = on_attach,
flags = flags,
+ capabilities = capabilities,
}
-- Vue
nvim_lsp.vuels.setup{
on_attach = on_attach,
flags = flags,
+ capabilities = capabilities,
}
-- Rust
nvim_lsp.rust_analyzer.setup{
on_attach = on_attach,
flags = flags,
+ capabilities = capabilities,
}
-- Python
nvim_lsp.pylsp.setup{
on_attach = on_attach,
flags = flags,
+ capabilities = capabilities,
}
-- Lua
@@ -57,6 +66,7 @@ table.insert(runtime_path, "lua/?/init.lua")
nvim_lsp.sumneko_lua.setup {
on_attach = on_attach,
flags = flags,
+ capabilities = capabilities,
cmd = { '/usr/bin/lua-language-server' }, -- Install from yay
settings = {
Lua = {
diff --git a/nvim/.config/nvim/lua/lsp-saga.lua b/nvim/.config/nvim/lua/lsp-saga.lua
deleted file mode 100644
index d3c1739..0000000
--- a/nvim/.config/nvim/lua/lsp-saga.lua
+++ /dev/null
@@ -1,11 +0,0 @@
-local saga = require 'lspsaga'
-
-vim.api.nvim_set_keymap('n', 'K', ':Lspsaga hover_doc<CR>', { noremap = true, silent = true })
-
-saga.init_lsp_saga {
- error_sign = '',
- warn_sign = '',
- hint_sign = '',
- infor_sign = '',
- border_style = "round",
-}
diff --git a/nvim/.config/nvim/lua/plugins.lua b/nvim/.config/nvim/lua/plugins.lua
index 317c370..519537c 100644
--- a/nvim/.config/nvim/lua/plugins.lua
+++ b/nvim/.config/nvim/lua/plugins.lua
@@ -1,4 +1,4 @@
-return require('packer').startup(function()
+return require('packer').startup(function(use)
-- Packer can manage itself
use 'wbthomason/packer.nvim'
@@ -10,8 +10,18 @@ return require('packer').startup(function()
-- Built-in LSP
use 'neovim/nvim-lspconfig'
- use 'hrsh7th/nvim-compe'
- use 'glepnir/lspsaga.nvim'
+
+ -- Autocompletion
+ use 'hrsh7th/nvim-cmp'
+ use 'hrsh7th/cmp-buffer'
+ use 'hrsh7th/cmp-path'
+ use 'hrsh7th/cmp-nvim-lsp'
+ use 'hrsh7th/cmp-nvim-lua'
+ use 'onsails/lspkind-nvim'
+
+ -- Snippets (only used for autocompletion)
+ use 'L3MON4D3/LuaSnip'
+ use 'saadparwaiz1/cmp_luasnip'
-- Treesitter
use { 'nvim-treesitter/nvim-treesitter', run = ':TSUpdate' }