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