Open david-christiansen opened 4 years ago
I tried to implement this, but there are some bummers:
do
is not on the same line in the original input, there may be reasons for that. For example there may be a comment between equal sign and the do block. If we try to force hanging placement in that case, the comment would shift do
to the next line and indentation will be incorrect. If we preserve the layout (that is, equal sign and do
remain on different lines) everything is fine.-- Real failure, QuickCheck, before:
case res of
MkResult{ok = Just True} -> -- successful test
do continue doneTesting
st'{ numSuccessTests = numSuccessTests st' + 1
, numRecentlyDiscardedTests = 0
, randomSeed = rnd2
} f
-- After:
case res of
MkResult {ok = Just True} ->
-- successful test
do
continue
doneTesting
st'
{ numSuccessTests = numSuccessTests st' + 1,
numRecentlyDiscardedTests = 0,
randomSeed = rnd2
}
f
Granted, one could argue that the way Ormolu handles comments is not perfect, but in this case it looks like respecting original placement is the best thing to do. In the end, what Ormolu does right now is good, because the do section starts at 4-th column instead of 5th.
It looks as though Ormolu prefers the trailing-style
do
instead of the expression-styledo
. That is,instead of
However, formatting the latter results in the following:
which seems to necessitate a manual pass to move all
do
keywords up to the previous line before automatically formatting. Perhaps an exemption from "respect the user's newlines" is in order in this particular case?