This document provides a technical overview of the Smart Commit plugin's architecture, internal components, and data flow.
Smart Commit is designed as a modular, event-driven system that leverages Neovim 0.11's asynchronous APIs to provide a responsive user experience. The plugin is structured around several key components:
- Configuration System: Hierarchical configuration loading and merging
- Task Runner: Asynchronous task execution with dependency tracking
- UI Components: Real-time feedback through sticky headers and sign column
- Predefined Tasks: Reusable task templates for common operations
- API Layer: Public interfaces for extension and integration
The configuration system loads and merges settings from multiple sources in order of precedence:
- Plugin defaults
- User global config (
~/.smart-commit.lua) - Project-specific config (first
.smart-commit.luafound in directory hierarchy) - Runtime setup options
Key functions:
load_config(): Loads and merges configuration from all sourcesfind_file_upwards(): Traverses directory hierarchy to find config filesprocess_tasks(): Resolves task extensions and handles shorthand syntax
The task runner is responsible for executing tasks asynchronously and managing their lifecycle:
- Uses
vim.system()for non-blocking command execution - Implements a dependency graph for task ordering
- Provides real-time status updates through UI callbacks
Key components:
- Task states:
PENDING,WAITING,RUNNING,SUCCESS,FAILED,SKIPPED run_tasks_with_dependencies(): Main entry point for task executionrun_task(): Executes a single task based on its configurationrun_command(): Handles shell command executionupdate_ui(): Updates the UI with current task states
The UI system provides visual feedback through:
- Sticky Header: A non-intrusive split window showing task status
- Sign Column: Icons indicating overall task status
- Analysis Window: Side panel for displaying detailed task output
Key functions:
set(): Creates or updates the header contenttoggle(): Shows or hides the headershow_analysis(): Creates a side panel for detailed outputupdate_signs(): Updates the sign column indicators
Centralized type definitions using EmmyLua annotations for LSP support:
SmartCommitTask: Core task definitionSmartCommitConfig: Plugin configuration structureStickyHeaderContent: UI content structure- Various utility types for callbacks and handlers
Reusable task templates for common operations:
- PNPM Tasks: Package management and script execution
- Copilot Tasks: AI-powered commit message generation and code analysis
-
Initialization:
- Plugin loads on Neovim startup
- Configuration is loaded and merged
- Autocommands are set up to detect commit buffers
-
Activation:
- Git commit buffer is opened
- Autocommand triggers
on_commit_buffer_open() - Initial UI is displayed
- Task runner is initialized
-
Task Execution:
- Tasks are filtered based on
whenconditions - Dependencies are resolved
- Tasks without dependencies start executing
- As tasks complete, dependent tasks are queued
- Tasks are filtered based on
-
UI Updates:
- Timer-based UI updates show real-time progress
- Task states are reflected in the sticky header
- Sign column shows overall status
- Detailed analysis is shown in side panels when available
-
Completion:
- All tasks complete (success, failure, or skipped)
- Final UI state is displayed
- Update timer is stopped
Smart Commit is designed to be extensible in several ways:
- Task Registration: Register custom tasks via the API
- Task Extension: Extend predefined tasks with custom behavior
- Configuration Files: Project-specific configuration
- Custom Handlers: Advanced task handling with full context access
The plugin maintains several key state objects:
- Task States: Current state of each task in
runner.tasks - UI States: Header and analysis window state in
ui.header_states - Configuration: Merged configuration in
M.config
- Asynchronous execution ensures the editor remains responsive
- UI updates are throttled to reduce overhead
- Tasks can run in parallel up to the configured concurrency limit
- All UI updates are scheduled to run on the main thread
- Task failures are captured and displayed in the UI
- Command execution errors are logged and reflected in task state
- Configuration errors are reported via notifications
- Timeouts prevent tasks from running indefinitely
- Task Caching: Cache task results to avoid redundant execution
- Task Grouping: Group related tasks for better organization
- Custom UI Themes: Allow customization of UI appearance
- Task Retry: Automatic retry for failed tasks
- Task History: Persistent history of task execution results