241 lines
8.3 KiB
Lua
241 lines
8.3 KiB
Lua
local function has_words_before()
|
|
local line, col = unpack(vim.api.nvim_win_get_cursor(0))
|
|
return col ~= 0 and vim.api.nvim_buf_get_lines(0, line - 1, line, true)[1]:sub(col, col):match("%s") == nil
|
|
end
|
|
|
|
local function setup_cmp()
|
|
local cmp = require("cmp")
|
|
|
|
cmp.setup({
|
|
preselect = cmp.PreselectMode.None,
|
|
completion = {
|
|
completeopt = 'menu,menuone,noinsert,noselect',
|
|
},
|
|
snippet = {
|
|
expand = function(args)
|
|
vim.snippet.expand(args.body)
|
|
end,
|
|
},
|
|
mapping = cmp.mapping.preset.insert({
|
|
['<Tab>'] = cmp.mapping(
|
|
function(fallback)
|
|
if cmp.visible() then
|
|
cmp.confirm({
|
|
behavior = cmp.ConfirmBehavior.Select,
|
|
select = true,
|
|
})
|
|
elseif has_words_before() then
|
|
cmp.complete()
|
|
else
|
|
fallback()
|
|
end
|
|
end,
|
|
{ "i", "s" }
|
|
),
|
|
['<C-k>'] = cmp.mapping.select_prev_item({ behaviour = cmp.SelectBehavior.Select }),
|
|
['<C-j>'] = cmp.mapping.select_next_item({ behaviour = cmp.SelectBehavior.Select }),
|
|
['<C-p>'] = cmp.mapping.scroll_docs(-4),
|
|
['<C-n>'] = cmp.mapping.scroll_docs(4),
|
|
['<C-e>'] = cmp.mapping.abort(),
|
|
}),
|
|
window = {
|
|
completion = {
|
|
border = "rounded",
|
|
winhighlight = "Normal:Normal,FloatBorder:FloatBorder",
|
|
scrollbar = true,
|
|
col_offset = 0,
|
|
side_padding = 1,
|
|
},
|
|
documentation = {
|
|
border = "rounded",
|
|
winhighlight = "Normal:Normal,FloatBorder:FloatBorder",
|
|
max_width = 60,
|
|
max_height = 20,
|
|
scrollbar = true,
|
|
},
|
|
},
|
|
formatting = {
|
|
format = function(entry, vim_item)
|
|
local kind_icons = {
|
|
Text = "",
|
|
Method = "",
|
|
Function = "",
|
|
Constructor = "",
|
|
Field = "",
|
|
Variable = "",
|
|
Class = "",
|
|
Interface = "",
|
|
Module = "",
|
|
Property = "",
|
|
Unit = "",
|
|
Value = "",
|
|
Enum = "",
|
|
Keyword = "",
|
|
Snippet = "",
|
|
Color = "",
|
|
File = "",
|
|
Reference = "",
|
|
Folder = "",
|
|
EnumMember = "",
|
|
Constant = "",
|
|
Struct = "",
|
|
Event = "",
|
|
Operator = "",
|
|
TypeParameter = "",
|
|
}
|
|
vim_item.kind = string.format('%s %s', kind_icons[vim_item.kind] or '', vim_item.kind)
|
|
|
|
local source_names = {
|
|
nvim_lsp = "LSP",
|
|
luasnip = "Snippet",
|
|
buffer = "Buffer",
|
|
tmux = "Tmux",
|
|
dotenv = "Env",
|
|
path = "Path",
|
|
}
|
|
vim_item.menu = string.format("[%s]", source_names[entry.source.name] or entry.source.name)
|
|
|
|
return vim_item
|
|
end,
|
|
},
|
|
sorting = {
|
|
priority_weight = 1.0,
|
|
comparators = {
|
|
cmp.config.compare.score,
|
|
cmp.config.compare.locality,
|
|
cmp.config.compare.recently_used,
|
|
cmp.config.compare.offset,
|
|
require("cmp-under-comparator").under,
|
|
cmp.config.compare.order,
|
|
},
|
|
},
|
|
sources = cmp.config.sources({
|
|
{ name = 'nvim_lsp', priority = 1500 },
|
|
-- { name = 'copilot', priority = 1400 },
|
|
{ name = 'luasnip', priority = 1250 },
|
|
{ name = 'buffer', priority = 1000 },
|
|
{ name = 'tmux', priority = 750 },
|
|
{ name = "dotenv", priority = 500 },
|
|
{ name = 'path', priority = 250 },
|
|
}),
|
|
})
|
|
end
|
|
|
|
return {
|
|
{
|
|
'L3MON4D3/LuaSnip',
|
|
event = "InsertEnter",
|
|
build = "make install_jsregexp",
|
|
dependencies = {
|
|
'hrsh7th/nvim-cmp',
|
|
'honza/vim-snippets',
|
|
},
|
|
config = function()
|
|
local ls = require("luasnip")
|
|
|
|
vim.g.snips_author = 'thek4n'
|
|
vim.g.snips_email = 'thek4n@yandex.com'
|
|
vim.g.snips_github = 'https://github.com/thek4n'
|
|
|
|
local function jump(val)
|
|
return function()
|
|
ls.jump(val)
|
|
end
|
|
end
|
|
|
|
local map = vim.keymap.set
|
|
map({'i', 's'}, '<C-n>', jump(1), {silent = true})
|
|
map({'i', 's'}, '<C-p>', jump(-1), {silent = true})
|
|
map({'i', 's'}, '<C-k>', ls.expand, {silent = true})
|
|
map({"i", "s"}, "<C-e>",
|
|
function()
|
|
if ls.choice_active() then
|
|
ls.change_choice(1)
|
|
end
|
|
end,
|
|
{silent = true}
|
|
)
|
|
|
|
local luasnip_loaders = require("luasnip.loaders.from_snipmate")
|
|
|
|
luasnip_loaders.lazy_load()
|
|
end
|
|
},
|
|
{
|
|
'hrsh7th/nvim-cmp',
|
|
event = "InsertEnter",
|
|
dependencies = {
|
|
"hrsh7th/cmp-buffer",
|
|
"hrsh7th/cmp-path",
|
|
'saadparwaiz1/cmp_luasnip',
|
|
'hrsh7th/cmp-nvim-lsp',
|
|
'lukas-reineke/cmp-under-comparator',
|
|
'SergioRibera/cmp-dotenv',
|
|
'andersevenrud/cmp-tmux',
|
|
'zbirenbaum/copilot-cmp',
|
|
'zbirenbaum/copilot.lua',
|
|
},
|
|
config = setup_cmp,
|
|
},
|
|
-- {
|
|
-- 'zbirenbaum/copilot.lua',
|
|
-- cmd = "Copilot",
|
|
-- event = "InsertEnter",
|
|
-- config = function()
|
|
-- require("copilot").setup({
|
|
-- suggestion = {
|
|
-- enabled = true,
|
|
-- auto_trigger = true,
|
|
-- debounce = 75,
|
|
-- keymap = {
|
|
-- accept = "<C-l>",
|
|
-- accept_word = false,
|
|
-- accept_line = "<C-y>", -- принять строку
|
|
-- next = "<M-]>", -- следующее предложение
|
|
-- prev = "<M-[>", -- предыдущее предложение
|
|
-- dismiss = "<C-b>", -- отклонить
|
|
-- },
|
|
-- },
|
|
-- panel = {
|
|
-- enabled = true,
|
|
-- auto_refresh = false,
|
|
-- keymap = {
|
|
-- jump_prev = "[[",
|
|
-- jump_next = "]]",
|
|
-- accept = "<CR>",
|
|
-- refresh = "gr",
|
|
-- open = "<M-CR>"
|
|
-- },
|
|
-- },
|
|
-- filetypes = {
|
|
-- yaml = true,
|
|
-- markdown = true,
|
|
-- help = false,
|
|
-- gitcommit = true,
|
|
-- gitrebase = false,
|
|
-- hgcommit = false,
|
|
-- svn = false,
|
|
-- cvs = false,
|
|
-- ["."] = false,
|
|
-- },
|
|
-- copilot_node_command = 'node',
|
|
-- server_opts_overrides = {},
|
|
-- })
|
|
-- end,
|
|
-- },
|
|
-- {
|
|
-- 'zbirenbaum/copilot-cmp',
|
|
-- dependencies = { 'zbirenbaum/copilot.lua' },
|
|
-- config = function()
|
|
-- require("copilot_cmp").setup({
|
|
-- method = "getCompletionsCycle",
|
|
-- formatters = {
|
|
-- label = require("copilot_cmp.format").format_label_text,
|
|
-- kind = require("copilot_cmp.format").format_kind,
|
|
-- documentation = require("copilot_cmp.format").format_documentation,
|
|
-- },
|
|
-- })
|
|
-- end,
|
|
-- },
|
|
}
|