nvim: ref cmp

This commit is contained in:
TheK4n 2023-03-12 23:09:28 +03:00
parent c4aee638e9
commit dca683a6e1
3 changed files with 48 additions and 15 deletions

View File

@ -8,11 +8,14 @@ local function has_words_before()
return col ~= 0 and vim.api.nvim_buf_get_lines(0, line - 1, line, true)[1]:sub(col, col):match("%s") == nil
end
-- nvim-cmp setup
local cmp = require 'cmp'
local border_opts = {
border = "single",
winhighlight = "Normal:Normal,FloatBorder:FloatBorder,CursorLine:Visual,Search:None",
}
cmp.setup {
completion = {
autocomplete = false
autocomplete = true
},
snippet = {
expand = function(args)
@ -24,7 +27,7 @@ cmp.setup {
if cmp.visible() then
cmp.select_next_item()
elseif has_words_before() then
cmp.complete()
cmp.complete()
else
fallback()
end
@ -35,11 +38,34 @@ cmp.setup {
['<C-e>'] = cmp.mapping.close(),
['<CR>'] = cmp.mapping.confirm {
behavior = cmp.ConfirmBehavior.Replace,
select = true,
select = false,
},
},
sources = {
{ name = 'nvim_lsp' },
{ name = 'luasnip' },
window = {
completion = cmp.config.window.bordered(border_opts),
documentation = cmp.config.window.bordered(border_opts),
},
sources = cmp.config.sources({
{ name = 'nvim_lsp', priority = 1000 },
{ name = 'luasnip', priority = 750 },
{ name = 'buffer', priority = 500 },
{ name = 'path', priority = 250 },
}, {
}),
}
cmp.setup.cmdline({ '/', '?' }, {
mapping = cmp.mapping.preset.cmdline(),
sources = {
{ name = 'buffer' }
}
})
cmp.setup.cmdline(':', {
mapping = cmp.mapping.preset.cmdline(),
sources = cmp.config.sources({
{ name = 'path' }
}, {
{ name = 'cmdline' }
})
})

View File

@ -48,3 +48,9 @@ for _, lsp in ipairs(servers) do
}
}
end
local capabilities = require('cmp_nvim_lsp').default_capabilities(vim.lsp.protocol.make_client_capabilities())
nvim_lsp.clangd.setup {
capabilities = capabilities,
}

View File

@ -105,13 +105,14 @@ local plugins = {
'neovim/nvim-lspconfig'
},
{
'hrsh7th/nvim-cmp'
},
{
'hrsh7th/cmp-nvim-lsp'
},
{
'saadparwaiz1/cmp_luasnip'
'hrsh7th/nvim-cmp',
dependencies = {
"hrsh7th/cmp-buffer",
"hrsh7th/cmp-path",
"hrsh7th/cmp-cmdline",
'saadparwaiz1/cmp_luasnip',
'hrsh7th/cmp-nvim-lsp',
}
},
{
'L3MON4D3/LuaSnip',