From e7970a93e4f75bdfa0de8eb96dddaecfad100cb7 Mon Sep 17 00:00:00 2001 From: huge-pancake Date: Sat, 1 Jul 2023 07:48:52 +0800 Subject: [PATCH 1/6] feat(ui)!: unify UI component `lualine` --- lua/modules/configs/ui/catppuccin.lua | 8 + lua/modules/configs/ui/lualine.lua | 278 +++++++++++++++++--------- lua/modules/plugins/ui.lua | 2 +- 3 files changed, 188 insertions(+), 100 deletions(-) diff --git a/lua/modules/configs/ui/catppuccin.lua b/lua/modules/configs/ui/catppuccin.lua index a95d1c78d..33a778f8b 100644 --- a/lua/modules/configs/ui/catppuccin.lua +++ b/lua/modules/configs/ui/catppuccin.lua @@ -181,6 +181,14 @@ return function() -- For treesitter ["@keyword.return"] = { fg = cp.pink, style = clear }, + + -- For lualine + LualineBranch = { fg = cp.subtext0, bg = cp.mantle, style = { "bold" } }, + LualineDiff = { fg = cp.subtext0, bg = cp.mantle }, + LualineLSP = { fg = cp.blue, bg = cp.mantle, style = { "bold" } }, + LualinePyVenv = { fg = cp.green, bg = cp.mantle }, + LualineCWD = { fg = cp.subtext0, bg = cp.mantle, style = { "bold" } }, + LualineSeparator = { fg = cp.surface1, bg = cp.mantle }, } end, }, diff --git a/lua/modules/configs/ui/lualine.lua b/lua/modules/configs/ui/lualine.lua index 0d6a3096c..878b86284 100644 --- a/lua/modules/configs/ui/lualine.lua +++ b/lua/modules/configs/ui/lualine.lua @@ -1,63 +1,10 @@ return function() - local colors = require("modules.utils").get_palette() local icons = { diagnostics = require("modules.utils.icons").get("diagnostics", true), - misc = require("modules.utils.icons").get("misc", true), + git = require("modules.utils.icons").get("git", true), ui = require("modules.utils.icons").get("ui", true), } - - local function escape_status() - local ok, m = pcall(require, "better_escape") - return ok and m.waiting and icons.misc.EscapeST or "" - end - - local _cache = { context = "", bufnr = -1 } - local function lspsaga_symbols() - local exclude = { - ["terminal"] = true, - ["toggleterm"] = true, - ["prompt"] = true, - ["NvimTree"] = true, - ["help"] = true, - } - if vim.api.nvim_win_get_config(0).zindex or exclude[vim.bo.filetype] then - return "" -- Excluded filetypes - else - local currbuf = vim.api.nvim_get_current_buf() - local ok, lspsaga = pcall(require, "lspsaga.symbolwinbar") - if ok and lspsaga:get_winbar() ~= nil then - _cache.context = lspsaga:get_winbar() - _cache.bufnr = currbuf - elseif _cache.bufnr ~= currbuf then - _cache.context = "" -- Reset [invalid] cache (usually from another buffer) - end - - return _cache.context - end - end - - local function diff_source() - local gitsigns = vim.b.gitsigns_status_dict - if gitsigns then - return { - added = gitsigns.added, - modified = gitsigns.changed, - removed = gitsigns.removed, - } - end - end - - local function get_cwd() - local cwd = vim.fn.getcwd() - local is_windows = require("core.global").is_windows - if not is_windows then - local home = require("core.global").home - if cwd:find(home, 1, true) == 1 then - cwd = "~" .. cwd:sub(#home + 1) - end - end - return icons.ui.RootFolderOpened .. cwd - end + local iconsNoSpace = { git = require("modules.utils.icons").get("git", false) } local mini_sections = { lualine_a = { "filetype" }, @@ -76,72 +23,211 @@ return function() filetypes = { "DiffviewFiles" }, } - local function python_venv() - local function env_cleanup(venv) - if string.find(venv, "/") then - local final_venv = venv - for w in venv:gmatch("([^/]+)") do - final_venv = w - end - venv = final_venv - end - return venv - end + local custom_theme = function() + local cp = require("modules.utils").get_palette() + return { + normal = { + a = { fg = cp.green, bg = cp.surface0, gui = "bold" }, + b = { fg = cp.text, bg = cp.mantle }, + c = { fg = cp.text, bg = cp.mantle }, + }, + command = { a = { fg = cp.yellow, bg = cp.surface0, gui = "bold" } }, + insert = { a = { fg = cp.blue, bg = cp.surface0, gui = "bold" } }, + visual = { a = { fg = cp.mauve, bg = cp.surface0, gui = "bold" } }, + terminal = { a = { fg = cp.teal, bg = cp.surface0, gui = "bold" } }, + replace = { a = { fg = cp.red, bg = cp.surface0, gui = "bold" } }, + inactive = { + a = { fg = cp.subtext0, bg = cp.mantle, gui = "bold" }, + b = { fg = cp.subtext0, bg = cp.mantle }, + c = { fg = cp.subtext0, bg = cp.mantle }, + }, + } + end + vim.api.nvim_create_autocmd("ColorScheme", { + group = vim.api.nvim_create_augroup("LualineColorScheme", { clear = true }), + callback = function() + require("lualine").setup({ options = { theme = custom_theme() } }) + end, + }) + + local conditions = { + hide_in_width = function() + return vim.o.columns > 100 + end, + check_git_workspace = function() + local filepath = vim.fn.expand("%:p:h") + local gitdir = vim.fn.finddir(".git", filepath .. ";") + return gitdir and #gitdir > 0 and #gitdir < #filepath + end, + } - if vim.bo.filetype == "python" then - local venv = os.getenv("CONDA_DEFAULT_ENV") - if venv then - return string.format("%s", env_cleanup(venv)) - end - venv = os.getenv("VIRTUAL_ENV") - if venv then - return string.format("%s", env_cleanup(venv)) - end + local function diff_source() + local gitsigns = vim.b.gitsigns_status_dict + if gitsigns then + return { + added = gitsigns.added, + modified = gitsigns.changed, + removed = gitsigns.removed, + } end - return "" end + local components = { + separator = { -- use as section separators + function() + return "│" + end, + padding = {}, + color = "LualineSeparator", + }, + + lsp = { + function() + if rawget(vim, "lsp") then + local names = {} + local lsp_exist = false + for _, client in ipairs(vim.lsp.get_active_clients()) do + if client.attached_buffers[vim.api.nvim_get_current_buf()] and client.name ~= "null-ls" then + table.insert(names, client.name) + lsp_exist = true + end + end + return lsp_exist and "󱜙 [" .. table.concat(names, ", ") .. "]" or "󱚧" + end + return "󱚧" + end, + color = "LualineLSP", + cond = conditions.hide_in_width, + }, + + python_venv = { + function() + local function env_cleanup(venv) + if string.find(venv, "/") then + local final_venv = venv + for w in venv:gmatch("([^/]+)") do + final_venv = w + end + venv = final_venv + end + return venv + end + + if vim.bo.filetype == "python" then + local venv = os.getenv("CONDA_DEFAULT_ENV") + if venv then + return string.format("%s", env_cleanup(venv)) + end + venv = os.getenv("VIRTUAL_ENV") + if venv then + return string.format("%s", env_cleanup(venv)) + end + end + return "" + end, + color = "LualinePyVenv", + cond = conditions.hide_in_width, + }, + cwd = { + function() + local cwd = vim.fn.getcwd() + local is_windows = require("core.global").is_windows + if not is_windows then + local home = require("core.global").home + if cwd:find(home, 1, true) == 1 then + cwd = "~" .. cwd:sub(#home + 1) + end + end + return icons.ui.RootFolderOpened .. cwd + end, + color = "LualineCWD", + }, + } + require("lualine").setup({ options = { icons_enabled = true, - theme = "catppuccin", - disabled_filetypes = {}, - component_separators = "|", - section_separators = { left = "", right = "" }, + theme = custom_theme(), + disabled_filetypes = { statusline = { "alpha" } }, + component_separators = "", + section_separators = { left = "", right = "" }, }, sections = { - lualine_a = { { "mode" } }, - lualine_b = { { "branch" }, { "diff", source = diff_source } }, - lualine_c = { lspsaga_symbols }, - lualine_x = { - { escape_status }, + lualine_a = { "mode" }, + lualine_b = { + -- idk what to put here + + -- FIXME: not perfect when in buffers such as `help` + -- vim.tbl_deep_extend("force", components.separator, { cond = conditions.check_git_workspace }), + }, + lualine_c = { + { -- branch + "b:gitsigns_head", + icon = iconsNoSpace.git.Branch, + color = "LualineBranch", + }, + { + "diff", + symbols = { + added = icons.git.Add, + modified = icons.git.Mod, + removed = icons.git.Remove, + }, + source = diff_source, + colored = false, + color = "LualineDiff", + padding = { right = 1 }, + }, + + { -- center + function() + return "%=" + end, + }, + { "diagnostics", sources = { "nvim_diagnostic" }, + sections = { "error", "warn", "info", "hint" }, symbols = { error = icons.diagnostics.Error, warn = icons.diagnostics.Warning, info = icons.diagnostics.Information, - hint = icons.diagnostics.Hint_alt, + hint = icons.diagnostics.Hint, }, }, - { get_cwd }, + components.lsp, }, - lualine_y = { - { "filetype", colored = true, icon_only = true }, - { python_venv }, - { "encoding" }, + lualine_x = { + { + "o:encoding", + fmt = string.upper, + padding = { left = 1 }, + cond = conditions.hide_in_width, + }, { "fileformat", - icons_enabled = true, symbols = { unix = "LF", dos = "CRLF", mac = "CR", }, + padding = { left = 1 }, + }, + { -- spaces + function() + local shiftwidth = vim.api.nvim_buf_get_option(0, "shiftwidth") + return icons.ui.ChevronRight .. shiftwidth + end, + padding = 1, }, }, - lualine_z = { "progress", "location" }, + lualine_y = { + components.separator, + components.python_venv, + components.cwd, + }, + lualine_z = { "location" }, }, inactive_sections = { lualine_a = {}, @@ -162,10 +248,4 @@ return function() diffview, }, }) - - -- Properly set background color for lspsaga - local winbar_bg = require("modules.utils").hl_to_rgb("StatusLine", true, colors.mantle) - for _, hlGroup in pairs(require("lspsaga.lspkind").get_kind_group()) do - require("modules.utils").extend_hl(hlGroup, { bg = winbar_bg }) - end end diff --git a/lua/modules/plugins/ui.lua b/lua/modules/plugins/ui.lua index 4230ea31f..7383b3954 100644 --- a/lua/modules/plugins/ui.lua +++ b/lua/modules/plugins/ui.lua @@ -38,7 +38,7 @@ ui["lukas-reineke/indent-blankline.nvim"] = { } ui["nvim-lualine/lualine.nvim"] = { lazy = true, - event = { "BufReadPost", "BufAdd", "BufNewFile" }, + event = "BufWinEnter", config = require("ui.lualine"), } ui["zbirenbaum/neodim"] = { From cc9ab7d0e24de06d97228a3e64171c47955ea1f0 Mon Sep 17 00:00:00 2001 From: Jint-lzxy <50296129+Jint-lzxy@users.noreply.github.com> Date: Sat, 1 Jul 2023 18:25:36 +0800 Subject: [PATCH 2/6] fixup! feat(ui)!: unify UI component `lualine` --- lua/core/options.lua | 2 +- lua/modules/configs/completion/formatting.lua | 2 +- lua/modules/configs/completion/lspsaga.lua | 2 +- lua/modules/configs/ui/bufferline.lua | 2 +- lua/modules/configs/ui/catppuccin.lua | 2 +- lua/modules/configs/ui/lualine.lua | 269 ++++++++++++------ lua/modules/plugins/completion.lua | 12 +- lua/modules/plugins/ui.lua | 2 +- lua/modules/utils/icons.lua | 3 + 9 files changed, 201 insertions(+), 95 deletions(-) diff --git a/lua/core/options.lua b/lua/core/options.lua index ed149c4af..b620249b1 100644 --- a/lua/core/options.lua +++ b/lua/core/options.lua @@ -17,7 +17,7 @@ local function load_options() breakat = [[\ \ ;:,!?]], breakindentopt = "shift:2,min:20", clipboard = "unnamedplus", - cmdheight = 2, -- 0, 1, 2 + cmdheight = 1, -- 0, 1, 2 cmdwinheight = 5, complete = ".,w,b,k", completeopt = "menuone,noselect", diff --git a/lua/modules/configs/completion/formatting.lua b/lua/modules/configs/completion/formatting.lua index f1586dd11..3e0b9a507 100644 --- a/lua/modules/configs/completion/formatting.lua +++ b/lua/modules/configs/completion/formatting.lua @@ -35,7 +35,7 @@ end, { nargs = 1, complete = "filetype" }) function M.enable_format_on_save(is_configured) local opts = { pattern = "*", timeout = 1000 } - vim.api.nvim_create_augroup("format_on_save", {}) + vim.api.nvim_create_augroup("format_on_save", { clear = true }) vim.api.nvim_create_autocmd("BufWritePre", { group = "format_on_save", pattern = opts.pattern, diff --git a/lua/modules/configs/completion/lspsaga.lua b/lua/modules/configs/completion/lspsaga.lua index feb371ef6..42cc4a146 100644 --- a/lua/modules/configs/completion/lspsaga.lua +++ b/lua/modules/configs/completion/lspsaga.lua @@ -108,7 +108,7 @@ return function() }, }, symbol_in_winbar = { - enable = false, + enable = true, separator = " " .. icons.ui.Separator, hide_keyword = true, show_file = false, diff --git a/lua/modules/configs/ui/bufferline.lua b/lua/modules/configs/ui/bufferline.lua index 68f76f426..feb269e4b 100644 --- a/lua/modules/configs/ui/bufferline.lua +++ b/lua/modules/configs/ui/bufferline.lua @@ -8,7 +8,7 @@ return function() buffer_close_icon = icons.ui.Close, left_trunc_marker = icons.ui.Left, right_trunc_marker = icons.ui.Right, - max_name_length = 14, + max_name_length = 20, max_prefix_length = 13, tab_size = 20, color_icons = true, diff --git a/lua/modules/configs/ui/catppuccin.lua b/lua/modules/configs/ui/catppuccin.lua index 33a778f8b..2ceb357b8 100644 --- a/lua/modules/configs/ui/catppuccin.lua +++ b/lua/modules/configs/ui/catppuccin.lua @@ -172,7 +172,7 @@ return function() bg = transparent_background and cp.none or cp.mantle, }, TelescopeSelection = { - fg = cp.green, + fg = transparent_background and cp.subtext0 or cp.text, bg = transparent_background and cp.none or cp.surface0, }, TelescopeResultsDiffAdd = { fg = cp.green }, diff --git a/lua/modules/configs/ui/lualine.lua b/lua/modules/configs/ui/lualine.lua index 878b86284..f2f541756 100644 --- a/lua/modules/configs/ui/lualine.lua +++ b/lua/modules/configs/ui/lualine.lua @@ -1,10 +1,50 @@ return function() + local colors = require("modules.utils").get_palette() local icons = { diagnostics = require("modules.utils.icons").get("diagnostics", true), git = require("modules.utils.icons").get("git", true), + git_nosep = require("modules.utils.icons").get("git"), + misc = require("modules.utils.icons").get("misc", true), ui = require("modules.utils.icons").get("ui", true), } - local iconsNoSpace = { git = require("modules.utils.icons").get("git", false) } + + local custom_theme = function() + colors = require("modules.utils").get_palette() + local universal_bg = require("core.settings").transparent_background and "NONE" or colors.mantle + return { + normal = { + a = { fg = colors.lavender, bg = colors.surface0, gui = "bold" }, + b = { fg = colors.text, bg = universal_bg }, + c = { fg = colors.text, bg = universal_bg }, + }, + command = { + a = { fg = colors.yellow, bg = colors.surface0, gui = "bold" }, + }, + insert = { + a = { fg = colors.green, bg = colors.surface0, gui = "bold" }, + }, + visual = { + a = { fg = colors.flamingo, bg = colors.surface0, gui = "bold" }, + }, + terminal = { + a = { fg = colors.teal, bg = colors.surface0, gui = "bold" }, + }, + replace = { + a = { fg = colors.red, bg = colors.surface0, gui = "bold" }, + }, + inactive = { + a = { fg = colors.subtext0, bg = universal_bg, gui = "bold" }, + b = { fg = colors.subtext0, bg = universal_bg }, + c = { fg = colors.subtext0, bg = universal_bg }, + }, + } + end + vim.api.nvim_create_autocmd("ColorScheme", { + group = vim.api.nvim_create_augroup("LualineColorScheme", { clear = true }), + callback = function() + require("lualine").setup({ options = { theme = custom_theme() } }) + end, + }) local mini_sections = { lualine_a = { "filetype" }, @@ -23,44 +63,57 @@ return function() filetypes = { "DiffviewFiles" }, } - local custom_theme = function() - local cp = require("modules.utils").get_palette() - return { - normal = { - a = { fg = cp.green, bg = cp.surface0, gui = "bold" }, - b = { fg = cp.text, bg = cp.mantle }, - c = { fg = cp.text, bg = cp.mantle }, - }, - command = { a = { fg = cp.yellow, bg = cp.surface0, gui = "bold" } }, - insert = { a = { fg = cp.blue, bg = cp.surface0, gui = "bold" } }, - visual = { a = { fg = cp.mauve, bg = cp.surface0, gui = "bold" } }, - terminal = { a = { fg = cp.teal, bg = cp.surface0, gui = "bold" } }, - replace = { a = { fg = cp.red, bg = cp.surface0, gui = "bold" } }, - inactive = { - a = { fg = cp.subtext0, bg = cp.mantle, gui = "bold" }, - b = { fg = cp.subtext0, bg = cp.mantle }, - c = { fg = cp.subtext0, bg = cp.mantle }, - }, - } - end - vim.api.nvim_create_autocmd("ColorScheme", { - group = vim.api.nvim_create_augroup("LualineColorScheme", { clear = true }), - callback = function() - require("lualine").setup({ options = { theme = custom_theme() } }) + local conditionals = { + trunc = function() + return vim.o.columns > 145 end, - }) - - local conditions = { - hide_in_width = function() - return vim.o.columns > 100 + has_comp_before = function() + return vim.bo.filetype ~= "" end, - check_git_workspace = function() + has_git = function() local filepath = vim.fn.expand("%:p:h") local gitdir = vim.fn.finddir(".git", filepath .. ";") return gitdir and #gitdir > 0 and #gitdir < #filepath end, } + ---@class lualine_hlgrp + ---@field fg string + ---@field bg string + ---@field gui string? + local utils = { + force_centering = function() + return "%=" + end, + abbreviate_path = function(path) + local home = require("core.global").home + if path:find(home, 1, true) == 1 then + path = "~" .. path:sub(#home + 1) + end + return path + end, + ---Generate `color` for any component + ---@param fg string @Foreground hl group + ---@param gen_bg boolean @Generate guibg from hl group |StatusLine|? + ---@param special_nobg boolean @Disable guibg for transparent backgrounds? + ---@param bg string? @Background hl group + ---@param gui string? @GUI highlight arguments + ---@return fun():lualine_hlgrp + gen_hl = function(fg, gen_bg, special_nobg, bg, gui) + return function() + local guifg = colors[fg] + local guibg = gen_bg and require("modules.utils").hl_to_rgb("StatusLine", true, colors.mantle) + or colors[bg] + local nobg = special_nobg and require("core.settings").transparent_background + return { + fg = guifg and guifg or colors.none, + bg = (guibg and not nobg) and guibg or colors.none, + gui = gui and gui or nil, + } + end + end, + } + local function diff_source() local gitsigns = vim.b.gitsigns_status_dict if gitsigns then @@ -77,27 +130,61 @@ return function() function() return "│" end, - padding = {}, - color = "LualineSeparator", + padding = 0, + color = utils.gen_hl("surface1", true, true), + }, + + file_status = { + function() + local function is_new_file() + local filename = vim.fn.expand("%") + return filename ~= "" and vim.bo.buftype == "" and vim.fn.filereadable(filename) == 0 + end + + local symbols = {} + if vim.bo.modified then + table.insert(symbols, "[+]") + end + if vim.bo.modifiable == false then + table.insert(symbols, "[-]") + end + if vim.bo.readonly == true then + table.insert(symbols, "[RO]") + end + if is_new_file() then + table.insert(symbols, "[New]") + end + return #symbols > 0 and table.concat(symbols, "") or "" + end, + padding = { left = -1, right = 1 }, + cond = conditionals.has_comp_before, }, lsp = { function() - if rawget(vim, "lsp") then - local names = {} - local lsp_exist = false - for _, client in ipairs(vim.lsp.get_active_clients()) do - if client.attached_buffers[vim.api.nvim_get_current_buf()] and client.name ~= "null-ls" then - table.insert(names, client.name) - lsp_exist = true + local buf_ft = vim.api.nvim_buf_get_option(0, "filetype") + local clients = vim.lsp.get_active_clients() + local lsp_lists = {} + local available_servers = {} + if next(clients) == nil then + return icons.misc.NoActiveLsp -- No server available + end + for _, client in ipairs(clients) do + local filetypes = client.config.filetypes + local client_name = client.name + if filetypes and vim.fn.index(filetypes, buf_ft) ~= -1 then + -- Avoid adding servers that already exists. + if not lsp_lists[client_name] then + lsp_lists[client_name] = true + table.insert(available_servers, client_name) end end - return lsp_exist and "󱜙 [" .. table.concat(names, ", ") .. "]" or "󱚧" end - return "󱚧" + return next(available_servers) == nil and icons.misc.NoActiveLsp + or string.format("%s[%s]", icons.misc.LspAvailable, table.concat(available_servers, ", ")) end, - color = "LualineLSP", - cond = conditions.hide_in_width, + color = utils.gen_hl("blue", true, true, nil, "bold"), + cond = conditionals.trunc, }, python_venv = { @@ -113,7 +200,7 @@ return function() return venv end - if vim.bo.filetype == "python" then + if vim.api.nvim_buf_get_option(0, "filetype") == "python" then local venv = os.getenv("CONDA_DEFAULT_ENV") if venv then return string.format("%s", env_cleanup(venv)) @@ -125,22 +212,39 @@ return function() end return "" end, - color = "LualinePyVenv", - cond = conditions.hide_in_width, + color = utils.gen_hl("green", true, true), + cond = conditionals.trunc, }, + + shiftwidth = { + function() + return icons.ui.ArrowClosed .. vim.api.nvim_buf_get_option(0, "shiftwidth") + end, + padding = 1, + }, + cwd = { function() - local cwd = vim.fn.getcwd() - local is_windows = require("core.global").is_windows - if not is_windows then - local home = require("core.global").home - if cwd:find(home, 1, true) == 1 then - cwd = "~" .. cwd:sub(#home + 1) - end + return icons.ui.FolderWithHeart .. utils.abbreviate_path(vim.fs.normalize(vim.fn.getcwd())) + end, + color = utils.gen_hl("subtext0", true, true, nil, "bold"), + }, + + file_location = { + function() + local cursorline = vim.fn.line(".") + local cursorcol = vim.fn.virtcol(".") + local filelines = vim.fn.line("$") + local position = "N/A" + if cursorline == 1 then + position = "Top" + elseif cursorline == filelines then + position = "Bot" + else + position = string.format("%2d%%%%", math.floor(cursorline / filelines * 100)) end - return icons.ui.RootFolderOpened .. cwd + return string.format("%s · %3d:%-2d", position, cursorline, cursorcol) end, - color = "LualineCWD", }, } @@ -155,36 +259,39 @@ return function() sections = { lualine_a = { "mode" }, lualine_b = { - -- idk what to put here - - -- FIXME: not perfect when in buffers such as `help` - -- vim.tbl_deep_extend("force", components.separator, { cond = conditions.check_git_workspace }), + { + "filetype", + colored = true, + icon_only = false, + icon = { align = "left" }, + }, + components.file_status, + vim.tbl_deep_extend("force", components.separator, { + cond = function() + return conditionals.has_git() and conditionals.has_comp_before() + end, + }), }, lualine_c = { - { -- branch - "b:gitsigns_head", - icon = iconsNoSpace.git.Branch, - color = "LualineBranch", + { + "branch", + icon = icons.git_nosep.Branch, + color = utils.gen_hl("subtext0", true, true, nil, "bold"), }, { "diff", symbols = { added = icons.git.Add, - modified = icons.git.Mod, + modified = icons.git.Mod_alt, removed = icons.git.Remove, }, source = diff_source, colored = false, - color = "LualineDiff", + color = utils.gen_hl("subtext0", true, true), padding = { right = 1 }, }, - { -- center - function() - return "%=" - end, - }, - + { utils.force_centering }, { "diagnostics", sources = { "nvim_diagnostic" }, @@ -193,41 +300,35 @@ return function() error = icons.diagnostics.Error, warn = icons.diagnostics.Warning, info = icons.diagnostics.Information, - hint = icons.diagnostics.Hint, + hint = icons.diagnostics.Hint_alt, }, }, components.lsp, }, lualine_x = { { - "o:encoding", + "encoding", fmt = string.upper, padding = { left = 1 }, - cond = conditions.hide_in_width, + cond = conditionals.trunc, }, { "fileformat", symbols = { unix = "LF", dos = "CRLF", - mac = "CR", + mac = "CR", -- Legacy macOS }, padding = { left = 1 }, }, - { -- spaces - function() - local shiftwidth = vim.api.nvim_buf_get_option(0, "shiftwidth") - return icons.ui.ChevronRight .. shiftwidth - end, - padding = 1, - }, + components.shiftwidth, }, lualine_y = { components.separator, components.python_venv, components.cwd, }, - lualine_z = { "location" }, + lualine_z = { components.file_location }, }, inactive_sections = { lualine_a = {}, diff --git a/lua/modules/plugins/completion.lua b/lua/modules/plugins/completion.lua index 241a2b7dc..b8371390b 100644 --- a/lua/modules/plugins/completion.lua +++ b/lua/modules/plugins/completion.lua @@ -5,15 +5,17 @@ completion["neovim/nvim-lspconfig"] = { event = { "BufReadPost", "BufAdd", "BufNewFile" }, config = require("completion.lsp"), dependencies = { - { "ray-x/lsp_signature.nvim" }, { "williamboman/mason.nvim" }, { "williamboman/mason-lspconfig.nvim" }, - { - "nvimdev/lspsaga.nvim", - config = require("completion.lspsaga"), - }, + { "ray-x/lsp_signature.nvim" }, }, } +completion["nvimdev/lspsaga.nvim"] = { + lazy = true, + event = "LspAttach", + config = require("completion.lspsaga"), + dependencies = { "nvim-tree/nvim-web-devicons" }, +} completion["jose-elias-alvarez/null-ls.nvim"] = { lazy = true, event = { "CursorHold", "CursorHoldI" }, diff --git a/lua/modules/plugins/ui.lua b/lua/modules/plugins/ui.lua index 7383b3954..4230ea31f 100644 --- a/lua/modules/plugins/ui.lua +++ b/lua/modules/plugins/ui.lua @@ -38,7 +38,7 @@ ui["lukas-reineke/indent-blankline.nvim"] = { } ui["nvim-lualine/lualine.nvim"] = { lazy = true, - event = "BufWinEnter", + event = { "BufReadPost", "BufAdd", "BufNewFile" }, config = require("ui.lualine"), } ui["zbirenbaum/neodim"] = { diff --git a/lua/modules/utils/icons.lua b/lua/modules/utils/icons.lua index 365143e4f..7780650cc 100644 --- a/lua/modules/utils/icons.lua +++ b/lua/modules/utils/icons.lua @@ -94,6 +94,7 @@ local data = { Fire = "", Folder = "", FolderOpen = "", + FolderWithHeart = "󱃪", Gear = "", History = "󰄉", Incoming = "󰏷", @@ -147,12 +148,14 @@ local data = { EscapeST = "", Gavel = "", Glass = "󰂖", + NoActiveLsp = "󱚧", PyEnv = "󰌠", Squirrel = "", Tag = "", Tree = "", Watch = "", Lego = "", + LspAvailable = "󱜙", Vbar = "│", Add = "+", Added = "", From bdf0784545ffbc46c89a5bea775eea9635362a95 Mon Sep 17 00:00:00 2001 From: Jint-lzxy <50296129+Jint-lzxy@users.noreply.github.com> Date: Sat, 1 Jul 2023 18:32:36 +0800 Subject: [PATCH 3/6] fix ci --- lua/modules/configs/ui/lualine.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lua/modules/configs/ui/lualine.lua b/lua/modules/configs/ui/lualine.lua index f2f541756..e58021921 100644 --- a/lua/modules/configs/ui/lualine.lua +++ b/lua/modules/configs/ui/lualine.lua @@ -235,7 +235,7 @@ return function() local cursorline = vim.fn.line(".") local cursorcol = vim.fn.virtcol(".") local filelines = vim.fn.line("$") - local position = "N/A" + local position if cursorline == 1 then position = "Top" elseif cursorline == filelines then From 730e07d0bf457745e8fb770c7a6e2560a9653af2 Mon Sep 17 00:00:00 2001 From: Jint-lzxy <50296129+Jint-lzxy@users.noreply.github.com> Date: Sat, 1 Jul 2023 19:07:50 +0800 Subject: [PATCH 4/6] fix autocmd registration --- lua/modules/configs/ui/lualine.lua | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/lua/modules/configs/ui/lualine.lua b/lua/modules/configs/ui/lualine.lua index e58021921..061af43d8 100644 --- a/lua/modules/configs/ui/lualine.lua +++ b/lua/modules/configs/ui/lualine.lua @@ -8,7 +8,14 @@ return function() ui = require("modules.utils.icons").get("ui", true), } - local custom_theme = function() + local function custom_theme() + vim.api.nvim_create_autocmd("ColorScheme", { + group = vim.api.nvim_create_augroup("LualineColorScheme", { clear = true }), + callback = function() + require("lualine").setup({ options = { theme = custom_theme() } }) + end, + }) + colors = require("modules.utils").get_palette() local universal_bg = require("core.settings").transparent_background and "NONE" or colors.mantle return { @@ -18,7 +25,7 @@ return function() c = { fg = colors.text, bg = universal_bg }, }, command = { - a = { fg = colors.yellow, bg = colors.surface0, gui = "bold" }, + a = { fg = colors.peach, bg = colors.surface0, gui = "bold" }, }, insert = { a = { fg = colors.green, bg = colors.surface0, gui = "bold" }, @@ -39,12 +46,6 @@ return function() }, } end - vim.api.nvim_create_autocmd("ColorScheme", { - group = vim.api.nvim_create_augroup("LualineColorScheme", { clear = true }), - callback = function() - require("lualine").setup({ options = { theme = custom_theme() } }) - end, - }) local mini_sections = { lualine_a = { "filetype" }, From 36843857464f30ffc56875428b1eceb310aeed39 Mon Sep 17 00:00:00 2001 From: Jint-lzxy <50296129+Jint-lzxy@users.noreply.github.com> Date: Sat, 1 Jul 2023 19:21:59 +0800 Subject: [PATCH 5/6] cleanups --- lua/modules/configs/ui/bufferline.lua | 4 ++-- lua/modules/configs/ui/catppuccin.lua | 15 +++++++-------- 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/lua/modules/configs/ui/bufferline.lua b/lua/modules/configs/ui/bufferline.lua index feb269e4b..7ceabab57 100644 --- a/lua/modules/configs/ui/bufferline.lua +++ b/lua/modules/configs/ui/bufferline.lua @@ -29,13 +29,13 @@ return function() filetype = "NvimTree", text = "File Explorer", text_align = "center", - padding = 1, + padding = 0, }, { filetype = "lspsagaoutline", text = "Lspsaga Outline", text_align = "center", - padding = 1, + padding = 0, }, }, }, diff --git a/lua/modules/configs/ui/catppuccin.lua b/lua/modules/configs/ui/catppuccin.lua index 2ceb357b8..3c2e0bb5c 100644 --- a/lua/modules/configs/ui/catppuccin.lua +++ b/lua/modules/configs/ui/catppuccin.lua @@ -128,6 +128,13 @@ return function() bg = transparent_background and cp.none or cp.mantle, }, + -- For lspsaga.nvim + OutlineNormal = { bg = transparent_background and cp.none or cp.mantle }, + OutlineWinSeparator = { + bg = transparent_background and cp.none or cp.base, + fg = transparent_background and cp.surface1 or cp.base, + }, + -- For fidget FidgetTask = { bg = cp.none, fg = cp.surface2 }, FidgetTitle = { fg = cp.blue, style = { "bold" } }, @@ -181,14 +188,6 @@ return function() -- For treesitter ["@keyword.return"] = { fg = cp.pink, style = clear }, - - -- For lualine - LualineBranch = { fg = cp.subtext0, bg = cp.mantle, style = { "bold" } }, - LualineDiff = { fg = cp.subtext0, bg = cp.mantle }, - LualineLSP = { fg = cp.blue, bg = cp.mantle, style = { "bold" } }, - LualinePyVenv = { fg = cp.green, bg = cp.mantle }, - LualineCWD = { fg = cp.subtext0, bg = cp.mantle, style = { "bold" } }, - LualineSeparator = { fg = cp.surface1, bg = cp.mantle }, } end, }, From 204e4c0cc0b5ad6f45718f0f0e76c66175a10763 Mon Sep 17 00:00:00 2001 From: Jint-lzxy <50296129+Jint-lzxy@users.noreply.github.com> Date: Sat, 1 Jul 2023 19:39:22 +0800 Subject: [PATCH 6/6] chore: make function names more intuitive --- lua/modules/configs/ui/lualine.lua | 16 ++++++++-------- lua/modules/utils/icons.lua | 1 + 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/lua/modules/configs/ui/lualine.lua b/lua/modules/configs/ui/lualine.lua index 061af43d8..d80a716d2 100644 --- a/lua/modules/configs/ui/lualine.lua +++ b/lua/modules/configs/ui/lualine.lua @@ -65,8 +65,8 @@ return function() } local conditionals = { - trunc = function() - return vim.o.columns > 145 + has_enough_room = function() + return vim.o.columns > 100 end, has_comp_before = function() return vim.bo.filetype ~= "" @@ -185,7 +185,7 @@ return function() or string.format("%s[%s]", icons.misc.LspAvailable, table.concat(available_servers, ", ")) end, color = utils.gen_hl("blue", true, true, nil, "bold"), - cond = conditionals.trunc, + cond = conditionals.has_enough_room, }, python_venv = { @@ -214,12 +214,12 @@ return function() return "" end, color = utils.gen_hl("green", true, true), - cond = conditionals.trunc, + cond = conditionals.has_enough_room, }, - shiftwidth = { + tabwidth = { function() - return icons.ui.ArrowClosed .. vim.api.nvim_buf_get_option(0, "shiftwidth") + return icons.ui.Tab .. vim.api.nvim_buf_get_option(0, "shiftwidth") end, padding = 1, }, @@ -311,7 +311,7 @@ return function() "encoding", fmt = string.upper, padding = { left = 1 }, - cond = conditionals.trunc, + cond = conditionals.has_enough_room, }, { "fileformat", @@ -322,7 +322,7 @@ return function() }, padding = { left = 1 }, }, - components.shiftwidth, + components.tabwidth, }, lualine_y = { components.separator, diff --git a/lua/modules/utils/icons.lua b/lua/modules/utils/icons.lua index 7780650cc..1bbe7dfb2 100644 --- a/lua/modules/utils/icons.lua +++ b/lua/modules/utils/icons.lua @@ -126,6 +126,7 @@ local data = { Sort = "", Spell = "󰓆", Symlink = "", + Tab = "", Table = "", Telescope = "", },