Skip to content

Feature/lamdera format #39

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 6 commits into
base: lamdera-next
Choose a base branch
from

Conversation

CharlonTank
Copy link
Collaborator

@CharlonTank CharlonTank commented Jan 25, 2025

Lamdera Compiler (view)
This pull request introduces a new feature to format Elm source files using the lamdera format command. The most important changes include adding the new Lamdera.CLI.Format module, updating existing modules to support the new command, and modifying the Lamdera.CLI module to include the new format command.

New Feature: Elm Source File Formatting

  • Added Lamdera.CLI.Format module to implement the lamdera format command, which includes functionality to format Elm source files, handle various command-line options, and provide usage instructions.
  • Updated Lamdera.CLI module to export the new format function and include the format command in the CLI interface. [1] [2] [3]
  • Modified elm.cabal to include the new Lamdera.CLI.Format module.

Codebase Enhancements

  • Updated Ext.ElmFormat module to support file path input for formatting functions and handle new imports required for formatting Elm source files. [1] [2]
  • Added the new format command to the list of available commands in the main function of terminal/src/Main.hs.

Copy link
Member

@supermario supermario left a comment

Choose a reason for hiding this comment

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

Tested locally, looking good! A few questions.

TIO.putStrLn " lamdera format src/ # format all *.elm files in the src directory\n"
TIO.putStrLn "Full guide to using elm-format at <https://github.com/avh4/elm-format>"
Exit.exitSuccess
else case inputs of
Copy link
Member

Choose a reason for hiding this comment

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

Wondering if it was possible to patch directly into elm-format's existing handling code here rather than replicating it? Or was there some problem doing so?

@CharlonTank CharlonTank force-pushed the feature/lamdera-format branch from 2324e47 to 76cdecd Compare June 25, 2025 18:30
@CharlonTank
Copy link
Collaborator Author

Thanks for the review @supermario! I apologize for the delayed response - it's been several months and I've had a lot on my plate.

I've investigated patching directly into elm-format's CLI handling code as you suggested.

While it would be ideal to reuse elm-format's CLI code directly, I found that the two CLIs have different architectures:

  • Lamdera uses the Terminal module with its own command parsing structure (consistent across all Lamdera commands)
  • elm-format uses a different command-line parsing approach with its own CommandLine.Program monad

Directly integrating would require either:

  1. Special-casing the format command to bypass Lamdera's normal CLI flow, or
  2. Significant refactoring of how Lamdera handles commands

The current implementation:

  • Maintains consistency with other Lamdera commands (same help format, flag handling, etc.)
  • Still uses elm-format's core formatting logic via the ElmFormat.Cli.format API
  • Follows the Lamdera project's minimal-invasion philosophy
  • Makes it easier to maintain when elm-format updates (we only depend on the stable format function API)

That said, if you feel strongly about deeper integration, I'm happy to explore it further. The trade-off would be more coupling with elm-format's internals vs. the current approach of depending only on its public API.

@supermario
Copy link
Member

supermario commented Jun 25, 2025

Special-casing the format command to bypass Lamdera's normal CLI flow

Sounds like exactly what we’re after in this case! Though I realize it may be tricky to have it work with ‘lamdera format ….’ versus ‘elm-format ….’ I.e the extra command, but have a bash, should be possible.

@CharlonTank
Copy link
Collaborator Author

CharlonTank commented Jun 30, 2025

Hey @supermario ! I've implemented the special-case approach as you suggested.

The implementation is minimal - just 11 lines in FormatDirect.hs to call elm-format, and a simple conditional check in Terminal.hs.

@CharlonTank CharlonTank force-pushed the feature/lamdera-format branch from a04a920 to fe36504 Compare June 30, 2025 17:57
As suggested in PR review, the format command now bypasses Lamdera's
normal CLI processing and delegates directly to elm-format's mainIO.
This ensures perfect compatibility with all elm-format features and
reduces code duplication.

Changes:
- Intercept "format" command early in Terminal.hs
- Add minimal FormatDirect module that calls elm-format
- Remove 244-line Format.hs implementation
- Keep stub command for help display consistency
@CharlonTank CharlonTank force-pushed the feature/lamdera-format branch from fe36504 to ab00039 Compare June 30, 2025 18:04
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.

2 participants