Do-It.nvim 2.0 introduces a modular framework that allows components to work independently or together. This architecture enables:
- Loading only the modules you need
- Using modules standalone or together
- Adding custom modules that integrate with the system
- Extending functionality without modifying core code
The module registry manages all loaded modules and provides:
- Dynamic module loading
- Dependency resolution
- Module lifecycle management
- Inter-module communication
The event system enables modules to communicate without direct dependencies:
-- Publishing an event
M.events.publish("todo:created", { todo = todo_data })
-- Subscribing to events
M.events.subscribe("todo:created", function(data)
-- Handle the event
end)Centralized configuration handling with:
- Module-specific configurations
- Global settings
- Runtime configuration updates
- Validation and defaults
Common UI utilities for consistent interface design:
- Window management
- Buffer utilities
- Keybinding helpers
- Notification system
local M = {}
M.config = {
-- Default configuration
}
function M.setup(config)
-- Module initialization
M.config = vim.tbl_deep_extend("force", M.config, config or {})
end
function M.load()
-- Called when module is loaded by framework
end
function M.unload()
-- Cleanup when module is unloaded
end
return MModules are automatically discovered if placed in the correct directory structure:
lua/doit/modules/
└── mymodule/
├── init.lua -- Main module file
├── config.lua -- Configuration defaults
└── ui.lua -- UI components
M.metadata = {
name = "mymodule",
version = "1.0.0",
description = "My custom module",
author = "Your Name",
dependencies = { "todos" }, -- Optional dependencies
}- Isolation: Modules should be self-contained and not depend on internal implementation details of other modules
- Events: Use the event system for loose coupling between modules
- Configuration: Provide sensible defaults and validate user configuration
- Documentation: Include help documentation and clear API documentation
- Testing: Write tests for your module using the project's testing framework
See :help doit-api for the complete API reference.