mirror of
https://github.com/LazyVim/LazyVim.git
synced 2025-06-22 17:03:39 +02:00
refactor: cmp
This commit is contained in:
parent
0d57115f01
commit
e2972f0cca
2 changed files with 34 additions and 32 deletions
|
@ -23,19 +23,19 @@ return {
|
||||||
vim.api.nvim_set_hl(0, "CmpGhostText", { link = "Comment", default = true })
|
vim.api.nvim_set_hl(0, "CmpGhostText", { link = "Comment", default = true })
|
||||||
local cmp = require("cmp")
|
local cmp = require("cmp")
|
||||||
local defaults = require("cmp.config.default")()
|
local defaults = require("cmp.config.default")()
|
||||||
|
local auto_select = true
|
||||||
return {
|
return {
|
||||||
auto_brackets = {}, -- configure any filetype to auto add brackets
|
auto_brackets = {}, -- configure any filetype to auto add brackets
|
||||||
completion = {
|
completion = {
|
||||||
completeopt = "menu,menuone,noinsert",
|
completeopt = "menu,menuone,noinsert" .. (auto_select and "" or ",noselect"),
|
||||||
},
|
},
|
||||||
|
preselect = auto_select and cmp.PreselectMode.Item or cmp.PreselectMode.None,
|
||||||
mapping = cmp.mapping.preset.insert({
|
mapping = cmp.mapping.preset.insert({
|
||||||
["<C-n>"] = cmp.mapping.select_next_item({ behavior = cmp.SelectBehavior.Insert }),
|
|
||||||
["<C-p>"] = cmp.mapping.select_prev_item({ behavior = cmp.SelectBehavior.Insert }),
|
|
||||||
["<C-b>"] = cmp.mapping.scroll_docs(-4),
|
["<C-b>"] = cmp.mapping.scroll_docs(-4),
|
||||||
["<C-f>"] = cmp.mapping.scroll_docs(4),
|
["<C-f>"] = cmp.mapping.scroll_docs(4),
|
||||||
["<C-Space>"] = cmp.mapping.complete(),
|
["<C-Space>"] = cmp.mapping.complete(),
|
||||||
["<C-e>"] = cmp.mapping.abort(),
|
["<CR>"] = LazyVim.cmp.confirm({ select = auto_select }),
|
||||||
["<CR>"] = LazyVim.cmp.confirm(),
|
["<C-y>"] = LazyVim.cmp.confirm({ select = true }),
|
||||||
["<S-CR>"] = LazyVim.cmp.confirm({ behavior = cmp.ConfirmBehavior.Replace }), -- Accept currently selected item. Set `select` to `false` to only confirm explicitly selected items.
|
["<S-CR>"] = LazyVim.cmp.confirm({ behavior = cmp.ConfirmBehavior.Replace }), -- Accept currently selected item. Set `select` to `false` to only confirm explicitly selected items.
|
||||||
["<C-CR>"] = function(fallback)
|
["<C-CR>"] = function(fallback)
|
||||||
cmp.abort()
|
cmp.abort()
|
||||||
|
@ -50,7 +50,7 @@ return {
|
||||||
}),
|
}),
|
||||||
formatting = {
|
formatting = {
|
||||||
format = function(_, item)
|
format = function(_, item)
|
||||||
local icons = require("lazyvim.config").icons.kinds
|
local icons = LazyVim.config.icons.kinds
|
||||||
if icons[item.kind] then
|
if icons[item.kind] then
|
||||||
item.kind = icons[item.kind] .. item.kind
|
item.kind = icons[item.kind] .. item.kind
|
||||||
end
|
end
|
||||||
|
@ -65,32 +65,7 @@ return {
|
||||||
sorting = defaults.sorting,
|
sorting = defaults.sorting,
|
||||||
}
|
}
|
||||||
end,
|
end,
|
||||||
---@param opts cmp.ConfigSchema | {auto_brackets?: string[]}
|
main = "lazyvim.util.cmp",
|
||||||
config = function(_, opts)
|
|
||||||
for _, source in ipairs(opts.sources) do
|
|
||||||
source.group_index = source.group_index or 1
|
|
||||||
end
|
|
||||||
|
|
||||||
local parse = require("cmp.utils.snippet").parse
|
|
||||||
require("cmp.utils.snippet").parse = function(input)
|
|
||||||
local ok, ret = pcall(parse, input)
|
|
||||||
if ok then
|
|
||||||
return ret
|
|
||||||
end
|
|
||||||
return LazyVim.cmp.snippet_preview(input)
|
|
||||||
end
|
|
||||||
|
|
||||||
local cmp = require("cmp")
|
|
||||||
cmp.setup(opts)
|
|
||||||
cmp.event:on("confirm_done", function(event)
|
|
||||||
if vim.tbl_contains(opts.auto_brackets or {}, vim.bo.filetype) then
|
|
||||||
LazyVim.cmp.auto_brackets(event.entry)
|
|
||||||
end
|
|
||||||
end)
|
|
||||||
cmp.event:on("menu_opened", function(event)
|
|
||||||
LazyVim.cmp.add_missing_snippet_docs(event.window)
|
|
||||||
end)
|
|
||||||
end,
|
|
||||||
},
|
},
|
||||||
|
|
||||||
-- snippets
|
-- snippets
|
||||||
|
|
|
@ -128,4 +128,31 @@ function M.expand(snippet)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
---@param opts cmp.ConfigSchema | {auto_brackets?: string[]}
|
||||||
|
function M.setup(opts)
|
||||||
|
for _, source in ipairs(opts.sources) do
|
||||||
|
source.group_index = source.group_index or 1
|
||||||
|
end
|
||||||
|
|
||||||
|
local parse = require("cmp.utils.snippet").parse
|
||||||
|
require("cmp.utils.snippet").parse = function(input)
|
||||||
|
local ok, ret = pcall(parse, input)
|
||||||
|
if ok then
|
||||||
|
return ret
|
||||||
|
end
|
||||||
|
return LazyVim.cmp.snippet_preview(input)
|
||||||
|
end
|
||||||
|
|
||||||
|
local cmp = require("cmp")
|
||||||
|
cmp.setup(opts)
|
||||||
|
cmp.event:on("confirm_done", function(event)
|
||||||
|
if vim.tbl_contains(opts.auto_brackets or {}, vim.bo.filetype) then
|
||||||
|
LazyVim.cmp.auto_brackets(event.entry)
|
||||||
|
end
|
||||||
|
end)
|
||||||
|
cmp.event:on("menu_opened", function(event)
|
||||||
|
LazyVim.cmp.add_missing_snippet_docs(event.window)
|
||||||
|
end)
|
||||||
|
end
|
||||||
|
|
||||||
return M
|
return M
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue