elm-codegen
elm-codegen copied to clipboard
Support for inline comments
I'd like to be able to conveniently generate inline comments.
The main use I have for generated Elm code is copy-pastable example code for reusable components. Sometimes these components need to be hooked up to application Msgs in order to do anything. I want to be able to provide example code, but I don't want to write out a bunch of extra TEA wiring, so I will often comment out a non-functional sample implementation.
For example, the generated Elm code that I currently use for a Tabs component example includes commented out code around adding tooltips:
Tabs.build { id = 0, idString = "tab-1" }
[ Tabs.tabString "Tab 1"
, Tabs.panelHtml (text "Panel 1")
, Tabs.withTooltip
[ Tooltip.plaintext "Tab 1"
-- You will need to have a tooltip handler
-- , Tooltip.onToggle ToggleTooltip
, Tooltip.open False
]
]
Yeah, that makes sense.
🤔 I was originally wary of allowing inline comments because I was thinking the design would have to be
inlineComment : String -> Expression
And then I was thinking you could have a weird situation where the generated code isn't valid anymore.
Buuut, what if we had
withComment : String -> Expression -> Expression
So you could insert an inline comment before any expression?
I love that idea! Adding comments before expressions would definitely work for my purposes
So, unfortunately this got more complicated :/ And I think I found the reason that I didn't do this initially
Elm Syntax parses comments into a top level list that organizes things by source position.
Which means we'd have to do some tricky source position math to get this to work. So, not going to happen in the near term.
I did talk to a few people who've had similar comment challenges with elm-syntax though. Maybe it'll get updated!
I'm going to keep this issue open because I would really like to add this.