Something went wrong. Try again.
🪴 a tiny, customizable statusline for neovim
Something went wrong. Try again.
1.7 kB · 70 lines
Lua
at main
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071---@module 'lylla.log'
local log = {}
log.stack = {}
local function getdebuginfo() local i = 3 local info = debug.getinfo(i, "nSf") local nextinfo = debug.getinfo(i + 1, "n") while nextinfo and info and info.name == nil do info = nextinfo i = i + 1 nextinfo = debug.getinfo(i + 1, "n") end return infoend
--- any message will not be displayed unless `'debug'` is set to `msg`.--- this is a purposeful design decisison made to avoid flooding the user with errors.--- this design decision also means that modules can silently fail.---@param msg string---@param level integerfunction log.notify(msg, level, debuginfo) debuginfo = debuginfo or getdebuginfo() local info = string.format( "%s %s at %s", #debuginfo.namewhat > 0 and debuginfo.namewhat or "chunk", debuginfo.name or "main", debuginfo.short_src or "main loop" ) log.stack[#log.stack + 1] = { level, info, msg } msg = string.format("in %s:\n\t%s", info, msg) if vim.o.debug == "" then return end if vim.o.debug == "throw" and level >= vim.log.levels.ERROR then error(msg, level) return end vim.notify_once(msg, level) return levelend
---@param msg stringfunction log.trace(msg) return log.notify(msg, vim.log.levels.TRACE, getdebuginfo())end
---@param msg stringfunction log.debug(msg) return log.notify(msg, vim.log.levels.DEBUG, getdebuginfo())end
---@param msg stringfunction log.info(msg) return log.notify(msg, vim.log.levels.INFO, getdebuginfo())end
---@param msg stringfunction log.warn(msg) return log.notify(msg, vim.log.levels.WARN, getdebuginfo())end
---@param msg stringfunction log.error(msg) return log.notify(msg, vim.log.levels.ERROR, getdebuginfo())end
return log