Migrate to nvim-cmp over nvim-compe

pull/2/head
Ensar Sarajčić 2021-10-08 16:28:07 +02:00
parent 60d4643cbd
commit fbfd4800f9
3 changed files with 34 additions and 36 deletions

View File

@ -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

View File

@ -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 = {
['<C-d>'] = cmp.mapping.scroll_docs(-4),
['<C-f>'] = cmp.mapping.scroll_docs(4),
['<C-Space>'] = cmp.mapping.complete(),
['<C-e>'] = cmp.mapping.close(),
['<C-y>'] = 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', '<C-Space>', 'compe#complete()', default_opts)
set_keymap('i', '<C-y>', "compe#confirm('<C-y>')", default_opts)
set_keymap('i', '<C-e>', "compe#close('<C-e>')", default_opts)
set_keymap('i', '<C-f>', "compe#scroll({ 'delta': +4 })", default_opts)
set_keymap('i', '<C-d>', "compe#scroll({ 'delta': -4 })", default_opts)

View File

@ -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
}