aboutsummaryrefslogtreecommitdiff
path: root/lua/config
diff options
context:
space:
mode:
authorjdhao <jdhao@hotmail.com>2021-10-18 21:56:32 +0800
committerjdhao <jdhao@hotmail.com>2021-10-18 21:57:06 +0800
commite2bcb7d8f40e399347c8e633e6cb4712d061c790 (patch)
tree4f6110beaf77beb3c77fad70bf4f75e53f67cf5a /lua/config
parenta603ce3e4dc67512c986bcbe86d888ad80518213 (diff)
transition from nvim-compe to nvim-cmp
Diffstat (limited to 'lua/config')
-rw-r--r--lua/config/compe.lua38
-rw-r--r--lua/config/lsp.lua6
-rw-r--r--lua/config/nvim-cmp.lua41
3 files changed, 46 insertions, 39 deletions
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", "<C-Space>", "compe#complete()", compe_map_opts)
-vim.api.nvim_set_keymap("i", "<CR>", "compe#confirm('<CR>')", compe_map_opts)
-vim.api.nvim_set_keymap("i", "<ESC>", "compe#close('<ESC>')", compe_map_opts)
-vim.api.nvim_set_keymap("i", "<C-f>", "compe#scroll({'delta': +4})", compe_map_opts)
-vim.api.nvim_set_keymap("i", "<C-d>", "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 = {
+ ['<Tab>'] = function(fallback)
+ if cmp.visible() then
+ cmp.select_next_item()
+ else
+ fallback()
+ end
+ end,
+ ['<S-Tab>'] = function(fallback)
+ if cmp.visible() then
+ cmp.select_prev_item()
+ else
+ fallback()
+ end
+ end,
+ ['<Esc>'] = 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
+ }
+})