-
-
Notifications
You must be signed in to change notification settings - Fork 10
Description
What's happening?
We have two commands (neo build and neo shell) that do almost the exact same thing! They both have about 60 lines of identical code that:
- Sets up your project configuration
- Finds all your Haskell modules
- Generates project files (Cabal, Nix, etc.)
- Writes everything to disk
The only difference? The last line:
neo build→ runsnix-buildto compile your projectneo shell→ runsnix-shellto give you a development environment
Why this matters to you
Right now, if you want to fix a bug or add a feature to how we set up projects, you'd need to:
- Make the change in
Neo.Build.hs - Copy-paste that exact same change to
Neo.Shell.hs - Hope you didn't miss anything! 🤞
This is the kind of thing that leads to subtle bugs where one command works slightly differently than the other.
The fix (spoiler: it's straightforward!)
Let's create a shared helper module that both commands can use. Think of it like extracting a function in your IDE, but at the module level.
Step 1: Create a new module
Create cli/src/Neo/Build/Common.hs (or ProjectSetup.hs - we're flexible on naming!)
Step 2: Move the shared code
Extract these shared pieces from both files:
-- All of this is currently duplicated:
- Project path setup
- Module discovery (finding .hs files)
- Template generation
- File writing
- Error handlingStep 3: Update both commands
Make them nice and simple:
-- Neo.Build.hs becomes:
handle config = do
projectFiles <- setupProject config -- New shared function!
-- Just the build-specific part:
Process.run "nix-build" ...
-- Neo.Shell.hs becomes:
handle config = do
projectFiles <- setupProject config -- Same shared function!
-- Just the shell-specific part:
Process.run "nix-shell" ...Getting started
Time estimate: 1-2 hours
You'll be working with:
cli/src/Neo/Build.hs(lines 28-87)cli/src/Neo/Shell.hs(lines 28-87)- Creating:
cli/src/Neo/Build/Common.hs(or similar name)
Good first issue? Yes! This is mostly copy-paste and organizing code. No complex logic changes needed.
How to test your changes
After refactoring:
- Run
neo buildon a test project - should work exactly as before - Run
neo shellon the same project - should also work exactly as before - Both commands should behave identically for the setup phase
Questions?
This is a great refactoring task for getting familiar with the codebase! If you get stuck for more than 15 minutes, hop into our Discord and we'll help you out.
Context: This duplication was spotted during our haskell.nix migration (PR #199). Now's a perfect time to clean it up!