From fbfd4800f97fef8c5516372b974719ab982a2109 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ensar=20Saraj=C4=8Di=C4=87?= Date: Fri, 8 Oct 2021 16:28:07 +0200 Subject: [PATCH] Migrate to nvim-cmp over nvim-compe --- symlinks/config/nvim/lua/init/plugins.lua | 4 +- symlinks/config/nvim/lua/lsp/completion.lua | 53 ++++++++------------- symlinks/config/nvim/lua/lsp/servers.lua | 13 ++++- 3 files changed, 34 insertions(+), 36 deletions(-) diff --git a/symlinks/config/nvim/lua/init/plugins.lua b/symlinks/config/nvim/lua/init/plugins.lua index 17407a7..7c476e0 100644 --- a/symlinks/config/nvim/lua/init/plugins.lua +++ b/symlinks/config/nvim/lua/init/plugins.lua @@ -78,7 +78,9 @@ return require('packer').startup { -- LSP -- use 'neovim/nvim-lspconfig' -- Easy LSP Config use 'alexaandru/nvim-lspupdate' -- Easy install and update for many LSP servers - use 'hrsh7th/nvim-compe' -- LSP completion integration + use 'hrsh7th/cmp-nvim-lsp' -- LSP source for cmp + use 'hrsh7th/cmp-buffer' -- Buffer source for nvim-cmp + use 'hrsh7th/nvim-cmp' -- completion integration use 'nvim-lua/lsp_extensions.nvim' -- LSP extensions (like closing labels for Dart) -- LSP language specific diff --git a/symlinks/config/nvim/lua/lsp/completion.lua b/symlinks/config/nvim/lua/lsp/completion.lua index 81bc85d..95ecf69 100644 --- a/symlinks/config/nvim/lua/lsp/completion.lua +++ b/symlinks/config/nvim/lua/lsp/completion.lua @@ -3,38 +3,25 @@ ------------------------------------------------------------------------------- -- Set completeopt to have a better completion experience -vim.o.completeopt = "menuone,noselect" +vim.o.completeopt = "menu,menuone,noselect" -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; - - source = { - path = true; - buffer = true; - calc = true; - nvim_lsp = true; - nvim_lua = true; - ultisnips = true; - }; +local cmp = require'cmp' +cmp.setup { + snippet = { + expand = function(args) + vim.fn["UltiSnips#Anon"](args.body) + end, + }, + mapping = { + [''] = cmp.mapping.scroll_docs(-4), + [''] = cmp.mapping.scroll_docs(4), + [''] = cmp.mapping.complete(), + [''] = cmp.mapping.close(), + [''] = cmp.mapping.confirm({ select = true }), + }, + sources = { + { name = 'nvim_lsp' }, + { name = 'ultisnips' }, + { name = 'buffer' }, + } } - -local function set_keymap(...) vim.api.nvim_set_keymap(...) end - -local default_opts = {noremap = true, silent = true, expr = true} - -set_keymap('i', '', 'compe#complete()', default_opts) -set_keymap('i', '', "compe#confirm('')", default_opts) -set_keymap('i', '', "compe#close('')", default_opts) -set_keymap('i', '', "compe#scroll({ 'delta': +4 })", default_opts) -set_keymap('i', '', "compe#scroll({ 'delta': -4 })", default_opts) diff --git a/symlinks/config/nvim/lua/lsp/servers.lua b/symlinks/config/nvim/lua/lsp/servers.lua index 9e2e152..1d54fa1 100644 --- a/symlinks/config/nvim/lua/lsp/servers.lua +++ b/symlinks/config/nvim/lua/lsp/servers.lua @@ -5,15 +5,21 @@ local lspconfig = require("lspconfig") local common_config = require("lsp.server_config") +local capabilities = require('cmp_nvim_lsp').update_capabilities(vim.lsp.protocol.make_client_capabilities()) + -- Lsp default language servers local servers = { "bashls", "clangd", "cucumber_language_server", "crystalline", "dockerls", "jsonls", "pyright", "rust_analyzer", "kotlin_language_server", "mint", "vimls", "clojure_lsp", "gopls", "gdscript", "terraformls", "tsserver" } for _, lsp in ipairs(servers) do - lspconfig[lsp].setup { on_attach = common_config.on_attach } + lspconfig[lsp].setup { + on_attach = common_config.on_attach, + capabilities = capabilities + } end -- Lua bultin lsp require('nlua.lsp.nvim').setup(lspconfig, { on_attach = common_config.on_attach, + capabilities = capabilities, -- Include globals you want to tell the LSP are real :) globals = {} @@ -22,7 +28,8 @@ require('nlua.lsp.nvim').setup(lspconfig, { -- Flutter tools require('flutter-tools').setup { lsp = { - on_attach = common_config.on_attach + on_attach = common_config.on_attach, + capabilities = capabilities } } @@ -32,10 +39,12 @@ local omnisharp_bin = vim.fn.glob('$HOME') .. "/lsp/dotnet/omnisharp/run" lspconfig.omnisharp.setup { cmd = { omnisharp_bin, "--languageserver" , "--hostPID", tostring(pid) }; on_attach = common_config.on_attach; + capabilities = capabilities } -- Leminx (XML Language server) lspconfig.lemminx.setup { cmd = { "lemminx" }; on_attach = common_config.on_attach; + capabilities = capabilities }