Skip to content

Commit

Permalink
feat(ui)!: unify UI components: cmp, wilder, floats (ayamir#772)
Browse files Browse the repository at this point in the history
* feat(ui)!: unify UI components: cmp, wilder, floats

---------

Signed-off-by: Jint-lzxy <[email protected]>
Co-authored-by: huge-pancake <[email protected]>

* fix entry tags

* fixup! fix entry tags

---------

Signed-off-by: Jint-lzxy <[email protected]>
Co-authored-by: huge-pancake <[email protected]>
  • Loading branch information
2 people authored and csyJoy committed Jun 4, 2023
1 parent 47a2b78 commit 36afc54
Show file tree
Hide file tree
Showing 12 changed files with 117 additions and 230 deletions.
4 changes: 2 additions & 2 deletions lazy-lock.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"cmp-path": { "branch": "main", "commit": "91ff86cd9c29299a64f968ebb45846c485725f23" },
"cmp-spell": { "branch": "master", "commit": "60584cb75e5e8bba5a0c9e4c3ab0791e0698bffa" },
"cmp-tmux": { "branch": "main", "commit": "984772716f66d8ee88535a6bf3f94c4b4e1301f5" },
"cmp-treesitter": { "branch": "master", "commit": "389eadd48c27aa6dc0e6b992644704f026802a2e" },
"cmp-treesitter": { "branch": "master", "commit": "c8e3a74b51597d69d240085a258636972ce98e15" },
"cmp-under-comparator": { "branch": "master", "commit": "6857f10272c3cfe930cece2afa2406e1385bfef8" },
"cmp_luasnip": { "branch": "master", "commit": "18095520391186d634a0045dacaa346291096566" },
"copilot-cmp": { "branch": "master", "commit": "c2cdb3c0f5078b0619055af192295830a7987790" },
Expand All @@ -36,7 +36,7 @@
"lazy.nvim": { "branch": "main", "commit": "67ae8bbbe3985e380b98abeaf6c567c422b29746" },
"leap.nvim": { "branch": "main", "commit": "be918a8e6aa00a6cfa7270d4bfcc11b2f80d6902" },
"lsp_signature.nvim": { "branch": "master", "commit": "7a26ebaa7e36aa2aefa6c1994b2b866c96de32e6" },
"lspsaga.nvim": { "branch": "main", "commit": "01b9633aefd010f272d6c7e3d8293c44fcfe7696" },
"lspsaga.nvim": { "branch": "main", "commit": "4c557ed5c7cf3284bcd8fb926f329f24a0f141bf" },
"lualine.nvim": { "branch": "master", "commit": "05d78e9fd0cdfb4545974a5aa14b1be95a86e9c9" },
"markdown-preview.nvim": { "branch": "master", "commit": "02cc3874738bc0f86e4b91f09b8a0ac88aef8e96" },
"mason-lspconfig.nvim": { "branch": "main", "commit": "f0ce33f4794a2364eb08d09d09380e8b04ec5e6a" },
Expand Down
93 changes: 39 additions & 54 deletions lua/modules/configs/completion/cmp.lua
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ return function()

local border = function(hl)
return {
{ "", hl },
{ "", hl },
{ "", hl },
{ "", hl },
{ "", hl },
{ "", hl },
{ "", hl },
{ "", hl },
{ "", hl },
{ "", hl },
{ "", hl },
{ "", hl },
}
end
Expand All @@ -32,47 +32,18 @@ return function()
return (diff < 0)
end

local function cmp_format(opts)
opts = opts or {}

return function(entry, vim_item)
if opts.before then
vim_item = opts.before(entry, vim_item)
end

local kind_symbol = opts.symbol_map[vim_item.kind] or icons.kind.Undefined
local source_symbol = opts.symbol_map[entry.source.name] or icons.cmp.undefined

vim_item.menu = " " .. source_symbol .. " |"
vim_item.kind = string.format(" 〔 %s %s 〕", kind_symbol, vim_item.kind)

if opts.maxwidth ~= nil then
if opts.ellipsis_char == nil then
vim_item.abbr = string.sub(vim_item.abbr, 1, opts.maxwidth)
else
local label = vim_item.abbr
local truncated_label = vim.fn.strcharpart(label, 0, opts.maxwidth)
if truncated_label ~= label then
vim_item.abbr = truncated_label .. opts.ellipsis_char
end
end
end
return vim_item
end
end

local cmp = require("cmp")
cmp.setup({
preselect = cmp.PreselectMode.Item,
window = {
completion = {
border = border("Normal"),
max_width = 80,
max_height = 20,
border = border("PmenuBorder"),
winhighlight = "Normal:Pmenu,CursorLine:PmenuSel,Search:PmenuSel",
scrollbar = false,
},
documentation = {
border = border("CmpDocBorder"),
winhighlight = "Normal:CmpDoc",
},
},
sorting = {
Expand All @@ -96,14 +67,38 @@ return function()
},
},
formatting = {
fields = { "menu", "abbr", "kind" },
fields = { "abbr", "kind", "menu" },
format = function(entry, vim_item)
local kind_map = vim.tbl_deep_extend("force", icons.kind, icons.type, icons.cmp)
local kind = cmp_format({
maxwidth = 50,
symbol_map = kind_map,
})(entry, vim_item)
return kind
local lspkind_icons = vim.tbl_deep_extend("force", icons.kind, icons.type, icons.cmp)
-- load lspkind icons
vim_item.kind =
string.format(" %s %s", lspkind_icons[vim_item.kind] or icons.cmp.undefined, vim_item.kind or "")

vim_item.menu = setmetatable({
cmp_tabnine = "[TN]",
copilot = "[CPLT]",
buffer = "[BUF]",
orgmode = "[ORG]",
nvim_lsp = "[LSP]",
nvim_lua = "[LUA]",
path = "[PATH]",
tmux = "[TMUX]",
treesitter = "[TS]",
luasnip = "[SNIP]",
spell = "[SPELL]",
}, {
__index = function()
return "[BTN]" -- builtin/unknown source names
end,
})[entry.source.name]

local label = vim_item.abbr
local truncated_label = vim.fn.strcharpart(label, 0, 80)
if truncated_label ~= label then
vim_item.abbr = truncated_label .. "..."
end

return vim_item
end,
},
matching = {
Expand Down Expand Up @@ -151,17 +146,7 @@ return function()
{ name = "nvim_lua" },
{ name = "luasnip" },
{ name = "path" },
{
name = "treesitter",
entry_filter = function(entry)
local ignore_list = {
"Error",
"Comment",
}
local kind = entry:get_completion_item().cmp.kind_text
return not vim.tbl_contains(ignore_list, kind)
end,
},
{ name = "treesitter" },
{ name = "spell" },
{ name = "tmux" },
{ name = "orgmode" },
Expand Down
2 changes: 1 addition & 1 deletion lua/modules/configs/completion/lsp.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ return function()
local mason = require("mason")
local mason_lspconfig = require("mason-lspconfig")

require("lspconfig.ui.windows").default_options.border = "single"
require("lspconfig.ui.windows").default_options.border = "rounded"

local icons = {
ui = require("modules.utils.icons").get("ui", true),
Expand Down
2 changes: 1 addition & 1 deletion lua/modules/configs/completion/servers/clangd.lua
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ return function(options)
"--header-insertion-decorators",
"--header-insertion=iwyu",
"--limit-references=3000",
"--limit-results=350",
"--limit-results=270",
},
commands = {
ClangdSwitchSourceHeader = {
Expand Down
10 changes: 5 additions & 5 deletions lua/modules/configs/tool/nvim-tree.lua
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ return function()
show = {
file = true,
folder = true,
folder_arrow = false,
folder_arrow = true,
git = true,
},
padding = " ",
Expand All @@ -81,10 +81,10 @@ return function()
ignored = icons.git.Ignore, --
},
folder = {
-- arrow_open = "",
-- arrow_closed = "",
arrow_open = "",
arrow_closed = "",
arrow_open = icons.ui.ArrowOpen,
arrow_closed = icons.ui.ArrowClosed,
-- arrow_open = "",
-- arrow_closed = "",
default = icons.ui.Folder,
open = icons.ui.FolderOpen,
empty = icons.ui.EmptyFolder,
Expand Down
11 changes: 7 additions & 4 deletions lua/modules/configs/tool/toggleterm.lua
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
return function()
local colors = require("modules.utils").get_palette()
local floatborder_hl = require("modules.utils").hl_to_rgb("FloatBorder", false, colors.blue)

require("toggleterm").setup({
-- size can be a number or function which is passed the current terminal
size = function(term)
Expand All @@ -18,8 +15,14 @@ return function()
vim.api.nvim_set_option_value("foldexpr", "0", { scope = "local" })
end,
highlights = {
Normal = {
link = "Normal",
},
NormalFloat = {
link = "NormalFloat",
},
FloatBorder = {
guifg = floatborder_hl,
link = "FloatBorder",
},
},
open_mapping = false, -- [[<c-\>]],
Expand Down
8 changes: 3 additions & 5 deletions lua/modules/configs/tool/wilder.lua
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
return function()
local wilder = require("wilder")
local colors = require("modules.utils").get_palette()
local icons = { ui = require("modules.utils.icons").get("ui") }

wilder.setup({ modes = { ":", "/", "?" } })
Expand All @@ -25,13 +24,12 @@ return function()
-- ),
-- })

local match_hl = require("modules.utils").hl_to_rgb("String", false, colors.green)

local popupmenu_renderer = wilder.popupmenu_renderer(wilder.popupmenu_border_theme({
border = "rounded",
highlights = {
border = "Title", -- highlight to use for the border
accent = wilder.make_hl("WilderAccent", "Pmenu", { { a = 0 }, { a = 0 }, { foreground = match_hl } }),
default = "Pmenu",
border = "PmenuBorder", -- highlight to use for the border
accent = wilder.make_hl("WilderAccent", "CmpItemAbbr", "CmpItemAbbrMatch"),
},
empty_message = wilder.popupmenu_empty_message_with_spinner(),
highlighter = wilder.lua_fzy_highlighter(),
Expand Down
6 changes: 3 additions & 3 deletions lua/modules/configs/ui/alpha.lua
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ return function()
cursor = 5,
width = 50,
align_shortcut = "right",
hl = "AlphaButton",
hl_shortcut = "AlphaAttr",
hl = "AlphaButtons",
hl_shortcut = "AlphaShortcut",
}

if nil == keybind then
Expand Down Expand Up @@ -127,7 +127,7 @@ return function()
end,
}),
}
dashboard.section.buttons.opts.hl = "AlphaButton"
dashboard.section.buttons.opts.hl = "AlphaButtons"

local function footer()
local stats = require("lazy").stats()
Expand Down
Loading

0 comments on commit 36afc54

Please sign in to comment.