mirror of
				https://github.com/folke/lazy.nvim.git
				synced 2025-10-30 22:11:09 +00:00 
			
		
		
		
	feat(util): utility method to walk over all modules in a directory
This commit is contained in:
		
					parent
					
						
							
								26a67e3c48
							
						
					
				
			
			
				commit
				
					
						5d9d35404f
					
				
			
		
					 1 changed files with 16 additions and 0 deletions
				
			
		|  | @ -201,6 +201,22 @@ function M.walk(path, fn) | |||
|   end) | ||||
| end | ||||
| 
 | ||||
| ---@param root string | ||||
| ---@param fn fun(modname:string, modpath:string) | ||||
| ---@param modname? string | ||||
| function M.walkmods(root, fn, modname) | ||||
|   modname = modname and (modname:gsub("%.$", "") .. ".") or "" | ||||
|   M.ls(root, function(path, name, type) | ||||
|     if name == "init.lua" then | ||||
|       fn(modname:gsub("%.$", ""), path) | ||||
|     elseif (type == "file" or type == "link") and name:sub(-4) == ".lua" then | ||||
|       fn(modname .. name:sub(1, -5), path) | ||||
|     elseif type == "directory" then | ||||
|       M.walkmods(path, fn, modname .. name .. ".") | ||||
|     end | ||||
|   end) | ||||
| end | ||||
| 
 | ||||
| ---@param modname string | ||||
| ---@param fn fun(modname:string, modpath:string) | ||||
| function M.lsmod(modname, fn) | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue