Alternative rules for signatures #94
Labels
No Label
blocked: dependency
blocked: info-needed
bug
duplicate
enhancement
fixed in HEAD
help wanted
hs:arrows
hs:brackets
hs:classes
hs:comments
hs:do-notation
hs:guards
hs:lists
hs:operators
hs:patterns
hs:records
hs:types
invalid
language extension support
layouting
needs confirmation
priority: high
priority: low
question
revisit before next release
wontfix
No Milestone
No project
No Assignees
1 Participants
Notifications
Due Date
No due date set.
Dependencies
No dependencies set.
Reference: hexagoxel/brittany#94
Loading…
Reference in New Issue
There is no content yet.
Delete Branch "%!s(<nil>)"
Deleting a branch is permanent. Although the deleted branch may exist for a short time before cleaning up, in most cases it CANNOT be undone. Continue?
This is probably a stupid question, but nonetheless. Some editors (mostly relying on TextMate grammar model) have trouble with highlighting signatures correctly if
::
operator appears on a different line than identifier itself. FWIW, GitHub also has this problem.Compare:
a.
b.
The question is, can I somehow convince brittany to format this as (b) instead of (a)?
@lierdakil There is no config option for such behaviour. But it seemed trivial to implement, so I quickly added
37e355fea5
. Could you test thehangingtypesig
branch? you'll have to add the new config flag to your user/project brittany config file (lconfig_hangingTypeSignature: true
).Disclaimer: I haven't written proper tests, and won't promise that this works in general or that this will be maintained in the future, because maintaining dozens of layouting special case config options such as this one will become rather time consuming.
Thanks!
Didn't break on my sources, so seems to work
Let me know if you want me to make a PR for that
I would hope that I made a reasonable enough case for why would one want this particular special case. Pretty sure Atom, TextMate and VSCode all have this limitation, and as you can plainly see, so does GitHub itself (that's because it uses Atom's grammar actually, but truth is there's no good alternative to that). Hopefully the deficiency of the grammar model that leads to this problem will be fixed sometime in the future, but in the meantime having
::
put on the second line by prettifiers is rather annoying.Full disclosure, I'm maintaining Haskell grammar for Atom, so I'm obviously biased -- I want brittany (and prettifiers in general) to play nice with that.
@lierdakil Is there anything blocking a fix in Atom's grammar? I also share @lspitzner's fear of ever expanding layout options. This is likely one that people want, but I've seen the
\n ::
style pretty pervasively in the Haskell ecosystem and this should likely be fixed in the upstream tool as well.@eborden yes. It's not a problem with grammar itself, it's a limitation of underlying grammar engine. Here's a TL;DR version: TextMate's grammar model (used also by Atom and VSCode) tokenizes line-by-line and forbids backtracking. Latter is for performance reasons. Hence, no lookaheads beyond current line. Also no arbitrary "state". See referencing issues for more background.
I have some hopes for tree-sitter, which is a proper parsing grammar engine for Atom and is apparently going to be available soon™ (although I believe nobody knows when exactly), but that won't help with other editors.
@lierdakil My editor (sublime-text) breaks too, but I value (visual) consistency (in indentation) and not wasting space for frequently large type signatures over some text colouring.
Well, and I created the commit, did I not? You seem to be missing my point. If 10 users come along with well-reasoned requests for special cases, it still might be too much work for me to maintain the corresponding code, and I wish to clearly communicate this. Repeating the reasoning for your case does not help with that.
Thanks for offering to contribute some tests, but this is blocked until we finish/merge the
inlineconfig
branch. Without that, testing custom configs is rather cumbersome.The details of why these highlighting engines break is interesting, and it is good to hear of better tooling on the horizon.
I'll merge
hangingtypesig
intodev
soon.Preface: it's your project, so your word is final, obviously. I can only give suggestions and try to explain reasoning behind those. Which is exactly what I did, or at least I hope so.
I would argue that (b) in OP "wastes" less space than (a), if we consider vertical space as well, but that's a matter of taste more than anything else.
And I'm very grateful, even if I might be bad at communicating that.
I personally find that "because tooling" is a stronger reason than "because style guide", but you're free to disagree of course. I can't think of a lot of "because tooling" reasons from the top of my head, so I would hope there won't be a lot of special cases like this. I guess it boils down to this request: if you find you have to remove support for some special cases to keep
brittany
maintainable, bear in mind that without this particular one, stuff breaks.Thanks again!
@lierdakil I still wanted to say thanks for reporting this issue and for explaining the reasoning for wanting this feature. It is vital that users give input so that maintainers can make sensible decisions, and I don't want to take away from this. So please don't let my pushing back above discourage you from reporting things in the future.
I finally did a release
0.9.0.1
that contains the additional config flag.