From 4505e5da189a4594234ada242b0e66645664b0ca Mon Sep 17 00:00:00 2001 From: Fernando Schauenburg Date: Wed, 14 Feb 2024 23:47:17 +0100 Subject: [PATCH] Partial code for loading extensions --- lua/scratchpad.lua | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 lua/scratchpad.lua diff --git a/lua/scratchpad.lua b/lua/scratchpad.lua new file mode 100644 index 0000000..4c9e96d --- /dev/null +++ b/lua/scratchpad.lua @@ -0,0 +1,38 @@ +local module_root = function(--[[modname]]_) + return '/Users/fernando/.dotfiles/config/nvim/lua/hello' +end + +local scan_dir = function(path, callback) + local handle = vim.loop.fs_scandir(path) + while handle do + local name, type = vim.loop.fs_scandir_next(handle) + if not name then break end + callback(path .. '/' .. name, name, type) + end +end + +local scan_module = function(modname, callback) + local root = module_root(modname) + if not root then return end + scan_dir(root, function(path, name, type) + if name == 'init.lua' then + callback(modname) + elseif (type == 'file' or type == 'link') and name:sub(-4) == '.lua' then + callback(modname .. '.' .. name:sub(1, -5)) + elseif type == 'directory' and vim.loop.fs_stat(path .. '/init.lua') then + callback(modname .. '.' .. name) + end + end) +end + +local merge_module = function(modname) + local modules = {} + scan_module(modname, function(name) + table.insert(modules, require(name)) + end) + return vim.tbl_extend('force', {}, unpack(modules)) +end + +P(merge_module('hello')) + +