nvim-config/lua/plugins/cmp.lua

106 lines
3.3 KiB
Lua

local cmp = require("cmp")
cmp.setup {
snippet = {
expand = function(args)
vim.fn["vsnip#anonymous"](args.body)
end,
},
window = {
completion = {
border = { "", "", "", "", "", "", "", "" },
},
documentation = {
border = { "", "", "", "", "", "", "", "" },
},
},
-- window = {
-- completion = cmp.config.window.bordered(),
-- documentation = cmp.config.window.bordered(),
-- },
mapping = cmp.mapping.preset.insert({
["<C-k>"] = cmp.mapping.select_prev_item(),
["<C-j>"] = cmp.mapping.select_next_item(),
["<C-b>"] = cmp.mapping(cmp.mapping.scroll_docs(-1), { "i", "c" }),
["<C-f>"] = cmp.mapping(cmp.mapping.scroll_docs(1), { "i", "c" }),
["<C-Space>"] = cmp.mapping(cmp.mapping.complete(), { "i", "c" }),
["<C-y>"] = cmp.config.disable, -- Specify `cmp.config.disable` if you want to remove the default `<C-y>` mapping.
["<C-e>"] = cmp.mapping {
i = cmp.mapping.abort(),
c = cmp.mapping.close(),
},
-- Accept currently selected item. If none selected, `select` first item.
-- Set `select` to `false` to only confirm explicitly selected items.
["<CR>"] = cmp.mapping.confirm { select = false },
["<Tab>"] = cmp.mapping(function(fallback)
if cmp.visible() then
cmp.select_next_item()
else
fallback()
end
end, { "i", "s" }),
["<S-Tab>"] = cmp.mapping(function(fallback)
if cmp.visible() then
cmp.select_prev_item()
else
fallback()
end
end, { "i", "s" })
}),
sources = cmp.config.sources(
{
{ name = 'nvim_lsp' },
{ name = 'nvim_lsp_signature_help' },
{ name = 'vsnip' },
{ name = 'nvim_lua' },
{ name = 'path' },
{ name = 'buffer' },
}
),
experimental = {
ghost_text = false,
native_menu = false,
},
}
-- Setup configuration for a specific type of file
cmp.setup.filetype('gitcommit', {
sources = cmp.config.sources({
{ name = 'git' },
}, {
{ name = 'buffer' },
})
})
-- Использовать источник буфера для `/` и `?` (если вы включили `native_menu`, это больше не будет работать)
cmp.setup.cmdline({ '/', '?' }, {
mapping = cmp.mapping.preset.cmdline(),
sources = { { name = 'buffer' } }
})
-- Используйте cmdline и источник пути для ':' (если вы включили `native_menu`, это больше не будет работать)
cmp.setup.cmdline(':', {
mapping = cmp.mapping.preset.cmdline(),
sources = cmp.config.sources({ { name = 'path' } }, { { name = 'cmdline' } })
})
-- Настройка конфига LSP
local capabilities = require('cmp_nvim_lsp').default_capabilities()
-- Замените <YOUR_LSP_SERVER> на нужный lsp-сервер (для каждого нужно создавать отдельный параметр)
-- require('lspconfig')['<YOUR_LSP_SERVER>'].setup {capabilities = capabilities}
require('lspconfig')['pyright'].setup { capabilities = capabilities }
-- Подстановка скобок к подсказкам, которым это нужно (дополнение для nvim-autopairs)
local cmp_autopairs = require('nvim-autopairs.completion.cmp')
cmp.event:on(
'confirm_done',
cmp_autopairs.on_confirm_done()
)