robin/lylla.nvim
a tiny, customizable statusline for neovim
git clone https://git.robinwobin.dev/robin/lylla.nvim
a25438a
main
1---@module 'lylla.log' 2 3local log ={} 4 5log . stack ={} 6 7local function getdebuginfo () 8local i =3 9local info =debug . getinfo ( i , "nSf" ) 10local nextinfo =debug . getinfo ( i + 1 , "n" ) 11while nextinfo and info and info . name == nil do 12info =nextinfo 13i =i + 1 14nextinfo =debug . getinfo ( i + 1 , "n" ) 15end 16return info 17end 18 19--- any message will not be displayed unless `'debug'` is set to `msg`. 20--- this is a purposeful design decisison made to avoid flooding the user with errors. 21--- this design decision also means that modules can silently fail. 22---@param msg string 23---@param level integer 24function log . notify ( msg , level , debuginfo ) 25debuginfo =debuginfo or getdebuginfo () 26local info =string . format ( 27"%s %s at %s" , 28# debuginfo . namewhat > 0 and debuginfo . namewhat or "chunk" , 29debuginfo . name or "main" , 30debuginfo . short_src or "main loop" 31) 32log . stack [ # log . stack + 1 ] ={ level , info , msg } 33msg =string . format ( "in %s:\n\t%s" , info , msg ) 34if vim . o . debug == "" then 35return 36end 37if vim . o . debug == "throw" and level >= vim . log . levels . ERROR then 38error ( msg , level ) 39return 40end 41vim . notify_once ( msg , level ) 42return level 43end 44 45---@param msg string 46function log . trace ( msg ) 47return log . notify ( msg , vim . log . levels . TRACE , getdebuginfo ()) 48end 49 50---@param msg string 51function log . debug ( msg ) 52return log . notify ( msg , vim . log . levels . DEBUG , getdebuginfo ()) 53end 54 55---@param msg string 56function log . info ( msg ) 57return log . notify ( msg , vim . log . levels . INFO , getdebuginfo ()) 58end 59 60---@param msg string 61function log . warn ( msg ) 62return log . notify ( msg , vim . log . levels . WARN , getdebuginfo ()) 63end 64 65---@param msg string 66function log . error ( msg ) 67return log . notify ( msg , vim . log . levels . ERROR , getdebuginfo ()) 68end 69 70return log