From e2bcb7d8f40e399347c8e633e6cb4712d061c790 Mon Sep 17 00:00:00 2001 From: jdhao Date: Mon, 18 Oct 2021 21:56:32 +0800 Subject: transition from nvim-compe to nvim-cmp --- lua/config/compe.lua | 38 -------------------------------------- lua/config/lsp.lua | 6 +++++- lua/config/nvim-cmp.lua | 41 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 46 insertions(+), 39 deletions(-) delete mode 100644 lua/config/compe.lua create mode 100644 lua/config/nvim-cmp.lua (limited to 'lua/config') diff --git a/lua/config/compe.lua b/lua/config/compe.lua deleted file mode 100644 index 5286a9d..0000000 --- a/lua/config/compe.lua +++ /dev/null @@ -1,38 +0,0 @@ --- nvim-compe settings -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 = { - omni = { filetypes = { "tex" } }, - path = true, - buffer = false, - spell = { filetypes = { "markdown", "tex" } }, - emoji = true, - nvim_lsp = true, - nvim_lua = true, - ultisnips = true, - calc = false, - vsnip = false, - }, -}) - -vim.o.completeopt = "menuone,noselect" - --- nvim-compe mappings -local compe_map_opts = { expr = true, noremap = true, silent = true } -vim.api.nvim_set_keymap("i", "", "compe#complete()", compe_map_opts) -vim.api.nvim_set_keymap("i", "", "compe#confirm('')", compe_map_opts) -vim.api.nvim_set_keymap("i", "", "compe#close('')", compe_map_opts) -vim.api.nvim_set_keymap("i", "", "compe#scroll({'delta': +4})", compe_map_opts) -vim.api.nvim_set_keymap("i", "", "compe#scroll({'delta': -4})", compe_map_opts) diff --git a/lua/config/lsp.lua b/lua/config/lsp.lua index f362e54..f65eb9e 100644 --- a/lua/config/lsp.lua +++ b/lua/config/lsp.lua @@ -66,7 +66,7 @@ local custom_attach = function(client, bufnr) -- vim.notify(msg, 'info', {title = 'Nvim-config', timeout = 2500}) end -local capabilities = vim.lsp.protocol.make_client_capabilities() +capabilities = require('cmp_nvim_lsp').update_capabilities(vim.lsp.protocol.make_client_capabilities()) capabilities.textDocument.completion.completionItem.snippetSupport = true local lspconfig = require("lspconfig") @@ -88,10 +88,12 @@ lspconfig.pylsp.setup({ flags = { debounce_text_changes = 200, }, + capabilities = capabilities, }) -- lspconfig.pyright.setup{ -- on_attach = custom_attach, +-- capabilities = capabilities -- } lspconfig.clangd.setup({ @@ -109,6 +111,7 @@ lspconfig.vimls.setup({ flags = { debounce_text_changes = 500, }, + capabilities = capabilities, }) local sumneko_binary_path = vim.fn.exepath("lua-language-server") @@ -144,6 +147,7 @@ if vim.g.is_mac or vim.g.is_linux and sumneko_binary_path ~= "" then }, }, }, + capabilities = capabilities, }) end diff --git a/lua/config/nvim-cmp.lua b/lua/config/nvim-cmp.lua new file mode 100644 index 0000000..97350b2 --- /dev/null +++ b/lua/config/nvim-cmp.lua @@ -0,0 +1,41 @@ +-- Setup nvim-cmp. +local cmp = require'cmp' + +cmp.setup({ + snippet = { + expand = function(args) + -- For `ultisnips` user. + vim.fn["UltiSnips#Anon"](args.body) + end, + }, + mapping = { + [''] = function(fallback) + if cmp.visible() then + cmp.select_next_item() + else + fallback() + end + end, + [''] = function(fallback) + if cmp.visible() then + cmp.select_prev_item() + else + fallback() + end + end, + [''] = cmp.mapping.close(), + }, + sources = { + { name = 'nvim_lsp' }, -- For nvim-lsp + { name = 'ultisnips' }, -- For ultisnips user. + { name = 'path' }, -- for path completion + { name = 'emoji', insert = true, } -- emoji completion + }, + completion = { + keyword_length = 1, + completeopt = "menu,menuone,noinsert" + }, + experimental = { + ghost_text = false + } +}) -- cgit v1.2.3