style(nvim): reformat
This commit is contained in:
parent
c3af4d4516
commit
a556a6e50a
@ -8,184 +8,183 @@ local luasnip = require("luasnip")
|
|||||||
require("luasnip.loaders.from_vscode").lazy_load()
|
require("luasnip.loaders.from_vscode").lazy_load()
|
||||||
|
|
||||||
cmp.setup({
|
cmp.setup({
|
||||||
formatting = {
|
formatting = {
|
||||||
|
|
||||||
fields = { cmp.ItemField.Kind, cmp.ItemField.Abbr, cmp.ItemField.Menu },
|
fields = { cmp.ItemField.Kind, cmp.ItemField.Abbr, cmp.ItemField.Menu },
|
||||||
format = function(entry, vim_item)
|
format = function(entry, vim_item)
|
||||||
local selections = {
|
local selections = {
|
||||||
fuzzy_buffer = { symbol = " ", name = "Buffer", hl_group = "Buffer" },
|
fuzzy_buffer = { symbol = " ", name = "Buffer", hl_group = "Buffer" },
|
||||||
path = { symbol = " ", name = "Path", hl_group = "Path" },
|
path = { symbol = " ", name = "Path", hl_group = "Path" },
|
||||||
calc = { symbol = " ", name = "Calculator", hl_group = "Calculator" },
|
calc = { symbol = " ", name = "Calculator", hl_group = "Calculator" },
|
||||||
neorg = { symbol = " ", name = "Neorg", hl_group = "Neorg" },
|
neorg = { symbol = " ", name = "Neorg", hl_group = "Neorg" },
|
||||||
emoji = { symbol = "ﲃ ", name = "Emoji", hl_group = "Emoji" },
|
emoji = { symbol = "ﲃ ", name = "Emoji", hl_group = "Emoji" },
|
||||||
zsh = { symbol = " ", name = "Zsh", hl_group = "Zsh" },
|
zsh = { symbol = " ", name = "Zsh", hl_group = "Zsh" },
|
||||||
crates = { symbol = " ", name = "Crates", hl_group = "Crates" },
|
crates = { symbol = " ", name = "Crates", hl_group = "Crates" },
|
||||||
cmdline_history = { symbol = " ", name = "Cmd History", hl_group = "CmdHistory" },
|
cmdline_history = { symbol = " ", name = "Cmd History", hl_group = "CmdHistory" },
|
||||||
rg = { symbol = " ", name = "Ripgrep", hl_group = "Ripgrep" },
|
rg = { symbol = " ", name = "Ripgrep", hl_group = "Ripgrep" },
|
||||||
npm = { symbol = " ", name = "Npm,", hl_group = "Npm," },
|
npm = { symbol = " ", name = "Npm,", hl_group = "Npm," },
|
||||||
conventionalcommits = { symbol = " ", name = "Commit", hl_group = "Commit" },
|
conventionalcommits = { symbol = " ", name = "Commit", hl_group = "Commit" },
|
||||||
spell = { symbol = " ", name = "Spell", hl_group = "Spell" },
|
spell = { symbol = " ", name = "Spell", hl_group = "Spell" },
|
||||||
}
|
}
|
||||||
|
|
||||||
local selection = selections[entry.source.name]
|
local selection = selections[entry.source.name]
|
||||||
if not selection then
|
if not selection then
|
||||||
local kind = require("lspkind").cmp_format({
|
local kind = require("lspkind").cmp_format({
|
||||||
mode = "symbol_text",
|
mode = "symbol_text",
|
||||||
maxwidth = 50,
|
maxwidth = 50,
|
||||||
})(entry, vim_item)
|
})(entry, vim_item)
|
||||||
local strings = vim.split(kind.kind, "%s", { trimempty = true })
|
local strings = vim.split(kind.kind, "%s", { trimempty = true })
|
||||||
kind.kind = " " .. strings[1] .. " "
|
kind.kind = " " .. strings[1] .. " "
|
||||||
vim_item.menu = strings[1] .. " " .. strings[2]
|
vim_item.menu = strings[1] .. " " .. strings[2]
|
||||||
return kind
|
return kind
|
||||||
else
|
else
|
||||||
local word = entry:get_insert_text()
|
local word = entry:get_insert_text()
|
||||||
if entry.completion_item.insertTextFormat == types.lsp.InsertTextFormat.Snippet then
|
if entry.completion_item.insertTextFormat == types.lsp.InsertTextFormat.Snippet then
|
||||||
word = vim.lsp.util.parse_snippet(word)
|
word = vim.lsp.util.parse_snippet(word)
|
||||||
end
|
end
|
||||||
word = str.oneline(word)
|
word = str.oneline(word)
|
||||||
|
|
||||||
-- concatenates the string
|
-- concatenates the string
|
||||||
local max = 50
|
local max = 50
|
||||||
if string.len(word) >= max then
|
if string.len(word) >= max then
|
||||||
local before = string.sub(word, 1, math.floor((max - 3) / 2))
|
local before = string.sub(word, 1, math.floor((max - 3) / 2))
|
||||||
word = before .. "..."
|
word = before .. "..."
|
||||||
end
|
end
|
||||||
vim_item.kind = " " .. selection.symbol
|
vim_item.kind = " " .. selection.symbol
|
||||||
vim_item.menu = selection.symbol .. selection.name
|
vim_item.menu = selection.symbol .. selection.name
|
||||||
vim_item.kind_hl_group = "CmpCustomSelection" .. selection.hl_group
|
vim_item.kind_hl_group = "CmpCustomSelection" .. selection.hl_group
|
||||||
vim_item.abbr = word
|
vim_item.abbr = word
|
||||||
return vim_item
|
return vim_item
|
||||||
end
|
end
|
||||||
end,
|
end,
|
||||||
|
},
|
||||||
|
view = {
|
||||||
|
entries = {
|
||||||
|
name = "custom",
|
||||||
|
selection_order = "near_cursor",
|
||||||
},
|
},
|
||||||
view = {
|
},
|
||||||
entries = {
|
window = {
|
||||||
name = "custom",
|
documentation = { side_padding = 0 },
|
||||||
selection_order = "near_cursor",
|
completion = {
|
||||||
},
|
winhighlight = "Normal:Pmenu,FloatBorder:Pmenu,Search:None",
|
||||||
|
col_offset = -3,
|
||||||
|
side_padding = 0,
|
||||||
},
|
},
|
||||||
window = {
|
},
|
||||||
documentation = { side_padding = 0 },
|
experimental = { ghost_text = true, native_menu = false },
|
||||||
completion = {
|
snippet = {
|
||||||
winhighlight = "Normal:Pmenu,FloatBorder:Pmenu,Search:None",
|
-- REQUIRED - you must specify a snippet engine
|
||||||
col_offset = -3,
|
expand = function(args)
|
||||||
side_padding = 0,
|
require("luasnip").lsp_expand(args.body) -- For `luasnip` users.
|
||||||
},
|
end,
|
||||||
},
|
},
|
||||||
experimental = { ghost_text = true, native_menu = false },
|
mapping = {
|
||||||
snippet = {
|
["<C-b>"] = cmp.mapping(cmp.mapping.scroll_docs(-4), { "i", "c" }),
|
||||||
-- REQUIRED - you must specify a snippet engine
|
["<C-f>"] = cmp.mapping(cmp.mapping.scroll_docs(4), { "i", "c" }),
|
||||||
expand = function(args)
|
["<C-Space>"] = cmp.mapping(cmp.mapping.complete(), { "i", "c" }),
|
||||||
require("luasnip").lsp_expand(args.body) -- For `luasnip` users.
|
["<C-y>"] = cmp.config.disable, -- Specify `cmp.config.disable` if you want to remove the default `<C-y>` mapping.
|
||||||
end,
|
["<C-e>"] = cmp.mapping({
|
||||||
},
|
i = cmp.mapping.abort(),
|
||||||
mapping = {
|
c = cmp.mapping.close(),
|
||||||
["<C-b>"] = cmp.mapping(cmp.mapping.scroll_docs(-4), { "i", "c" }),
|
|
||||||
["<C-f>"] = cmp.mapping(cmp.mapping.scroll_docs(4), { "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(),
|
|
||||||
}),
|
|
||||||
["<CR>"] = cmp.mapping.confirm({ select = false }), -- Accept currently selected item. Set `select` to `false` to only confirm explicitly selected items.
|
|
||||||
["<C-Tab>"] = cmp.mapping(function(fallback)
|
|
||||||
if luasnip.expand_or_jumpable() then
|
|
||||||
luasnip.expand_or_jump()
|
|
||||||
else
|
|
||||||
fallback()
|
|
||||||
end
|
|
||||||
end, { "i", "s" }),
|
|
||||||
["<C-S-Tab>"] = cmp.mapping(function(fallback)
|
|
||||||
if luasnip.jumpable(-1) then
|
|
||||||
luasnip.jump(-1)
|
|
||||||
else
|
|
||||||
fallback()
|
|
||||||
end
|
|
||||||
end, { "i", "s" }),
|
|
||||||
["<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()
|
|
||||||
elseif luasnip.jumpable(-1) then
|
|
||||||
luasnip.jump(-1)
|
|
||||||
else
|
|
||||||
fallback()
|
|
||||||
end
|
|
||||||
end, { "i", "s" }),
|
|
||||||
},
|
|
||||||
sources = cmp.config.sources({
|
|
||||||
{ name = "nvim_lsp", priority = 11 },
|
|
||||||
{ name = "luasnip", priority = 10 }, -- For luasnip users.
|
|
||||||
{ name = "fuzzy_buffer", priority = 9, keyword_length = 3, max_item_count = 10 },
|
|
||||||
{ name = "buffer-lines", priority = 8, max_item_count = 10 },
|
|
||||||
{
|
|
||||||
name = "rg",
|
|
||||||
priority = 7,
|
|
||||||
keyword_length = 3,
|
|
||||||
max_item_count = 10,
|
|
||||||
},
|
|
||||||
{ name = "path", priority = 6 },
|
|
||||||
{ name = "zsh", priority = 5 },
|
|
||||||
{ name = "emoji", keyword_length = 2 },
|
|
||||||
{ name = "neorg" },
|
|
||||||
{ name = "calc" },
|
|
||||||
{ name = "npm", keyword_length = 2 },
|
|
||||||
{ name = "spell", keyword_length = 2 },
|
|
||||||
}),
|
}),
|
||||||
sorting = {
|
["<CR>"] = cmp.mapping.confirm({ select = false }), -- Accept currently selected item. Set `select` to `false` to only confirm explicitly selected items.
|
||||||
comparators = {
|
["<C-Tab>"] = cmp.mapping(function(fallback)
|
||||||
compare.score,
|
if luasnip.expand_or_jumpable() then
|
||||||
compare.offset,
|
luasnip.expand_or_jump()
|
||||||
compare.recently_used,
|
else
|
||||||
compare.exact,
|
fallback()
|
||||||
require("cmp_fuzzy_buffer.compare"),
|
end
|
||||||
compare.kind,
|
end, { "i", "s" }),
|
||||||
compare.sort_text,
|
["<C-S-Tab>"] = cmp.mapping(function(fallback)
|
||||||
compare.length,
|
if luasnip.jumpable(-1) then
|
||||||
compare.order,
|
luasnip.jump(-1)
|
||||||
},
|
else
|
||||||
|
fallback()
|
||||||
|
end
|
||||||
|
end, { "i", "s" }),
|
||||||
|
["<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()
|
||||||
|
elseif luasnip.jumpable(-1) then
|
||||||
|
luasnip.jump(-1)
|
||||||
|
else
|
||||||
|
fallback()
|
||||||
|
end
|
||||||
|
end, { "i", "s" }),
|
||||||
|
},
|
||||||
|
sources = cmp.config.sources({
|
||||||
|
{ name = "nvim_lsp", priority = 11 },
|
||||||
|
{ name = "luasnip", priority = 10 }, -- For luasnip users.
|
||||||
|
{ name = "fuzzy_buffer", priority = 9, keyword_length = 3, max_item_count = 10 },
|
||||||
|
{
|
||||||
|
name = "rg",
|
||||||
|
priority = 7,
|
||||||
|
keyword_length = 3,
|
||||||
|
max_item_count = 10,
|
||||||
},
|
},
|
||||||
|
{ name = "path", priority = 6 },
|
||||||
|
{ name = "zsh", priority = 5 },
|
||||||
|
{ name = "emoji", keyword_length = 2 },
|
||||||
|
{ name = "neorg" },
|
||||||
|
{ name = "calc" },
|
||||||
|
{ name = "npm", keyword_length = 2 },
|
||||||
|
{ name = "spell", keyword_length = 2 },
|
||||||
|
}),
|
||||||
|
sorting = {
|
||||||
|
comparators = {
|
||||||
|
compare.score,
|
||||||
|
compare.offset,
|
||||||
|
compare.recently_used,
|
||||||
|
compare.exact,
|
||||||
|
require("cmp_fuzzy_buffer.compare"),
|
||||||
|
compare.kind,
|
||||||
|
compare.sort_text,
|
||||||
|
compare.length,
|
||||||
|
compare.order,
|
||||||
|
},
|
||||||
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
-- Git Commit Completions
|
-- Git Commit Completions
|
||||||
cmp.setup.filetype("gitcommit", {
|
cmp.setup.filetype("gitcommit", {
|
||||||
sources = cmp.config.sources({ { name = "conventionalcommits", priority = 20 } }),
|
sources = cmp.config.sources({ { name = "conventionalcommits", priority = 20 } }),
|
||||||
})
|
})
|
||||||
|
|
||||||
cmp.setup.filetype("toml", { sources = cmp.config.sources({ { name = "crates" } }) })
|
cmp.setup.filetype("toml", { sources = cmp.config.sources({ { name = "crates" } }) })
|
||||||
|
|
||||||
-- Use buffer source for `/` (if you enabled `native_menu`, this won't work anymore).
|
-- Use buffer source for `/` (if you enabled `native_menu`, this won't work anymore).
|
||||||
cmp.setup.cmdline("/", {
|
cmp.setup.cmdline("/", {
|
||||||
mapping = cmp.mapping.preset.cmdline(),
|
mapping = cmp.mapping.preset.cmdline(),
|
||||||
sources = cmp.config.sources({ { name = "fuzzy_buffer" } }),
|
sources = cmp.config.sources({ { name = "fuzzy_buffer" } }),
|
||||||
})
|
})
|
||||||
|
|
||||||
cmp.setup.cmdline("?", {
|
cmp.setup.cmdline("?", {
|
||||||
mapping = cmp.mapping.preset.cmdline(),
|
mapping = cmp.mapping.preset.cmdline(),
|
||||||
sources = cmp.config.sources({ { name = "fuzzy_buffer" } }),
|
sources = cmp.config.sources({ { name = "fuzzy_buffer" } }),
|
||||||
})
|
})
|
||||||
|
|
||||||
cmp.setup.cmdline("@", {
|
cmp.setup.cmdline("@", {
|
||||||
mapping = cmp.mapping.preset.cmdline(),
|
mapping = cmp.mapping.preset.cmdline(),
|
||||||
sources = cmp.config.sources({
|
sources = cmp.config.sources({
|
||||||
{ name = "fuzzy_buffer" },
|
{ name = "fuzzy_buffer" },
|
||||||
{ name = "cmdline_history" },
|
{ name = "cmdline_history" },
|
||||||
}),
|
}),
|
||||||
})
|
})
|
||||||
|
|
||||||
-- Use cmdline & path source for ':' (if you enabled `native_menu`, this won't work anymore).
|
-- Use cmdline & path source for ':' (if you enabled `native_menu`, this won't work anymore).
|
||||||
cmp.setup.cmdline(":", {
|
cmp.setup.cmdline(":", {
|
||||||
mapping = cmp.mapping.preset.cmdline(),
|
mapping = cmp.mapping.preset.cmdline(),
|
||||||
sources = cmp.config.sources({
|
sources = cmp.config.sources({
|
||||||
{ name = "path" },
|
{ name = "path" },
|
||||||
{ name = "cmdline" },
|
{ name = "cmdline" },
|
||||||
{ name = "cmdline_history" },
|
{ name = "cmdline_history" },
|
||||||
}),
|
}),
|
||||||
})
|
})
|
||||||
|
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user