Repository navigation
Support leading arrows - #209
Conversation
|
👋 @3kyro Reviewer: Please verify the following things have been done, if applicable.
|
|
I tried this and get things like: commandCallbacks :: :: [Callback UpdateIssue (Maybe (M.Issue Result)) State] |
Hey, sorry but I'm still in the process of rebasing the original PR, so it's bound to be broken in some way 😃 |
|
Got it 👍 Good luck! Can't wait to play with this one - I'll wait until you're ready 😄 |
e80a57c to
52d4f39
Compare
|
@expipiplus1 I've also created a PR that targets your original branch :) |
|
Thanks, probably best to stick to this PR! Not sure of the value of me merging into my branch at this point haha |
|
Ping. Is this still Wip as the title suggests? |
3190f1a to
70f309a
Compare
@brandonchinn178 I think this PR can be reviewed now. I've added a small set of tests in 9e72445 that should probably be expanded a bit (maybe @expipiplus1 could help :) ) cc @arybczak |
brandonchinn178
left a comment
There was a problem hiding this comment.
Thanks for the PR! Still looking through, left some initial thoughts
| GT | ||
|
|
||
| functionName | ||
| :: (C1, C2, C3, C4, C5) |
There was a problem hiding this comment.
I think there's value in keeping :: next to the identifier: #86 (comment)
Similar to what happened with diff-friendly-import-export, it would be nice if leading-arrows didn't change two things: the placement of :: and the placement of ->. I think it would be more consistent, style-wise, to do something like
foo ::
a
-> String
-> Bool
foo2 ::
Show a =>
a
-> String
-> Bool
foo3 ::
( Show a
, Eq a
) =>
a
-> String
-> Bool
foo4 ::
forall a.
( Show a
, Eq a
) =>
a
-> String
-> BoolMy reasoning:
- The main part of the type
a -> String -> Boolis visually separate from the constraints and is formatted the same, whether there are constraints or not - Keeping the fat arrow with the multiline constraints also avoids a lonely
)on its own line - Similarly, constraints are formatted the same whether there's an explicit
forallor not - Avoids double indenting when constraints are on multiple lines:
-- the constraints are all an extra three spaces over (5 spaces total from `foo`) foo :: ( MonadLogger m , MonadIO m , MonadCatch m , MonadReader MyEnv m ) -- vs. only two spaces from `foo` foo :: ( MonadLogger m , MonadIO m , MonadCatch m , MonadReader MyEnv m )
Thoughts?
There was a problem hiding this comment.
👎 to this IMO. This design has been in the making for more than a year and it would be a real shame to delay it any further over what seems to me like quite a controversial last-minute suggestion.
While I think that a strong argument can be made for keeping :: on the same line as the function name (to aid greppability), I think it would be horrible to end up with something like the following:
foo ::
C =>
D =>
E =>
f
-> g
-> hThis isn't some weird case nobody would ever write, I've observed this pattern in real-world code.
I definitely wouldn't object to a future PR, adding a no-::-or-=> option alongside true and false
There was a problem hiding this comment.
This design has been in the making for more than a year and it would be a real shame to delay it any further over what seems to me like quite a controversial last-minute suggestion.
Where was it discussed for this year? I have seen zero discussion about this, so from my perspective, this is a big design decision that I'm being asked to merge with zero feedback.
There was a problem hiding this comment.
Sorry the the brusque tone! Thank you for the work you're doing.
There was a problem hiding this comment.
Sounds good with me!
There was a problem hiding this comment.
Leaving :: or => dangling will diverge from the style align type stuff on the left. I don't think I've ever seen such code in the wild. Personally, I would be very surprised (and, honestly, annoyed) if applying a "leading-arrows" config to my codebase would produce a diffsplosion introducing the shuffle.
function-arrows: leading/trailing is nice, though.
There was a problem hiding this comment.
The lack of :: on the same line as the symbol being defined has actually made me reconsider whether I want this. I appreciate all the thoughts about how to get that, but I will probably not end up using leading-arrows after all. That said, one more suggestion from a colleague at work was to do things like:
foo :: ()
=> X
-> Y
-> Zwhich I thought was quite clever. You basically always have a => with this style.
There was a problem hiding this comment.
I don't know if this is of topic, of this pull request, but I really like @ocharles suggestion, however it has a drawback, namely that it will introduce syntax to a program. I'm not sure if this is against the goal of the project. You could claim that the user just have to all it themselves, they want even prettier aligning of arrows. This means that the following are both valid formatted functions:
uglyFun ::
a
-> c
prettyFun :: ()
=> a
-> cThe solution do however require that 'preamble' (foralls and constraints) and args are treated differently. namely that the preamble can be on one line while the args are on multiple lines and visa versa, essentially that all of these examples are valid results depending on the indentation of the user:
fun :: forall a b. ( C1, C2 ) => a -> c
fun :: forall a b. ( C1, C2 )
=> a -> c
fun :: forall a b. ( C1, C2 )
=> a
-> c
fun :: forall a b.
( C1, C2 )
=> a -> c
fun :: forall a b.
( C1
, C2
)
=> a -> c
fun :: forall a b.
( C1, C2 )
=> a
-> c
fun :: forall a b.
( C1
, C2
)
=> a
-> c
fun ::
forall a b.
( C1
, C2
)
=> a
-> cbaa4477 to
ea453be
Compare
At what cost though, need to test constraints
ea453be to
4209dc4
Compare
586b9b5 to
8151c59
Compare
|
@brandonchinn178 @expipiplus1 I think I've addressed the initial comments, keeping the existing behavior for |
697ae5a to
9bd0e35
Compare
brandonchinn178
left a comment
There was a problem hiding this comment.
Thanks for getting through all the comments. Just a few more. The trickiest part of this PR is making sure merging Ormolu stuff back isn't going to be a pain. I think if we can resolve the last few comments and utilize scPrevTypeCtx more instead of returning + passing PrevTypeCtx, we'll be able to reduce the diff even more.
| instance Eq Int where | ||
| (==) :: Int -> Int -> Bool | ||
| (==) _ _ = False |
There was a problem hiding this comment.
Continuing conversation from #209 (comment)
Can the "test where type is on one line" be a normal function instead of a class instance? Or possibly one of both? And also add a comment saying "testing one-line type"?
| a <- case tele of | ||
| HsForAllInvis _ bndrs -> p_forallBndrs' ForAllInvis p_hsTyVarBndr bndrs | ||
| HsForAllVis _ bndrs -> p_forallBndrs' ForAllVis p_hsTyVarBndr bndrs | ||
| a' <- | ||
| getPrinterOpt poFunctionArrows >>= \case | ||
| LeadingArrows | multilineArgs -> pure a | ||
| _ -> p_after False a $> TypeCtxStart |
There was a problem hiding this comment.
Instead of threading the PrevTypeCtx everywhere, why not have p_forallBndrs' call a new setPrevTypeCtx function and p_after call getPrevTypeCtx?
| p_rdrName name | ||
| space | ||
| txt "::" | ||
| trailingArrowType -- TODO, the space in tAT wasn't here before |
There was a problem hiding this comment.
what does this TODO mean?
There was a problem hiding this comment.
I'm not sure, maybe @expipiplus1 can help? Seems to not be relevant anymore though so I've removed it.
There was a problem hiding this comment.
honestly no idea, it definitely looks as though there was a space there before... Makes sense to remove it, I guess it was something stale from dev
|
|
||
| -- | Like 'p_hsType' but indent properly following a forall | ||
| p_hsType :: HsType GhcPs -> R () | ||
| p_hsType t = p_hsType' (hasDocStrings t) PipeStyle t |
There was a problem hiding this comment.
how did it work without layout == Multiline here?
There was a problem hiding this comment.
I believe it's needed now for splitting foralls and contraints which can't be handled by interArgBreak as before.
| TypeCtxArgument -> txt "->" >> space | ||
|
|
||
| -- | like p_after but only when we're rendering leading arrows | ||
| p_leadingAfter :: Bool -> PrevTypeCtx -> R () |
There was a problem hiding this comment.
seems like we can inline this?
| then newline | ||
| else breakpoint | ||
| p_hsTypeR = p_hsType' multilineArgs docStyle | ||
| p_hsTypeR prevTypeCtx m = withPrevTypeCtx prevTypeCtx $ do |
There was a problem hiding this comment.
oh if this is the only place withPrevTypeCtx is used, let's just inline it here
There was a problem hiding this comment.
Inlinening it here would require exporting the R constructor from Ormolu.Printer.Internal though. Maybe we can leave it in the Internal module like all the other functions that manipulate the underlying monads of R?
There was a problem hiding this comment.
Actually implementing setPrevTypeCtx makes withPrevTypeCtx obsolete
|
Looks great! Is this ready to merge, or are you still testing? |
I think it can be merged. It would be best to squash the commits though as they are a bit messy due to the rebase. |
|
@brandonchinn178 Do you have an estimate on when we can expect a release? We're quite eager to switch to fourmolu after this 🙂 |
|
I'll make a release within a week. Thanks for the hard work! |
|
Thanks @brandonchinn178 and @3kyro! |
This is the rebasing branch for #95 .
Very much work in progressRemaining items:
Meat/Type