I’m having trouble understanding how BlankLineWant...
# ktfmt
s
I’m having trouble understanding how BlankLineWanted, genSym(), and breakOp all work together. How do I tell if an expression like
Copy code
blah(
  name = a.b.c.d.e.f.g.h
)
is going to break at any point? It seems that this is partially handled by breaking the expression into parts and then grouping, but I don’t understand the grouping. Also the doc comments are quite confusing in places. or here where I’m confused as to what the groupings actually accomplish. Why is a paired with b, but c is paired with d, with no group between b and c?
n
TBH I don't fully understand that part myself either 😅 cc @David Torosyan in case you could help on this
s
that second link is actually incredibly confusing. It states that there’s 4 expressions even though it then lists 5 and then it proceeds to only group it into 3 😵‍💫
n
I'd say the documentation there needs to be updated. This was done a while ago and maybe it got outdated or just overlooked. I'd be more than happy to accept a PR that fixes just that, in case you have something
s
Haha if I get to the point that I understand it then I will definitely make a PR. as it is, I’m struggling to understand a lot of the formatting code.
n
I've worked with it for a while and TBH that's often the case for myself as well 😅 Using TDD helps me a lot when I'm trying to touch it. I also really like the work from Nick Reid (nreid260) on the trailing commas (https://github.com/facebook/ktfmt/pull/427) and some other parts that I have thought maybe we could use something like that to help us deal with this part of the formatting, in the hope of simplifying things. I haven't looked much into that though, but if you have time and/or want to maybe it's worth looking to see if this could be helpful
d
The confusing bit here was (a) written long ago, (b) rewritten by me, (c) rewritten by Omer. As you can see in some of the summaries, it never made total sense to any of us.
If you want to understand this bit:
BlankLineWanted, genSym(), and breakOp
I'd recommend going directly to google-java-format. Those are all their concepts, all we do is create a tree with those tokens and let them format from there. (except for
genSym
, but that's just a simple helper)
How do I tell if an expression like is going to break at any point?
In general that kind be hard to tell. Whether or not a line breaks depends both on the groupings, but also the allowed line length. GJF is probably your best bet to understand the motiviations. That said, what in particular are you trying to accomplish / understand? I might be able to answer something more targeted.
s
Sorry, been super busy since you responded. You responded to the PR I made around what I’m trying to solve. I am initially adding test cases to demonstrate the issue, but then hope to actually fix it, as I detail in this issue. https://github.com/facebook/ktfmt/issues/482