gleam
gleam copied to clipboard
Formatter: Merge duplicate imports
import a
import a.{one}
import a.{two}
Is formatted as
import a.{one, two}
Note imports with an as clause should not be merged.
Hi, I'm interested in this issue.
If import statements are the following,
import a
import b
import a.{one}
import a.{two}
I guess we finally expect such as:
import a.{one, two}
import b
This requires a sort of import statements before the merge. Formatter doesn't sort them currently, so we should implement sort of import statements at first.
What do you think?
Hey @thara! Thanks for helping with Gleam.
Since writing this issue the matter of formatting imports has got slightly more complicated because of a use case for grouping imports so that they can be documented. There's some discussion here https://github.com/gleam-lang/gleam/pull/860
I think to implement this we would need to implement this grouping logic first, which makes it a bigger job. Let me know if you would still be interested in this.
Thanks @lpil, I read #860.
I understood we need to modify AST for grouping imports, i.e. update this language semantics and fix its parser. Sure, this may be a large job for me in my first contribution.
I think we should want to work on this issue after the language designer(you!) update this semantics and parser.
I don't think there's anything to change in the parser or the AST as the information required to detect comments and line breaks is already preserve by the parser. This feature can be implemented purely within the formatter.
Good places to look at are how the formatter writes comments and additional empty lines in blocks.
the AST as the information required to detect comments and line breaks
the formatter writes comments and additional empty lines in blocks.
Oh, I missed it. It seems like I can do it, so I will see it. Thanks!
Just curious, was this closed intentionally or by accident? @lpil
Intentionally, duplicates are no longer valid
Oh that's great. Good!