Something went wrong. Try again.
Vim/Neovim configurations just for me
neovim
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105local highlight = require("rc.highlight")local line = require("rc.line")local ui = require("rc.ui")
local M = {}
local normalize_pathdo if package.config:sub(1, 1) == "\\" then ---@param s string function normalize_path(s) s = vim.fs.normalize(s) return s:sub(2, 3) == ":/" and ("%s%s"):format(s:sub(1, 1):upper(), s:sub(2)) or s end else ---@param s string function normalize_path(s) return vim.fs.normalize(s) end endend
local replace_homedirdo local home = vim.uv.os_homedir() if home then home = normalize_path(home) ---@param s string function replace_homedir(s) return s:sub(1, home:len()) == home and ("~%s"):format(s:sub(home:len() + 1)) or s end else ---@param s string function replace_homedir(s) return s end endend
---@param s string---@param buf integerlocal function replace_cwd(s, buf) local cwd = normalize_path(vim.fn.getcwd(vim.fn.bufwinnr(buf))) return s:sub(1, cwd:len()) == cwd and s:sub(cwd:len() + 2) or send
---@param buf integerlocal function current_file(buf) return replace_homedir(replace_cwd(normalize_path(vim.api.nvim_buf_get_name(buf)), buf))end
---@param buf numberlocal function diagnostics(buf) local severity = vim.diagnostic.severity local hl_map = { [severity.ERROR] = "DiagnosticError", [severity.WARN] = "DiagnosticWarn", [severity.INFO] = "DiagnosticInfo", [severity.HINT] = "DiagnosticHint", } local severities = { severity.HINT, severity.WARN, severity.ERROR, } local r = " " for _, s in pairs(severities) do local count = #vim.diagnostic.get(buf, { severity = s }) if count == 0 then r = r .. line.with_hl(" ", "WinBar") else local level = math.min(20 + count * 8, 100) r = r .. line.with_hl( " ", highlight.ensure("WinBar" .. hl_map[s] .. level, function() return highlight.get("Whitespace"):mix(hl_map[s], level) end) ) end end return rend
local function get_winbar(buf) local s = " " .. current_file(buf):gsub("/", ui.winbar_sep.path) .. "%=" .. diagnostics(buf) return send
function M.setup() vim.api.nvim_create_autocmd("DiagnosticChanged", { callback = function(cx) vim.api.nvim__redraw({ winbar = true, buf = cx.buf }) end, }) vim.api.nvim_create_autocmd("BufRead", { pattern = "*", callback = function(cx) vim.opt_local.winbar = line.as_opt(get_winbar, tostring(cx.buf)) end, })end
return M