diff --git a/.luarc.json b/.luarc.json index 4ec713d..b32b188 100644 --- a/.luarc.json +++ b/.luarc.json @@ -1,5 +1,5 @@ { - "$schema": "https://raw.githubusercontent.com/sumneko/vscode-lua/master/setting/schema-zh-cn.json", + "$schema": "https://raw.githubusercontent.com/sumneko/vscode-lua/master/setting/schema-zh-tw.json", "diagnostics": { "globals": ["vim"], "disable": ["different-requires"] diff --git a/init.lua b/init.lua index dbacf0b..1544509 100644 --- a/init.lua +++ b/init.lua @@ -1,9 +1,3 @@ if not vim.g.vscode then require("core") end - ---[[ - -Support sematic token once 0.9 is released! - -]] diff --git a/lua/core/event.lua b/lua/core/event.lua index 3c3fba6..d003c1b 100644 --- a/lua/core/event.lua +++ b/lua/core/event.lua @@ -58,20 +58,16 @@ function autocmd.load_autocmds() { "BufWritePre", "MERGE_MSG", "setlocal noundofile" }, { "BufWritePre", "*.tmp", "setlocal noundofile" }, { "BufWritePre", "*.bak", "setlocal noundofile" }, - -- auto change directory - { "BufEnter", "*", "silent! lcd %:p:h" }, + -- change cursor to vertical bar after leaving neovim. + { "VimLeave", "*", "set guicursor=a:ver2" }, -- auto place to last edit { "BufReadPost", "*", [[if line("'\"") > 1 && line("'\"") <= line("$") | execute "normal! g'\"" | endif]], }, - -- Change cursor to vertical bar after leaving neovim. - { - "VimLeave", - "*", - "set guicursor=a:ver2", - }, + -- auto change directory + -- { "BufEnter", "*", "silent! lcd %:p:h" }, -- Auto toggle fcitx5 -- {"InsertLeave", "* :silent", "!fcitx5-remote -c"}, -- {"BufCreate", "*", ":silent !fcitx5-remote -c"}, diff --git a/lua/core/init.lua b/lua/core/init.lua index eeeaf18..7f07490 100644 --- a/lua/core/init.lua +++ b/lua/core/init.lua @@ -115,6 +115,32 @@ local clipboard_config = function() end end +local shell_config = function() + if global.is_windows then + if not (vim.fn.executable("pwsh") or vim.fn.executable("powershell")) then + vim.notify( + [[ +Failed to setup terminal config +PowerShell is either not installed, missing from PATH, or not executable; +cmd.exe will be used instead for `:!` (shell bang) and toggleterm.nvim. +You're recommended to install PowerShell for better experience.]], + vim.log.levels.WARN, + { title = "[core] Runtime error" } + ) + return + end + + local basecmd = "-NoLogo -MTA -ExecutionPolicy RemoteSigned" + local ctrlcmd = "-Command [console]::InputEncoding = [console]::OutputEncoding = [System.Text.Encoding]::UTF8" + vim.api.nvim_set_option_value("shell", vim.fn.executable("pwsh") and "pwsh" or "powershell", {}) + vim.api.nvim_set_option_value("shellcmdflag", string.format("%s %s;", basecmd, ctrlcmd), {}) + vim.api.nvim_set_option_value("shellredir", "-RedirectStandardOutput %s -NoNewWindow -Wait", {}) + vim.api.nvim_set_option_value("shellpipe", "2>&1 | Out-File -Encoding UTF8 %s; exit $LastExitCode", {}) + vim.api.nvim_set_option_value("shellquote", nil, {}) + vim.api.nvim_set_option_value("shellxquote", nil, {}) + end +end + local load_core = function() createdir() disable_distribution_plugins() @@ -122,6 +148,7 @@ local load_core = function() neovide_config() clipboard_config() + shell_config() require("core.options") require("core.mapping") diff --git a/lua/core/mapping.lua b/lua/core/mapping.lua index b372417..9d295cf 100644 --- a/lua/core/mapping.lua +++ b/lua/core/mapping.lua @@ -8,7 +8,6 @@ local core_map = { -- Vim map ["n|"] = map_cr("normal za"):with_noremap():with_silent(), ["n|"] = map_cu("write"):with_noremap():with_silent(), - ["n|"] = map_cmd("execute 'silent! write !sudo tee % >/dev/null' edit!"):with_silent():with_noremap(), ["n|Y"] = map_cmd("y$"), ["n|D"] = map_cmd("d$"), ["n|n"] = map_cmd("nzzzv"):with_noremap(), @@ -24,14 +23,22 @@ local core_map = { ["n|‘"] = map_cr("vertical resize +5"):with_silent(), ["n|…"] = map_cr("resize -2"):with_silent(), ["n|æ"] = map_cr("resize +2"):with_silent(), - ["n|"] = map_cmd(":wq"), - ["n|Œ"] = map_cmd(":q!"), + ["n|"] = map_cr("wq"), + ["n|Œ"] = map_cr("q!"), ["n|o"] = map_cr("setlocal spell! spelllang=en_us"), ["x|p"] = map_cmd('"_dP'):with_silent():with_noremap(), + ["n|+"] = map_cmd(""):with_noremap():with_silent(), + ["n|-"] = map_cmd(""):with_noremap():with_silent(), + ["n|"] = map_cmd("gg0vG$"):with_noremap():with_silent(), + ["x|"] = map_cmd("gg0vG$"):with_noremap():with_silent(), + ["n|tn"] = map_cr("tabnew"):with_noremap():with_silent(), + ["n|tk"] = map_cr("tabnext"):with_noremap():with_silent(), + ["n|tj"] = map_cr("tabprevious"):with_noremap():with_silent(), + ["n|to"] = map_cr("tabonly"):with_noremap():with_silent(), -- Insert mode ["i|"] = map_cmd("u"):with_noremap(), ["i|"] = map_cmd(""):with_noremap(), - ["i|"] = map_cmd("^i"):with_noremap(), + ["i|"] = map_cmd("^i"):with_noremap(), ["i|"] = map_cmd(":w"), ["i|"] = map_cmd(":wq"), -- Command mode diff --git a/lua/core/options.lua b/lua/core/options.lua index a9cf0c1..9af575a 100644 --- a/lua/core/options.lua +++ b/lua/core/options.lua @@ -17,7 +17,7 @@ local function load_options() cmdwinheight = 5, complete = ".,w,b,k", completeopt = "menuone,noselect", - cursorcolumn = false, --目前不是很喜欢竖直的线w + cursorcolumn = false, cursorline = true, diffopt = "filler,iwhite,internal,algorithm:patience", display = "lastline", @@ -47,7 +47,7 @@ local function load_options() redrawtime = 1500, ruler = true, scrolloff = 3, - sessionoptions = "curdir,help,tabpages,winsize", + sessionoptions = "buffers,curdir,help,tabpages,winsize", shada = "!,'300,<50,@100,s10,h", shiftround = true, shortmess = "aoOTIcF", diff --git a/lua/core/settings.lua b/lua/core/settings.lua index 27a248c..6d8757c 100644 --- a/lua/core/settings.lua +++ b/lua/core/settings.lua @@ -1,4 +1,5 @@ local settings = {} +local home = require("core.global").home -- Set it to false if you want to use https to update plugins and treesitter parsers. ---@type boolean @@ -8,9 +9,15 @@ settings["use_ssh"] = true ---@type boolean settings["format_on_save"] = true +-- Set it to false if diagnostics virtual text is annoying for you +---@type boolean +settings["diagnostics_virtual_text"] = true + -- Set the format disabled directories here, files under these dirs won't be formatted on save. ---@type string[] -settings["format_disabled_dirs"] = {} +settings["format_disabled_dirs"] = { + home .. "/Library/Rime", +} -- Set it to false if you don't use nvim to open big files. ---@type boolean @@ -28,6 +35,10 @@ settings["palette_overwrite"] = {} ---@type string settings["colorscheme"] = "catppuccin" +-- Set it to true if your terminal has transparent background. +---@type boolean +settings["transparent_background"] = false + -- Set background color to use here. -- Useful if you would like to use a colorscheme that has a light and dark variant like `edge`. -- Valid values are: `dark`, `light`. diff --git a/lua/keymap/init.lua b/lua/keymap/init.lua index d8d6817..59e63d7 100644 --- a/lua/keymap/init.lua +++ b/lua/keymap/init.lua @@ -72,6 +72,8 @@ local plug_map = { ["n|"] = map_cr([[execute v:count . "ToggleTerm direction=vertical"]]):with_noremap():with_silent(), ["i|"] = map_cmd("ToggleTerm direction=vertical"):with_noremap():with_silent(), ["t|"] = map_cmd("ToggleTerm"):with_noremap():with_silent(), + -- Plugin suda.vim + ["n|"] = map_cu("SudaWrite"):with_silent():with_noremap(), -- Plugin trouble ["n|gt"] = map_cr("TroubleToggle"):with_noremap():with_silent(), ["n|cr"] = map_cr("TroubleToggle lsp_references"):with_noremap():with_silent(), diff --git a/lua/modules/configs/completion/formatting.lua b/lua/modules/configs/completion/formatting.lua index 7b7559a..42dfe4c 100644 --- a/lua/modules/configs/completion/formatting.lua +++ b/lua/modules/configs/completion/formatting.lua @@ -15,7 +15,7 @@ vim.api.nvim_create_user_command("FormatterToggleFt", function(opts) vim.notify( string.format("[LSP] Formatter for [%s] has been recorded in list and disabled.", opts.args), vim.log.levels.WARN, - { title = "LSP Formatter Warning!" } + { title = "LSP Formatter Warning" } ) block_list[opts.args] = true else @@ -49,7 +49,7 @@ function M.enable_format_on_save(is_configured) vim.notify( "Successfully enabled format-on-save", vim.log.levels.INFO, - { title = "Settings modification success!" } + { title = "Settings modification success" } ) end end @@ -60,7 +60,7 @@ function M.disable_format_on_save() vim.notify( "Successfully disabled format-on-save", vim.log.levels.INFO, - { title = "Settings modification success!" } + { title = "Settings modification success" } ) end end @@ -102,6 +102,11 @@ function M.format(opts) local cwd = vim.fn.getcwd() for i = 1, #disabled_workspaces do if cwd.find(cwd, disabled_workspaces[i]) ~= nil then + vim.notify( + string.format("[LSP] Formatting support for all files under [%s] is disabled.", disabled_workspaces[i]), + vim.log.levels.WARN, + { title = "LSP Formatter Warning" } + ) return end end @@ -129,7 +134,7 @@ function M.format(opts) vim.notify( "[LSP] Format request failed, no matching language servers.", vim.log.levels.WARN, - { title = "Formatting Failed!" } + { title = "Formatting Failed" } ) end @@ -143,7 +148,7 @@ function M.format(opts) vim.bo.filetype ), vim.log.levels.WARN, - { title = "LSP Formatter Warning!" } + { title = "LSP Formatter Warning" } ) return end @@ -152,15 +157,15 @@ function M.format(opts) if result and result.result then vim.lsp.util.apply_text_edits(result.result, bufnr, client.offset_encoding) vim.notify( - string.format("Format successfully with %s!", client.name), + string.format("[LSP] Format successfully with %s!", client.name), vim.log.levels.INFO, - { title = "LSP Format Success!" } + { title = "LSP Format Success" } ) elseif err then vim.notify( string.format("[LSP][%s] %s", client.name, err), - vim.log.levels.WARN, - { title = "LSP Format Warning!" } + vim.log.levels.ERROR, + { title = "LSP Format Error" } ) end end diff --git a/lua/modules/configs/completion/lsp.lua b/lua/modules/configs/completion/lsp.lua index 16ccf37..5a3dd23 100644 --- a/lua/modules/configs/completion/lsp.lua +++ b/lua/modules/configs/completion/lsp.lua @@ -36,6 +36,13 @@ mason_lspconfig.setup({ local capabilities = vim.lsp.protocol.make_client_capabilities() capabilities = require("cmp_nvim_lsp").default_capabilities(capabilities) +vim.lsp.handlers["textDocument/publishDiagnostics"] = vim.lsp.with(vim.lsp.diagnostic.on_publish_diagnostics, { + signs = true, + underline = true, + virtual_text = require("core.settings").diagnostics_virtual_text, + update_in_insert = false, +}) + local opts = { on_attach = function() require("lsp_signature").on_attach({ diff --git a/lua/modules/configs/completion/lspsaga.lua b/lua/modules/configs/completion/lspsaga.lua index c033bd8..277f43c 100644 --- a/lua/modules/configs/completion/lspsaga.lua +++ b/lua/modules/configs/completion/lspsaga.lua @@ -79,7 +79,6 @@ return function() keys = { exec_action = "r", quit = "q", - go_action = "g", expand_or_jump = "", quit_in_show = { "q", "" }, }, @@ -119,6 +118,7 @@ return function() frequency = 12, }, ui = { + title = false, border = "single", -- Can be single, double, rounded, solid, shadow. winblend = 0, actionfix = icons.ui.Spell, diff --git a/lua/modules/configs/editor/suda.lua b/lua/modules/configs/editor/suda.lua new file mode 100644 index 0000000..bf77b65 --- /dev/null +++ b/lua/modules/configs/editor/suda.lua @@ -0,0 +1,3 @@ +return function() + vim.g["suda#prompt"] = "Enter administrator password: " +end diff --git a/lua/modules/configs/tool/nvim-tree.lua b/lua/modules/configs/tool/nvim-tree.lua index bb11678..2044419 100644 --- a/lua/modules/configs/tool/nvim-tree.lua +++ b/lua/modules/configs/tool/nvim-tree.lua @@ -67,17 +67,17 @@ return function() git = true, }, padding = " ", - symlink_arrow = "  ", + symlink_arrow = " 󰁔 ", glyphs = { default = icons.documents.Default, -- symlink = icons.documents.Symlink, -- bookmark = icons.ui.Bookmark, git = { unstaged = icons.git.Mod_alt, - staged = icons.git.Add, -- + staged = icons.git.Add, --󰄬 unmerged = icons.git.Unmerged, - renamed = icons.git.Rename, -- - untracked = icons.git.Untracked, -- "ﲉ" + renamed = icons.git.Rename, --󰁔 + untracked = icons.git.Untracked, -- "󰞋" deleted = icons.git.Remove, -- ignored = icons.git.Ignore, --◌ }, diff --git a/lua/modules/configs/tool/project.lua b/lua/modules/configs/tool/project.lua index 281f1a2..153d023 100644 --- a/lua/modules/configs/tool/project.lua +++ b/lua/modules/configs/tool/project.lua @@ -3,7 +3,7 @@ return function() manual_mode = false, detection_methods = { "lsp", "pattern" }, patterns = { ".git", "_darcs", ".hg", ".bzr", ".svn", "Makefile", "package.json" }, - ignore_lsp = { "efm", "copilot" }, + ignore_lsp = { "null-ls", "copilot" }, exclude_dirs = {}, show_hidden = false, silent_chdir = true, diff --git a/lua/modules/configs/ui/alpha.lua b/lua/modules/configs/ui/alpha.lua index 12779ec..5f8af75 100644 --- a/lua/modules/configs/ui/alpha.lua +++ b/lua/modules/configs/ui/alpha.lua @@ -1,6 +1,7 @@ return function() local alpha = require("alpha") local dashboard = require("alpha.themes.dashboard") + require("modules.utils").gen_alpha_hl() dashboard.section.header.val = { [[ ██╗██╗███╗ ██╗████████╗ ██╗ ███████╗██╗ ██╗██╗ ██╗ ]], @@ -12,7 +13,7 @@ return function() [[ ]], [[ Configuration By 冷酔閑吟 ver ]] .. os.date("%Y.%m") .. [[ ]], } - dashboard.section.header.opts.hl = "Type" + dashboard.section.header.opts.hl = "AlphaHeader" local function button(sc, txt, leader_txt, keybind, keybind_opts) local sc_after = sc:gsub("%s", ""):gsub(leader_txt, "") @@ -23,8 +24,8 @@ return function() cursor = 5, width = 50, align_shortcut = "right", - hl = "String", - hl_shortcut = "Keyword", + hl = "AlphaButton", + hl_shortcut = "AlphaAttr", } if keybind == nil then @@ -51,24 +52,24 @@ return function() dashboard.section.buttons.val = { button("[leader] f c", " Scheme change", leader, "Telescope colorscheme"), button("[leader] f r", " File frecency", leader, "Telescope frecency"), - button("[leader] f e", " File history", leader, "Telescope oldfiles"), + button("[leader] f e", "󰋚 File history", leader, "Telescope oldfiles"), button("[leader] f p", " Project find", leader, "Telescope projects"), - button("[leader] f f", " File find", leader, "Telescope find_files"), + button("[leader] f f", "󰈞 File find", leader, "Telescope find_files"), button("[leader] f n", " File new", leader, "enew"), button("[leader] f w", " Word find", leader, "Telescope live_grep"), } - dashboard.section.buttons.opts.hl = "String" + dashboard.section.buttons.opts.hl = "AlphaButton" local function footer() local stats = require("lazy").stats() local greet = " 💝 Have Fun with neovim" - .. "  v" + .. " 󰀨 v" .. vim.version().major .. "." .. vim.version().minor .. "." .. vim.version().patch - .. "  " + .. " 󰂖 " .. stats.count .. " plugins" local quote = table.concat(require("alpha.fortune")(), "\n") @@ -76,7 +77,7 @@ return function() end dashboard.section.footer.val = footer() - dashboard.section.footer.opts.hl = "Typedef" + dashboard.section.footer.opts.hl = "AlphaFooter" local head_butt_padding = 2 local occu_height = #dashboard.section.header.val + 2 * #dashboard.section.buttons.val + head_butt_padding diff --git a/lua/modules/configs/ui/bufferline.lua b/lua/modules/configs/ui/bufferline.lua index 85c3900..0e8bcf9 100644 --- a/lua/modules/configs/ui/bufferline.lua +++ b/lua/modules/configs/ui/bufferline.lua @@ -47,7 +47,7 @@ return function() highlights = {}, } - if vim.g.colors_name == "catppuccin" then + if vim.g.colors_name:find("catppuccin") then local cp = require("modules.utils").get_palette() -- Get the palette. local catppuccin_hl_overwrite = { diff --git a/lua/modules/configs/ui/catppuccin.lua b/lua/modules/configs/ui/catppuccin.lua index 852b58e..ec763d7 100644 --- a/lua/modules/configs/ui/catppuccin.lua +++ b/lua/modules/configs/ui/catppuccin.lua @@ -1,5 +1,5 @@ return function() - local transparent_background = false -- Set background transparency here! + local transparent_background = require("core.settings").transparent_background require("catppuccin").setup({ flavour = "mocha", @@ -242,7 +242,7 @@ return function() ["@field.lua"] = { fg = cp.lavender }, ["@constructor.lua"] = { fg = cp.flamingo }, - ["@variable.builtin.lua"] = { fg = cp.flamingo, style = { "italic" } }, + ["@variable.builtin.lua"] = { fg = cp.flamingo }, ["@constant.java"] = { fg = cp.teal }, diff --git a/lua/modules/configs/ui/edge.lua b/lua/modules/configs/ui/edge.lua index 216899a..6f63356 100644 --- a/lua/modules/configs/ui/edge.lua +++ b/lua/modules/configs/ui/edge.lua @@ -4,5 +4,5 @@ return function() vim.g.edge_disable_italic_comment = 1 vim.g.edge_show_eob = 1 vim.g.edge_better_performance = 1 - vim.g.edge_transparent_background = 1 + vim.g.edge_transparent_background = require("core.settings").transparent_background and 2 or 0 end diff --git a/lua/modules/configs/ui/lualine.lua b/lua/modules/configs/ui/lualine.lua index 88b52fa..e662dd9 100644 --- a/lua/modules/configs/ui/lualine.lua +++ b/lua/modules/configs/ui/lualine.lua @@ -231,7 +231,7 @@ return function() sections = { lualine_a = { { "mode", icon = icons.misc.ManUp } }, lualine_b = { - { "branch", icon = icons.cmp.Copilot }, + { "branch", icon = icons.cmp.copilot }, { "diff", symbols = { added = "  ", modified = "  ", removed = "  " }, @@ -252,6 +252,7 @@ return function() error = icons.diagnostics.Error, warn = icons.diagnostics.Warning, info = icons.diagnostics.Information, + hint = icons.diagnostics.Hint_alt, }, separator = "", }, diff --git a/lua/modules/configs/ui/nord.lua b/lua/modules/configs/ui/nord.lua index 522d3f7..17f5355 100644 --- a/lua/modules/configs/ui/nord.lua +++ b/lua/modules/configs/ui/nord.lua @@ -2,7 +2,7 @@ return function() vim.g.nord_contrast = true vim.g.nord_borders = false vim.g.nord_cursorline_transparent = true - vim.g.nord_disable_background = false + vim.g.nord_disable_background = require("core.settings").transparent_background vim.g.nord_enable_sidebar_background = true vim.g.nord_italic = true end diff --git a/lua/modules/plugins/completion.lua b/lua/modules/plugins/completion.lua index 6269911..653bc2a 100644 --- a/lua/modules/plugins/completion.lua +++ b/lua/modules/plugins/completion.lua @@ -8,7 +8,7 @@ completion["neovim/nvim-lspconfig"] = { { "williamboman/mason.nvim" }, { "williamboman/mason-lspconfig.nvim" }, { - "glepnir/lspsaga.nvim", + "nvimdev/lspsaga.nvim", config = require("completion.lspsaga"), }, { "ray-x/lsp_signature.nvim" }, diff --git a/lua/modules/plugins/editor.lua b/lua/modules/plugins/editor.lua index bc7a8d1..a827dc7 100644 --- a/lua/modules/plugins/editor.lua +++ b/lua/modules/plugins/editor.lua @@ -62,6 +62,11 @@ editor["luukvbaal/stabilize.nvim"] = { lazy = true, event = "BufReadPost", } +editor["lambdalisue/suda.vim"] = { + lazy = true, + cmd = { "SudaRead", "SudaWrite" }, + config = require("editor.suda"), +} editor["romainl/vim-cool"] = { lazy = true, event = { "CursorMoved", "InsertEnter" }, diff --git a/lua/modules/plugins/ui.lua b/lua/modules/plugins/ui.lua index cffedf8..0879d4e 100644 --- a/lua/modules/plugins/ui.lua +++ b/lua/modules/plugins/ui.lua @@ -25,7 +25,7 @@ ui["mbbill/undotree"] = { } ui["j-hui/fidget.nvim"] = { lazy = true, - event = "BufReadPost", + event = "LspAttach", config = require("ui.fidget"), } ui["lewis6991/gitsigns.nvim"] = { diff --git a/lua/modules/utils/icons.lua b/lua/modules/utils/icons.lua index 04d0698..758b81c 100644 --- a/lua/modules/utils/icons.lua +++ b/lua/modules/utils/icons.lua @@ -2,33 +2,33 @@ local icons = {} local data = { kind = { - Class = "ﴯ", - Color = "", - Constant = "", + Class = "󰠱", + Color = "󰏘", + Constant = "󰏿", Constructor = "", Enum = "", EnumMember = "", Event = "", - Field = "", - File = "", - Folder = "", - Function = "", + Field = "󰇽", + File = "󰈙", + Folder = "󰉋", + Function = "󰊕", Interface = "", - Keyword = "", - Method = "", + Keyword = "󰌋", + Method = "󰆧", Module = "", - Namespace = "", + Namespace = "󰌗", Number = "", - Operator = "", + Operator = "󰆕", Package = "", - Property = "ﰠ", + Property = "󰜢", Reference = "", Snippet = "", Struct = "", - Text = "", - TypeParameter = "", + Text = "󰉿", + TypeParameter = "󰅲", Unit = "", - Value = "", + Value = "󰎠", Variable = "", -- ccls-specific icons. TypeAlias = "", @@ -37,18 +37,18 @@ local data = { Macro = "", }, type = { - Array = "", + Array = "󰅪", Boolean = "", - Null = "ﳠ", + Null = "󰟢", Number = "", - Object = "", - String = "", + Object = "󰅩", + String = "󰉿", }, documents = { Default = "", File = "", Files = "", - FileTree = "פּ", + FileTree = "󰙅", Import = "", Symlink = "", }, @@ -56,15 +56,15 @@ local data = { Add = "", Branch = "", Diff = "", - Git = "", + Git = "󰊢", Ignore = "", Mod = "M", Mod_alt = "", Remove = "", Rename = "", Repo = "", - Unmerged = "שׂ", - Untracked = "ﲉ", + Unmerged = "󰘬", + Untracked = "󰞋", Unstaged = "", Staged = "", Conflict = "", @@ -74,55 +74,55 @@ local data = { ArrowOpen = "", BigCircle = "", BigUnfilledCircle = "", - BookMark = "", + BookMark = "󰃃", Bug = "", Calendar = "", - Check = "", + Check = "󰄳", ChevronRight = "", Circle = "", - Close = "", + Close = "󰅖", Close_alt = "", CloudDownload = "", - Comment = "", - CodeAction = "", + Comment = "󰅺", + CodeAction = "󰌵", Dashboard = "", - Emoji = "", + Emoji = "󰱫", EmptyFolder = "", EmptyFolderOpen = "", - File = "", + File = "󰈤", Fire = "", Folder = "", FolderOpen = "", Gear = "", - History = "", - Incoming = "", + History = "󰄉", + Incoming = "󰏷", Indicator = "", Keyboard = "", Left = "", List = "", Square = "", SymlinkFolder = "", - Lock = "", + Lock = "󰍁", Modified = "✥", Modified_alt = "", NewFile = "", Newspaper = "", - Note = "", - Outgoing = "", + Note = "󰍨", + Outgoing = "󰏻", Package = "", - Pencil = "", - Perf = "", + Pencil = "󰏫", + Perf = "󰅒", Play = "", Project = "", Right = "", RootFolderOpened = "", - Search = "", + Search = "󰍉", Separator = "", - DoubleSeparator = "", + DoubleSeparator = "󰄾", SignIn = "", SignOut = "", Sort = "", - Spell = "暈", + Spell = "󰓆", Symlink = "", Table = "", Telescope = "", @@ -132,21 +132,21 @@ local data = { Warning = "", Information = "", Question = "", - Hint = "", + Hint = "󰌵", -- Holo version - Error_alt = "", - Warning_alt = "", + Error_alt = "󰅚", + Warning_alt = "󰀪", Information_alt = "", Question_alt = "", - Hint_alt = "", + Hint_alt = "󰌶", }, misc = { - Campass = "", + Campass = "󰀹", Code = "", EscapeST = "", Gavel = "", - Glass = "", - PyEnv = "", + Glass = "󰂖", + PyEnv = "󰌠", Squirrel = "", Tag = "", Tree = "", @@ -155,35 +155,46 @@ local data = { Vbar = "│", Add = "+", Added = "", - Ghost = "", + Ghost = "󰊠", ManUp = "", Vim = "", }, cmp = { - Copilot = "", + Codeium = "", + TabNine = "", + Copilot = "", Copilot_alt = "", + -- Add source-specific icons here + buffer = "", + cmp_tabnine = "", + codeium = "", + copilot = "", + copilot_alt = "", + latex_symbols = "", + luasnip = "󰃐", nvim_lsp = "", nvim_lua = "", + orgmode = "", path = "", - buffer = "", - spell = "暈", - luasnip = "", + spell = "󰓆", + tmux = "", treesitter = "", + undefined = "", }, dap = { - Breakpoint = "", - BreakpointCondition = "ﳁ", + Breakpoint = "󰝥", + BreakpointCondition = "󰟃", BreakpointRejected = "", LogPoint = "", Pause = "", Play = "", RunLast = "↻", StepBack = "", - StepInto = "", - StepOut = "", - StepOver = "", + StepInto = "󰆹", + StepOut = "󰆸", + StepOver = "󰆷", Stopped = "", - Terminate = "ﱢ", + Terminate = "󰝤", }, } diff --git a/lua/modules/utils/init.lua b/lua/modules/utils/init.lua index b6f674a..0360c3e 100644 --- a/lua/modules/utils/init.lua +++ b/lua/modules/utils/init.lua @@ -36,7 +36,7 @@ local palette = nil ---@return palette local function init_palette() if not palette then - palette = vim.g.colors_name == "catppuccin" and require("catppuccin.palettes").get_palette() + palette = vim.g.colors_name:find("catppuccin") and require("catppuccin.palettes").get_palette() or { rosewater = "#DC8A78", flamingo = "#DD7878", @@ -80,6 +80,44 @@ local function hexToRgb(c) return { tonumber(c:sub(2, 3), 16), tonumber(c:sub(4, 5), 16), tonumber(c:sub(6, 7), 16) } end +---Parse the `style` string into nvim_set_hl options +---@param style string @The style config +---@return table +local function parse_style(style) + if not style or style == "NONE" then + return {} + end + + local result = {} + for field in string.gmatch(style, "([^,]+)") do + result[field] = true + end + + return result +end + +---Wrapper function for nvim_get_hl_by_name +---@param hl_group string @Highlight group name +---@return table +local function get_highlight(hl_group) + local hl = vim.api.nvim_get_hl_by_name(hl_group, true) + if hl.link then + return get_highlight(hl.link) + end + + local result = parse_style(hl.style) + result.fg = hl.foreground and string.format("#%06x", hl.foreground) + result.bg = hl.background and string.format("#%06x", hl.background) + result.sp = hl.special and string.format("#%06x", hl.special) + for attr, val in pairs(hl) do + if type(attr) == "string" and attr ~= "foreground" and attr ~= "background" and attr ~= "special" then + result[attr] = val + end + end + + return result +end + ---Blend foreground with background ---@param foreground string @The foreground color ---@param background string @The background color to blend with @@ -105,10 +143,10 @@ end ---@return string function M.hl_to_rgb(hl_group, use_bg, fallback_hl) local hex = fallback_hl or "#000000" - local hlexists = pcall(vim.api.nvim_get_hl, 0, { name = hl_group, link = false }) + local hlexists = pcall(vim.api.nvim_get_hl_by_name, hl_group, true) if hlexists then - local result = vim.api.nvim_get_hl(0, { name = hl_group, link = false }) + local result = get_highlight(hl_group) if use_bg then hex = result.bg and result.bg or "NONE" else @@ -123,12 +161,12 @@ end ---@param name string @Target highlight group name ---@param def table @Attributes to be extended function M.extend_hl(name, def) - local hlexists = pcall(vim.api.nvim_get_hl, 0, { name = name, link = false }) + local hlexists = pcall(vim.api.nvim_get_hl_by_name, name, true) if not hlexists then -- Do nothing if highlight group not found return end - local current_def = vim.api.nvim_get_hl(0, { name = name, link = false }) + local current_def = get_highlight(name) local combined_def = vim.tbl_deep_extend("force", current_def, def) vim.api.nvim_set_hl(0, name, combined_def) @@ -145,6 +183,7 @@ function M.get_palette(overwrite) end end +-- Generate highlight groups for lspsaga. Existing attributes will NOT be overwritten function M.gen_lspkind_hl() local colors = M.get_palette() local dat = { @@ -189,6 +228,16 @@ function M.gen_lspkind_hl() end end +-- Generate highlight groups for alpha. Existing attributes will NOT be overwritten +function M.gen_alpha_hl() + local colors = M.get_palette() + + vim.api.nvim_set_hl(0, "AlphaHeader", { fg = colors.blue, default = true }) + vim.api.nvim_set_hl(0, "AlphaButton", { fg = colors.green, default = true }) + vim.api.nvim_set_hl(0, "AlphaAttr", { fg = colors.pink, italic = true, default = true }) + vim.api.nvim_set_hl(0, "AlphaFooter", { fg = colors.yellow, default = true }) +end + ---Convert number (0/1) to boolean ---@param value number @The value to check ---@return boolean|nil @Returns nil if failed