mirror of
https://github.com/kristoferssolo/SoloVim.git
synced 2025-10-21 20:10:41 +00:00
fix cmp
This commit is contained in:
parent
7ce24049e1
commit
ceb534f014
101
lua/user/cmp.lua
101
lua/user/cmp.lua
@ -3,18 +3,11 @@ if not cmp_status_ok then
|
|||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
local snip_status_ok, luasnip = pcall(require, "luasnip")
|
local luasnip_status_ok, luasnip = pcall(require, "luasnip")
|
||||||
if not snip_status_ok then
|
if not luasnip_status_ok then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
require("luasnip/loaders/from_vscode").lazy_load()
|
|
||||||
|
|
||||||
local check_backspace = function()
|
|
||||||
local col = vim.fn.col(".") - 1
|
|
||||||
return col == 0 or vim.fn.getline("."):sub(col, col):match("%s")
|
|
||||||
end
|
|
||||||
|
|
||||||
local kind_icons = {
|
local kind_icons = {
|
||||||
Text = "",
|
Text = "",
|
||||||
Method = "",
|
Method = "",
|
||||||
@ -44,85 +37,59 @@ local kind_icons = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
cmp.setup({
|
cmp.setup({
|
||||||
snippet = {
|
mapping = {
|
||||||
expand = function(args)
|
|
||||||
luasnip.lsp_expand(args.body) -- For `luasnip` users.
|
|
||||||
end,
|
|
||||||
},
|
|
||||||
|
|
||||||
mapping = cmp.mapping.preset.insert({
|
|
||||||
["<C-k>"] = cmp.mapping.select_prev_item(),
|
["<C-k>"] = cmp.mapping.select_prev_item(),
|
||||||
["<C-j>"] = cmp.mapping.select_next_item(),
|
["<C-j>"] = cmp.mapping.select_next_item(),
|
||||||
["<C-b>"] = cmp.mapping(cmp.mapping.scroll_docs(-1), { "i", "c" }),
|
["<C-d>"] = cmp.mapping.scroll_docs(-4),
|
||||||
["<C-f>"] = cmp.mapping(cmp.mapping.scroll_docs(1), { "i", "c" }),
|
["<C-u>"] = cmp.mapping.scroll_docs(4),
|
||||||
["<C-Space>"] = cmp.mapping(cmp.mapping.complete(), { "i", "c" }),
|
["<C-Space>"] = cmp.mapping.complete(),
|
||||||
["<C-e>"] = cmp.mapping({
|
["<C-e>"] = cmp.mapping({
|
||||||
i = cmp.mapping.abort(),
|
i = cmp.mapping.abort(),
|
||||||
c = cmp.mapping.close(),
|
c = cmp.mapping.close(),
|
||||||
}),
|
}),
|
||||||
-- Accept currently selected item. If none selected, `select` first item.
|
-- Accept currently selected item. If none selected, `select` first item.
|
||||||
-- Set `select` to `false` to only confirm explicitly selected items.
|
-- Set `select` to `false` to only confirm explicitly selected items.
|
||||||
["<CR>"] = cmp.mapping.confirm({ select = true }),
|
["<cr>"] = cmp.mapping.confirm({ select = true }),
|
||||||
["<Tab>"] = cmp.mapping(function(fallback)
|
},
|
||||||
if cmp.visible() then
|
sources = {
|
||||||
cmp.select_next_item()
|
{ name = "gh_issues" },
|
||||||
elseif luasnip.expandable() then
|
{ name = "nvim_lua" },
|
||||||
luasnip.expand()
|
{ name = "nvim_lsp" },
|
||||||
elseif luasnip.expand_or_jumpable() then
|
{ name = "path" },
|
||||||
luasnip.expand_or_jump()
|
{ name = "luasnip" },
|
||||||
elseif check_backspace() then
|
{ name = "buffer", keyword_length = 5 },
|
||||||
fallback()
|
},
|
||||||
else
|
snippet = {
|
||||||
fallback()
|
expand = function(args)
|
||||||
end
|
luasnip.lsp_expand(args.body)
|
||||||
end, {
|
end,
|
||||||
"i",
|
},
|
||||||
"s",
|
|
||||||
}),
|
|
||||||
["<S-Tab>"] = cmp.mapping(function(fallback)
|
|
||||||
if cmp.visible() then
|
|
||||||
cmp.select_prev_item()
|
|
||||||
elseif luasnip.jumpable(-1) then
|
|
||||||
luasnip.jump(-1)
|
|
||||||
else
|
|
||||||
fallback()
|
|
||||||
end
|
|
||||||
end, {
|
|
||||||
"i",
|
|
||||||
"s",
|
|
||||||
}),
|
|
||||||
}),
|
|
||||||
formatting = {
|
formatting = {
|
||||||
fields = { "kind", "abbr", "menu" },
|
fields = { "kind", "abbr", "menu" },
|
||||||
format = function(entry, vim_item)
|
format = function(entry, vim_item)
|
||||||
vim_item.kind = kind_icons[vim_item.kind]
|
vim_item.kind = kind_icons[vim_item.kind]
|
||||||
vim_item.menu = ({
|
vim_item.menu = ({
|
||||||
nvim_lsp = "",
|
nvim_lsp = "[LSP]",
|
||||||
nvim_lua = "",
|
nvim_lua = "[api]",
|
||||||
luasnip = "",
|
luasnip = "[snip]",
|
||||||
buffer = "",
|
buffer = "[buf]",
|
||||||
path = "",
|
path = "[path]",
|
||||||
emoji = "",
|
emoji = "[emoji]",
|
||||||
|
gh_issues = "[issues]",
|
||||||
})[entry.source.name]
|
})[entry.source.name]
|
||||||
return vim_item
|
return vim_item
|
||||||
end,
|
end,
|
||||||
},
|
},
|
||||||
sources = {
|
experimental = {
|
||||||
{ name = "nvim_lsp" },
|
ghost_text = true,
|
||||||
{ name = "nvim_lua" },
|
native_menu = false,
|
||||||
{ name = "luasnip" },
|
|
||||||
{ name = "buffer" },
|
|
||||||
{ name = "path" },
|
|
||||||
},
|
|
||||||
confirm_opts = {
|
|
||||||
behavior = cmp.ConfirmBehavior.Replace,
|
|
||||||
select = false,
|
|
||||||
},
|
},
|
||||||
window = {
|
window = {
|
||||||
completion = cmp.config.window.bordered(),
|
completion = cmp.config.window.bordered(),
|
||||||
documentation = cmp.config.window.bordered(),
|
documentation = cmp.config.window.bordered(),
|
||||||
},
|
},
|
||||||
experimental = {
|
confirm_opts = {
|
||||||
ghost_text = true,
|
behavior = cmp.ConfirmBehavior.Replace,
|
||||||
|
select = false,
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user