Skip to content

Commit

Permalink
Scaffold modules
Browse files Browse the repository at this point in the history
Add functionality to load all modules in the `lua/dorm/mod` directory.

* **`lua/dorm/mod/init.lua`**
  - Add `Mod.load_modules` function to load all modules in the `lua/dorm/mod` directory.
  - Use `vim.loop.fs_scandir` to iterate over the files in the directory.
  - Call `Mod.load_module` for each file that matches the pattern `module.lua`.

* **`lua/dorm/init.lua`**
  - Call `Mod.load_modules` in the `dorm.setup` function to load all modules.

---

For more details, open the [Copilot Workspace session](https://copilot-workspace.githubnext.com/clpi/dorm.lua?shareId=XXXX-XXXX-XXXX-XXXX).
  • Loading branch information
clpi committed Nov 16, 2024
1 parent a048f23 commit 729021f
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
3 changes: 3 additions & 0 deletions lua/dorm/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,9 @@ function dorm.setup(cfg)
end,
})
end

-- Call Mod.load_modules to load all modules
mod.load_modules()
end

--- This function gets called upon entering a .dorm file and loads all of the user-defined mod.
Expand Down
21 changes: 21 additions & 0 deletions lua/dorm/mod/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -837,4 +837,25 @@ function Mod.send_event(recipient, event)
end
end

--- Load all modules in the `lua/dorm/mod` directory.
function Mod.load_modules()
local dir = "lua/dorm/mod"
local handle = vim.loop.fs_scandir(dir)
if not handle then
return
end

while true do
local name, type = vim.loop.fs_scandir_next(handle)
if not name then
break
end

if type == "file" and name:match("module%.lua$") then
local module_name = name:gsub("%.lua$", "")
Mod.load_module(module_name)
end
end
end

return Mod

0 comments on commit 729021f

Please sign in to comment.