initial commit
This commit is contained in:
127
lua/plugins/cmp.lua
Normal file
127
lua/plugins/cmp.lua
Normal file
@ -0,0 +1,127 @@
|
||||
-- To use mini icons with blink.cmp
|
||||
local function get_mini_icon(ctx)
|
||||
if ctx.source_name == "Path" then
|
||||
local is_unknown_type = vim.tbl_contains(
|
||||
{ "link", "socket", "fifo", "char", "block", "unknown" },
|
||||
ctx.item.data.type
|
||||
)
|
||||
local mini_icon, mini_hl, _ = require("mini.icons").get(
|
||||
is_unknown_type and "os" or ctx.item.data.type,
|
||||
is_unknown_type and "" or ctx.label
|
||||
)
|
||||
if mini_icon then
|
||||
return mini_icon, mini_hl
|
||||
end
|
||||
end
|
||||
local mini_icon, mini_hl, _ = require("mini.icons").get("lsp", ctx.kind)
|
||||
return mini_icon, mini_hl
|
||||
end
|
||||
|
||||
vim.api.nvim_create_autocmd('PackChanged', {
|
||||
callback = function(ev)
|
||||
print("mqsidjfmqoisdfj")
|
||||
if ev.data.spec.name == 'blink.cmp' then
|
||||
local res = vim.system({ 'cargo', 'build', '--release' }, { cwd = ev.data.path })
|
||||
if vim.v.shell_error ~= 0 then
|
||||
vim.notify('Failed to compile blink.cmp: ' .. res, vim.log.levels.ERROR)
|
||||
else
|
||||
vim.notify('Successfully compiled blink.cmp', vim.log.levels.INFO)
|
||||
end
|
||||
end
|
||||
end,
|
||||
})
|
||||
|
||||
vim.pack.add({
|
||||
"https://github.com/xzbdmw/colorful-menu.nvim",
|
||||
{ src = "https://github.com/saghen/blink.cmp", verion = vim.version.range("1.x") },
|
||||
})
|
||||
|
||||
-- You don't need to set these options.
|
||||
require("colorful-menu").setup({
|
||||
ls = {
|
||||
["rust-analyzer"] = {
|
||||
-- Such as (as Iterator), (use std::io).
|
||||
extra_info_hl = "@comment",
|
||||
-- Similar to the same setting of gopls.
|
||||
align_type_to_right = true,
|
||||
-- See https://github.com/xzbdmw/colorful-menu.nvim/pull/36
|
||||
preserve_type_when_truncate = true,
|
||||
},
|
||||
clangd = {
|
||||
-- Such as "From <stdio.h>".
|
||||
extra_info_hl = "@comment",
|
||||
-- Similar to the same setting of gopls.
|
||||
align_type_to_right = true,
|
||||
-- the hl group of leading dot of "•std::filesystem::permissions(..)"
|
||||
import_dot_hl = "@comment",
|
||||
-- See https://github.com/xzbdmw/colorful-menu.nvim/pull/36
|
||||
preserve_type_when_truncate = true,
|
||||
},
|
||||
-- If true, try to highlight "not supported" languages.
|
||||
fallback = true,
|
||||
-- this will be applied to label description for unsupport languages
|
||||
fallback_extra_info_hl = "@comment",
|
||||
},
|
||||
-- If the built-in logic fails to find a suitable highlight group for a label,
|
||||
-- this highlight is applied to the label.
|
||||
fallback_highlight = "@variable",
|
||||
-- If provided, the plugin truncates the final displayed text to
|
||||
-- this width (measured in display cells). Any highlights that extend
|
||||
-- beyond the truncation point are ignored. When set to a float
|
||||
-- between 0 and 1, it'll be treated as percentage of the width of
|
||||
-- the window: math.floor(max_width * vim.api.nvim_win_get_width(0))
|
||||
-- Default 60.
|
||||
max_width = 60,
|
||||
})
|
||||
|
||||
vim.api.nvim_set_hl(0, "BlinkCmpMenu", { link = "NormalFloat" })
|
||||
vim.api.nvim_set_hl(0, "BlinkCmpMenuBorder", { link = "FloatBorder" })
|
||||
vim.api.nvim_set_hl(0, "BlinkCmpDoc", { link = "NormalFloat" })
|
||||
vim.api.nvim_set_hl(0, "BlinkCmpDocBorder", { link = "FloatBorder" })
|
||||
|
||||
require("blink.cmp").setup({
|
||||
keymap = { preset = "super-tab" },
|
||||
signature = { enabled = true },
|
||||
sources = {
|
||||
default = { "lsp", "path", "buffer" },
|
||||
},
|
||||
|
||||
completion = {
|
||||
documentation = { auto_show = false },
|
||||
menu = {
|
||||
-- border = "single",
|
||||
draw = {
|
||||
-- We don't need label_description now because label and label_description are already
|
||||
-- combined together in label by colorful-menu.nvim.
|
||||
columns = { { "kind_icon" }, { "label", gap = 1 } },
|
||||
components = {
|
||||
label = {
|
||||
text = function(ctx)
|
||||
return require("colorful-menu").blink_components_text(ctx)
|
||||
end,
|
||||
highlight = function(ctx)
|
||||
return require("colorful-menu").blink_components_highlight(ctx)
|
||||
end,
|
||||
},
|
||||
kind_icon = {
|
||||
text = function(ctx)
|
||||
local mini_icon, _mini_hl = get_mini_icon(ctx)
|
||||
return mini_icon
|
||||
end,
|
||||
highlight = function(ctx)
|
||||
local _mini_icon, mini_hl = get_mini_icon(ctx)
|
||||
return mini_hl
|
||||
end,
|
||||
},
|
||||
kind = {
|
||||
-- (optional) use highlights from mini.icons
|
||||
highlight = function(ctx)
|
||||
local _mini_icon, mini_hl = get_mini_icon(ctx)
|
||||
return mini_hl
|
||||
end,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
})
|
||||
Reference in New Issue
Block a user