|
| 1 | +# CLAUDE.md |
| 2 | + |
| 3 | +This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository. |
| 4 | + |
| 5 | +## Project Overview |
| 6 | + |
| 7 | +ghciwatch is a GHCi-based file watcher and recompiler for Haskell projects written in Rust. It loads a GHCi session and automatically reloads it when source files change, providing fast feedback during Haskell development. |
| 8 | + |
| 9 | +## Common Development Commands |
| 10 | + |
| 11 | +### Build |
| 12 | +```bash |
| 13 | +cargo build # Build debug version |
| 14 | +cargo build --release # Build optimized release version |
| 15 | +``` |
| 16 | + |
| 17 | +### Test |
| 18 | +```bash |
| 19 | +cargo nextest run # Run tests with nextest (preferred, faster) |
| 20 | +cargo test # Alternative test runner |
| 21 | +cargo llvm-cov nextest # Run tests with coverage |
| 22 | +``` |
| 23 | + |
| 24 | +### Lint & Format |
| 25 | +```bash |
| 26 | +cargo clippy # Run linter |
| 27 | +cargo fmt # Format code |
| 28 | +cargo check # Check compilation without building |
| 29 | +``` |
| 30 | + |
| 31 | +### Documentation |
| 32 | +```bash |
| 33 | +cargo doc --document-private-items --no-deps --workspace # Generate API docs |
| 34 | +cargo run --features clap-markdown -- --generate-markdown-help > docs/cli.md # Update CLI docs |
| 35 | +mdbook build docs # Build user manual |
| 36 | +``` |
| 37 | + |
| 38 | +## High-Level Architecture |
| 39 | + |
| 40 | +The codebase follows a modular architecture with clear separation of concerns: |
| 41 | + |
| 42 | +### Core Components |
| 43 | + |
| 44 | +1. **Main Entry Point** (`src/main.rs`, `src/lib.rs`): Initializes the application, parses CLI arguments, and orchestrates the three main subsystems below. |
| 45 | + |
| 46 | +2. **GHCi Management** (`src/ghci/`): |
| 47 | + - `manager.rs`: Handles lifecycle of the GHCi process including startup, shutdown, and reload coordination |
| 48 | + - `process.rs`: Manages the actual GHCi subprocess |
| 49 | + - `stdin.rs`, `stdout.rs`, `stderr.rs`: Handle I/O streams from GHCi |
| 50 | + - `parse/`: Contains parsers for GHCi output including error messages, module information, and evaluation comments |
| 51 | + - `warning_tracker.rs`: Tracks and manages GHC warnings across reloads |
| 52 | + |
| 53 | +3. **File Watching** (`src/watcher.rs`): Monitors filesystem changes and triggers reload events. Uses the `notify` crate for cross-platform file watching. |
| 54 | + |
| 55 | +4. **TUI (Terminal UI)** (`src/tui/`): Optional terminal interface for displaying compilation results in a structured format using ratatui. |
| 56 | + |
| 57 | +### Key Architectural Patterns |
| 58 | + |
| 59 | +- **Async/Await**: Uses Tokio for concurrent operations, allowing GHCi process management, file watching, and UI updates to run simultaneously |
| 60 | +- **Channel-based Communication**: Components communicate via mpsc channels (e.g., `WatcherEvent` sent from watcher to GHCi manager) |
| 61 | +- **Graceful Shutdown**: `ShutdownManager` coordinates clean shutdown across all subsystems |
| 62 | +- **Hook System** (`src/hooks.rs`): Extensible lifecycle hooks allow running custom commands at various points (startup, before/after reload, etc.) |
| 63 | + |
| 64 | +### Data Flow |
| 65 | + |
| 66 | +1. File watcher detects changes → sends `WatcherEvent` to GHCi manager |
| 67 | +2. GHCi manager processes event → sends reload command to GHCi process |
| 68 | +3. GHCi output is parsed → compilation results displayed to user |
| 69 | +4. Lifecycle hooks execute at appropriate points |
| 70 | +5. TUI (if enabled) continuously updates display with latest compilation state |
| 71 | + |
| 72 | +## Development Notes |
| 73 | + |
| 74 | +- The project uses Nix for development environment setup (`nix develop`) |
| 75 | +- Integration tests in `tests/` require a Haskell toolchain (GHC, cabal, hpack) |
| 76 | +- Test harness is in `test-harness/` workspace member |
| 77 | +- Minimum supported Rust version appears to be 1.72 based on dependency constraints |
0 commit comments