From be7acfd660f449027f87ed1c2aaa8a60b2ec27aa Mon Sep 17 00:00:00 2001 From: eug-vs Date: Fri, 22 Oct 2021 12:04:55 +0300 Subject: feat(nvim): migrate to nvim-cmp --- nvim/.config/nvim/init.vim | 2 +- nvim/.config/nvim/lua/completion.lua | 100 ++++++++++++++--------------------- nvim/.config/nvim/lua/lsp-config.lua | 10 ++++ nvim/.config/nvim/lua/lsp-saga.lua | 11 ---- nvim/.config/nvim/lua/plugins.lua | 16 ++++-- 5 files changed, 64 insertions(+), 75 deletions(-) delete mode 100644 nvim/.config/nvim/lua/lsp-saga.lua (limited to 'nvim/.config') 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 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 "" - elseif check_back_space() then - return t "" - else - return vim.fn['compe#complete']() - end -end -_G.s_tab_complete = function() - if vim.fn.pumvisible() == 1 then - return t "" - else - return t "" - end -end - -vim.opt.completeopt = { "menuone", "noselect" } -vim.api.nvim_set_keymap("i", "", "v:lua.tab_complete()", {expr = true}) -vim.api.nvim_set_keymap("s", "", "v:lua.tab_complete()", {expr = true}) -vim.api.nvim_set_keymap("i", "", "v:lua.s_tab_complete()", {expr = true}) -vim.api.nvim_set_keymap("s", "", "v:lua.s_tab_complete()", {expr = true}) -vim.api.nvim_set_keymap('i', '', 'compe#complete()', { expr = true }) -vim.api.nvim_set_keymap('i', '', 'compe#confirm({ "keys": "\\delimitMateCR", "mode": "" })', { expr = true }) +cmp.setup({ + snippet = { + expand = function(args) + require('luasnip').lsp_expand(args.body) + end, + }, + mapping = { + [''] = cmp.mapping.complete(), + [''] = cmp.mapping.close(), + [''] = 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', 'lua vim.lsp.buf.type_definition()', opts) buf_set_keymap('n', 'gi', 'lua vim.lsp.buf.implementation()', opts) buf_set_keymap('n', 'gr', 'lua vim.lsp.buf.references()', opts) + buf_set_keymap('n', 'K', 'lua vim.lsp.buf.hover()', opts) + buf_set_keymap('n', '', 'lua vim.lsp.buf.signature_help()', opts) buf_set_keymap('n', 'rn', 'lua vim.lsp.buf.rename()', opts) buf_set_keymap('n', 'ca', 'lua vim.lsp.buf.code_action()', 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', { 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' } -- cgit v1.2.3