Skip to content
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

Support for inline comments #39

Open
tesk9 opened this issue Aug 19, 2022 · 3 comments
Open

Support for inline comments #39

tesk9 opened this issue Aug 19, 2022 · 3 comments

Comments

@tesk9
Copy link
Contributor

tesk9 commented Aug 19, 2022

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
	       ]
	    ]
@mdgriffith
Copy link
Owner

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?

@tesk9
Copy link
Contributor Author

tesk9 commented Aug 22, 2022

I love that idea! Adding comments before expressions would definitely work for my purposes

@mdgriffith
Copy link
Owner

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.

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

No branches or pull requests

2 participants