feat(lazy): allow for hot loading plugin specs
This commit is contained in:
+104
-93
@@ -24,101 +24,112 @@ local function has_words_after()
|
||||
~= nil
|
||||
end
|
||||
|
||||
local function setup()
|
||||
local utils = require("utils")
|
||||
local cmp = require("cmp")
|
||||
local luasnip = require("luasnip")
|
||||
local lspkind = utils.try_require("lspkind")
|
||||
|
||||
local opt = {
|
||||
preselect = cmp.PreselectMode.None,
|
||||
completion = { keyword_length = 0 },
|
||||
snippet = {
|
||||
expand = function(args)
|
||||
luasnip.lsp_expand(args.body)
|
||||
---@type LazyPluginSpec
|
||||
return {
|
||||
"hrsh7th/nvim-cmp",
|
||||
dependencies = {
|
||||
"saadparwaiz1/cmp_luasnip",
|
||||
"hrsh7th/cmp-path",
|
||||
"hrsh7th/cmp-cmdline",
|
||||
"hrsh7th/cmp-nvim-lsp",
|
||||
{
|
||||
"L3MON4D3/LuaSnip",
|
||||
config = function()
|
||||
require("luasnip.loaders.from_vscode").lazy_load()
|
||||
end,
|
||||
build = (require("utils").os_name ~= "Windows_NT" and "make install_jsregexp" or nil),
|
||||
version = "2.*",
|
||||
},
|
||||
formatting = {
|
||||
format = function(entry, vim_item)
|
||||
if lspkind then
|
||||
vim_item = lspkind.cmp_format({
|
||||
mode = "symbol",
|
||||
maxwidth = 50,
|
||||
ellipsis_char = "...",
|
||||
before = function(_, item)
|
||||
item.dup = 0 -- remove duplicates, see nvim-cmp #511
|
||||
return item
|
||||
end,
|
||||
})(entry, vim_item)
|
||||
end
|
||||
},
|
||||
config = function()
|
||||
local cmp = require("cmp")
|
||||
local luasnip = require("luasnip")
|
||||
local utils = require("utils")
|
||||
local lspkind = utils.try_require("lspkind")
|
||||
|
||||
return vim_item
|
||||
end,
|
||||
},
|
||||
mapping = {
|
||||
["<C-p>"] = cmp.mapping.select_prev_item({
|
||||
behavior = cmp.SelectBehavior.Select,
|
||||
}),
|
||||
["<C-n>"] = cmp.mapping.select_next_item({
|
||||
behavior = cmp.SelectBehavior.Select,
|
||||
}),
|
||||
["<C-y>"] = function(fallback)
|
||||
if cmp.visible() then
|
||||
cmp.confirm({ behavior = cmp.ConfirmBehavior.Replace })
|
||||
else
|
||||
fallback()
|
||||
end
|
||||
end,
|
||||
["<C-x><C-o>"] = cmp.mapping.complete(),
|
||||
["<C-l>"] = function(fallback)
|
||||
if luasnip.expand_or_locally_jumpable() then
|
||||
luasnip.expand_or_jump()
|
||||
else
|
||||
fallback()
|
||||
end
|
||||
end,
|
||||
["<C-h>"] = function(fallback)
|
||||
if luasnip.locally_jumpable(-1) then
|
||||
luasnip.jump(-1)
|
||||
else
|
||||
fallback()
|
||||
end
|
||||
end,
|
||||
},
|
||||
sources = {
|
||||
{ name = "nvim_lsp" },
|
||||
-- { name = "luasnip", },
|
||||
{ name = "orgmode" },
|
||||
{ name = "path" },
|
||||
},
|
||||
}
|
||||
|
||||
if utils.try_require("moonfly") then
|
||||
local winhighlight = {
|
||||
winhighlight = "Normal:NormalFloat,FloatBorder:FloatBorder,CursorLine:PmenuSel",
|
||||
}
|
||||
opt.window = {
|
||||
completion = cmp.config.window.bordered(winhighlight),
|
||||
documentation = cmp.config.window.bordered(winhighlight),
|
||||
}
|
||||
end
|
||||
|
||||
cmp.setup(opt)
|
||||
|
||||
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",
|
||||
option = { ignore_cmds = { "Man", "!" } },
|
||||
local opts = {
|
||||
preselect = cmp.PreselectMode.None,
|
||||
completion = {
|
||||
autocomplete = { "InsertEnter", "TextChanged" },
|
||||
keyword_length = 1,
|
||||
},
|
||||
}),
|
||||
})
|
||||
end
|
||||
snippet = {
|
||||
expand = function(args)
|
||||
luasnip.lsp_expand(args.body)
|
||||
end,
|
||||
},
|
||||
formatting = {
|
||||
format = function(entry, vim_item)
|
||||
if lspkind then
|
||||
vim_item = lspkind.cmp_format({
|
||||
mode = "symbol",
|
||||
maxwidth = 50,
|
||||
ellipsis_char = "...",
|
||||
before = function(_, item)
|
||||
item.dup = 0 -- remove duplicates, see nvim-cmp #511
|
||||
return item
|
||||
end,
|
||||
})(entry, vim_item)
|
||||
end
|
||||
|
||||
return setup
|
||||
return vim_item
|
||||
end,
|
||||
},
|
||||
|
||||
mapping = {
|
||||
["<S-tab>"] = cmp.mapping.select_prev_item({
|
||||
behavior = cmp.SelectBehavior.Insert,
|
||||
}),
|
||||
["<tab>"] = cmp.mapping.select_next_item({
|
||||
behavior = cmp.SelectBehavior.Insert,
|
||||
}),
|
||||
["<C-x><C-o>"] = cmp.mapping.complete(),
|
||||
["<C-l>"] = function(fallback)
|
||||
if luasnip.expand_or_locally_jumpable() then
|
||||
luasnip.expand_or_jump()
|
||||
else
|
||||
fallback()
|
||||
end
|
||||
end,
|
||||
["<C-h>"] = function(fallback)
|
||||
if luasnip.locally_jumpable(-1) then
|
||||
luasnip.jump(-1)
|
||||
else
|
||||
fallback()
|
||||
end
|
||||
end,
|
||||
},
|
||||
sources = {
|
||||
{ name = "nvim_lsp" },
|
||||
-- { name = "luasnip", },
|
||||
{ name = "orgmode" },
|
||||
{ name = "path" },
|
||||
},
|
||||
}
|
||||
|
||||
if utils.try_require("moonfly") then
|
||||
local winhighlight = {
|
||||
winhighlight = "Normal:NormalFloat,FloatBorder:FloatBorder,CursorLine:PmenuSel",
|
||||
}
|
||||
opts.window = {
|
||||
completion = cmp.config.window.bordered(winhighlight),
|
||||
documentation = cmp.config.window.bordered(winhighlight),
|
||||
}
|
||||
end
|
||||
|
||||
cmp.setup(opts)
|
||||
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",
|
||||
option = { ignore_cmds = { "Man", "!" } },
|
||||
},
|
||||
}),
|
||||
})
|
||||
end,
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user