Skip to content

Scaffold modules#3

Merged
clpi merged 1 commit intomasterfrom
copilot
Nov 16, 2024
Merged

Scaffold modules#3
clpi merged 1 commit intomasterfrom
copilot

Conversation

@clpi
Copy link
Copy Markdown
Owner

@clpi clpi commented Nov 16, 2024

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.

Summary by Sourcery

Add functionality to automatically load all modules in the 'lua/dorm/mod' directory during the setup process by introducing a new function 'Mod.load_modules' and integrating it into 'dorm.setup'.

New Features:

  • Introduce a function to load all modules in the 'lua/dorm/mod' directory using 'vim.loop.fs_scandir'.

Enhancements:

  • Enhance the 'dorm.setup' function to automatically load all modules by calling 'Mod.load_modules'.

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).
@sourcery-ai
Copy link
Copy Markdown

sourcery-ai Bot commented Nov 16, 2024

Reviewer's Guide by Sourcery

This PR implements module loading functionality by adding a new load_modules function that automatically scans and loads all module files from the lua/dorm/mod directory. The implementation uses Neovim's built-in vim.loop.fs_scandir API for directory traversal and integrates the module loading into the main setup function.

Sequence diagram for module loading process

sequenceDiagram
    participant User
    participant dorm
    participant Mod
    participant vim.loop

    User->>dorm: Call setup(cfg)
    dorm->>Mod: Call load_modules()
    Mod->>vim.loop: fs_scandir("lua/dorm/mod")
    alt Directory exists
        loop For each file in directory
            Mod->>vim.loop: fs_scandir_next(handle)
            alt File matches pattern "module.lua"
                Mod->>Mod: load_module(module_name)
            end
        end
    end
Loading

Class diagram for Mod module changes

classDiagram
    class Mod {
        +send_event(recipient, event)
        +load_modules()
    }
    note for Mod "Added load_modules function to load all modules in the directory"
Loading

File-Level Changes

Change Details Files
Implement automatic module loading functionality
  • Add load_modules function to scan the mod directory
  • Use vim.loop.fs_scandir for directory traversal
  • Filter files matching 'module.lua' pattern
  • Call load_module for each matching file
lua/dorm/mod/init.lua
Integrate module loading into the setup process
  • Add call to mod.load_modules in the setup function
lua/dorm/init.lua

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time. You can also use
    this command to specify where the summary should be inserted.

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link
Copy Markdown

@sourcery-ai sourcery-ai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @clpi - I've reviewed your changes - here's some feedback:

Overall Comments:

  • Consider adding error handling in Mod.load_modules() to gracefully handle module loading failures without breaking the entire plugin
Here's what I looked at during the review
  • 🟡 General issues: 1 issue found
  • 🟢 Security: all looks good
  • 🟢 Testing: all looks good
  • 🟢 Complexity: all looks good
  • 🟢 Documentation: all looks good

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Comment thread lua/dorm/mod/init.lua
function Mod.load_modules()
local dir = "lua/dorm/mod"
local handle = vim.loop.fs_scandir(dir)
if not handle then
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion (bug_risk): Consider logging an error when directory scanning fails

Silent failures can make debugging difficult. Consider logging an error message when fs_scandir fails to help with troubleshooting.

  if not handle then
    vim.notify("Failed to scan directory: " .. dir, vim.log.levels.ERROR)
    return

@clpi clpi merged commit 4a4624f into master Nov 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant