From 4f789d3406d0d2424a677dfc0cb14224b00b7aec Mon Sep 17 00:00:00 2001 From: siduck Date: Mon, 21 Nov 2022 21:06:49 +0530 Subject: [PATCH] add multiple cmp themes https://github.com/NvChad/base46/issues/109 --- init.lua | 1 - lua/core/default_config.lua | 15 +++++++++++- lua/core/init.lua | 2 +- lua/plugins/configs/cmp.lua | 48 ++++++++++++++++++++++++++++++------- 4 files changed, 54 insertions(+), 12 deletions(-) diff --git a/init.lua b/init.lua index cc36d01..b042390 100644 --- a/init.lua +++ b/init.lua @@ -26,7 +26,6 @@ if fn.empty(fn.glob(install_path)) > 0 then vim.api.nvim_create_autocmd("User", { pattern = "PackerComplete", callback = function() - require("base46").compile() require("base46").load_all_highlights() vim.cmd "bw | silent! MasonInstallAll" -- close packer window diff --git a/lua/core/default_config.lua b/lua/core/default_config.lua index 5d11e7c..24c6592 100644 --- a/lua/core/default_config.lua +++ b/lua/core/default_config.lua @@ -10,14 +10,27 @@ M.options = { } M.ui = { + ------------------------------- base46 ------------------------------------- -- hl = highlights hl_add = {}, hl_override = {}, + changed_themes = {}, theme_toggle = { "onedark", "one_light" }, theme = "onedark", -- default theme + transparency = false, + -- cmp themeing + cmp = { + icons = true, + lspkind_text = true, + style = "default", -- default/flat_light/flat_dark/atom/atom_colored + border_color = "grey_fg", -- only applicable for "default" style, use color names from base30 variables + selected_item_bg = "colored", -- colored / simple + }, + + ------------------------------- nvchad_ui modules ----------------------------- statusline = { separator_style = "default", -- default/round/block/arrow overriden_modules = nil, @@ -58,7 +71,7 @@ M.ui = { M.plugins = {} --- check core.mappings for table structure +-- these are default mappings, check core.mappings for table structure M.mappings = require "core.mappings" return M diff --git a/lua/core/init.lua b/lua/core/init.lua index 80d9250..7d1fb4d 100644 --- a/lua/core/init.lua +++ b/lua/core/init.lua @@ -29,5 +29,5 @@ autocmd("VimEnter", { local new_cmd = vim.api.nvim_create_user_command new_cmd("CompileNvTheme", function() - require("base46").compile() + require("base46").load_all_highlights() end, {}) diff --git a/lua/plugins/configs/cmp.lua b/lua/plugins/configs/cmp.lua index c89daae..2a7312d 100644 --- a/lua/plugins/configs/cmp.lua +++ b/lua/plugins/configs/cmp.lua @@ -8,6 +8,35 @@ loadfile(vim.g.base46_cache .. "cmp")() vim.o.completeopt = "menu,menuone,noselect" +local cmp_ui = require("core.utils").load_config().ui.cmp +local cmp_style = cmp_ui.style + +local field_arrangement = { + atom = { "kind", "abbr", "menu" }, + atom_colored = { "kind", "abbr", "menu" }, +} + +local formatting_style = { + -- default fields order i.e completion word + item.kind + item.kind icons + fields = field_arrangement[cmp_style] or { "abbr", "kind", "menu" }, + + format = function(_, item) + local icons = require("nvchad_ui.icons").lspkind + local icon = (cmp_ui.icons and icons[item.kind]) or "" + + if cmp_style == "atom" or cmp_style == "atom_colored" then + icon = " " .. icon .. " " + item.menu = cmp_ui.lspkind_text and " (" .. item.kind .. ")" or "" + item.kind = icon + else + icon = cmp_ui.lspkind_text and (" " .. icon .. " ") or icon + item.kind = string.format("%s %s", icon, cmp_ui.lspkind_text and item.kind or "") + end + + return item + end, +} + local function border(hl_name) return { { "╭", hl_name }, @@ -33,11 +62,12 @@ end local options = { window = { completion = { - border = border "CmpBorder", - winhighlight = "Normal:CmpPmenu,CursorLine:PmenuSel,Search:None", + side_padding = (cmp_style ~= "atom" and cmp_style ~= "atom_colored") and 1 or 0, + winhighlight = "Normal:CmpPmenu,CursorLine:CmpSel,Search:PmenuSel", }, documentation = { border = border "CmpDocBorder", + winhighlight = "Normal:CmpDoc", }, }, snippet = { @@ -45,13 +75,9 @@ local options = { require("luasnip").lsp_expand(args.body) end, }, - formatting = { - format = function(_, vim_item) - local icons = require("nvchad_ui.icons").lspkind - vim_item.kind = string.format("%s %s", icons[vim_item.kind], vim_item.kind) - return vim_item - end, - }, + + formatting = formatting_style, + mapping = { [""] = cmp.mapping.select_prev_item(), [""] = cmp.mapping.select_next_item(), @@ -97,6 +123,10 @@ local options = { }, } +if cmp_style ~= "atom" and cmp_style ~= "atom_colored" then + options.window.completion.border = border "CmpBorder" +end + -- check for any override options = require("core.utils").load_override(options, "hrsh7th/nvim-cmp")