robin/laufey
git clone https://git.robinwobin.dev/robin/laufey
aa1d8a2702
master
1local M ={} 2local health =vim . health 3 4local deprecated ={} ---@type table<string, [string, string[], string?]> 5 6function M . check () 7if next ( deprecated ) == nil then 8health . ok ( 'No deprecated functions detected' ) 9return 10end 11 12for name , v in vim . spairs ( deprecated ) do 13health . start ( '' ) 14 15local version , backtraces , alternative =v [ 1 ], v [ 2 ], v [ 3 ] 16local major_str , minor_str =version : match ( '(%d+)%.(%d+)' ) 17local major , minor =vim . _assert_integer ( major_str ), vim . _assert_integer ( minor_str ) 18local removal_version =string . format ( 'nvim-%d.%d' , major , minor ) 19local will_be_removed =vim . fn . has ( removal_version ) == 1 and 'was removed' or 'will be removed' 20 21local msg =( '%s is deprecated. Feature %s in Nvim %s' ): format ( name , will_be_removed , version ) 22local msg_alternative =alternative and ( 'use %s instead.' ): format ( alternative ) 23local advice ={ msg_alternative } 24table . insert ( advice , backtraces ) 25advice =vim . iter ( advice ): flatten (): totable () 26health . warn ( msg , advice ) 27end 28end 29 30--- @param name string 31--- @param version string 32--- @param backtrace string 33--- @param alternative? string 34function M . add ( name , version , backtrace , alternative ) 35if deprecated [ name ] == nil then 36deprecated [ name ] ={ version , { backtrace } , alternative } 37return 38end 39 40local it =vim . iter ( deprecated [ name ][ 2 ]) 41if it : find ( backtrace ) == nil then 42table . insert ( deprecated [ name ][ 2 ], backtrace ) 43end 44end 45 46return M