robin/laufey
git clone https://git.robinwobin.dev/robin/laufey
aa1d8a2702
master
1local M ={} 2local ts =vim . treesitter 3local health =vim . health 4 5--- Performs a healthcheck for treesitter integration 6function M . check () 7health . start ( 'Treesitter features' ) 8 9health . info ( 10string . format ( 11'Treesitter ABI support: min %d, max %d' , 12ts . minimum_language_version , 13ts . language_version 14) 15) 16 17local can_wasm =vim . _ts_add_language_from_wasm ~= nil 18health . info ( string . format ( 'WASM parser support: %s' , tostring ( can_wasm ))) 19 20health . start ( 'Treesitter parsers' ) 21local parsers =vim . api . nvim_get_runtime_file ( 'parser/*' , true ) 22 23---@class ParserEntry 24---@field name string 25---@field path string 26---@field index integer runtime path index (unique) 27 28local sorted_parsers ={} ---@type ParserEntry[] 29 30for i , parser in ipairs ( parsers ) do 31local parsername =vim . fn . fnamemodify ( parser , ':t:r' ) 32table . insert ( sorted_parsers , { name =parsername , path =parser , index =i } ) 33end 34 35table . sort ( sorted_parsers , function ( a , b ) 36if a . name == b . name then 37return a . index < b . index -- if names are the same sort by rtpath index (unique) 38else 39return a . name < b . name 40end 41end ) 42 43for i , parser in ipairs ( sorted_parsers ) do 44local previous =sorted_parsers [ i - 1 ] 45local is_loadable , err_or_nil =pcall ( ts . language . add , parser . name ) 46 47if not is_loadable then 48health . error ( 49string . format ( 50'Parser "%s" failed to load (path: %s): %s' , 51parser . name , 52parser . path , 53err_or_nil or '?' 54) 55) 56elseif previous and previous . name == parser . name then 57-- Sorted by runtime path order (load order), thus, if the previous parser has the same name, 58-- the current parser will not be loaded and `ts.language.inspect(parser.name)` with have 59-- incorrect information. 60health . ok ( string . format ( 'Parser: %-20s (not loaded), path: %s' , parser . name , parser . path )) 61else 62local lang =ts . language . inspect ( parser . name ) 63health . ok ( 64string . format ( 'Parser: %-25s ABI: %d, path: %s' , parser . name , lang . abi_version , parser . path ) 65) 66end 67end 68 69health . start ( 'Treesitter queries' ) 70local query_files =vim . api . nvim_get_runtime_file ( 'queries/**/*.scm' , true ) 71 72---@class QueryEntry 73---@field lang string 74---@field type string 75---@field path string 76---@field index integer 77 78local queries_by_lang ={} ---@type table<string, QueryEntry[]> 79 80for i , query_file in ipairs ( query_files ) do 81local lang , query_type =query_file : match ( 'queries/([^/]+)/([^/]+)%.scm$' ) 82if lang and query_type then 83if not queries_by_lang [ lang ] then 84queries_by_lang [ lang ] ={} 85end 86table . insert ( queries_by_lang [ lang ], { 87lang =lang , 88type =query_type , 89path =query_file , 90index =i , 91} ) 92end 93end 94 95if not vim . tbl_isempty ( queries_by_lang ) then 96for lang , queries in vim . spairs ( queries_by_lang ) do 97table . sort ( queries , function ( a , b ) 98if a . type == b . type then 99return a . index < b . index 100else 101return a . type < b . type 102end 103end ) 104 105for _ , query in ipairs ( queries ) do 106local dir =vim . fs . dirname ( query . path ) 107health . ok ( string . format ( '%-15s %-15s %s' , lang , query . type , dir )) 108end 109end 110end 111end 112 113return M