on master help sign in
Handle “prefixed blocks” when they go after an operator
f937aa7mrkkrp
data/examples/declaration/value/function/do-out.hs+6
@@ -20,3 +20,9 @@ baz = do
20 bar c
20 bar c
21 let d = c + 2
21 let d = c + 2
22 return d
22 return d
23+
24+quux =
25+ something $ do
26+ foo
27+ bar
28+ baz
data/examples/declaration/value/function/do.hs+5
@@ -16,3 +16,8 @@ baz = do
16 bar c
16 bar c
17 let d = c + 2
17 let d = c + 2
18 return d
18 return d
19+
20+quux = something $ do
21+ foo
22+ bar
23+ baz
src/Ormolu/Printer/Meat/Declaration/Pat.hs+2−4
@@ -55,10 +55,8 @@ p_pat = \case
55 Nothing -> txt ".."
55 Nothing -> txt ".."
56 Just x -> located x p_hsRecField
56 Just x -> located x p_hsRecField
57 inci . braces . velt . withSep comma f $ case dotdot of
57 inci . braces . velt . withSep comma f $ case dotdot of
58− Nothing ->
59− Just <$> fields
58+ Nothing -> Just <$> fields
60− Just n -> do
61− (Just <$> take n fields) ++ [Nothing]
59+ Just n -> (Just <$> take n fields) ++ [Nothing]
62 InfixCon x y -> do
60 InfixCon x y -> do
63 located x p_pat
61 located x p_pat
64 space
62 space
src/Ormolu/Printer/Meat/Declaration/Value.hs+13−7
@@ -231,7 +231,9 @@ p_hsExpr = \case
231 located x p_hsExpr
231 located x p_hsExpr
232 space
232 space
233 located op p_hsExpr
233 located op p_hsExpr
234+ if isPrefixBlockExpr (unL y)
235+ then space
234− breakpoint
236+ else breakpoint
235 inci (located y p_hsExpr)
237 inci (located y p_hsExpr)
236 NegApp NoExt e _ -> do
238 NegApp NoExt e _ -> do
237 txt "-"
239 txt "-"
@@ -437,10 +439,14 @@ getGRHSSpan (XGRHS NoExt) = notImplemented "XGRHS"
437-- case expressions.
439-- case expressions.
438
440
439isPrefixBlock :: [LGRHS GhcPs (LHsExpr GhcPs)] -> Bool
441isPrefixBlock :: [LGRHS GhcPs (LHsExpr GhcPs)] -> Bool
440−isPrefixBlock [(L _ (GRHS NoExt _ (L _ e)))] =
442+isPrefixBlock [(L _ (GRHS NoExt _ (L _ e)))] = isPrefixBlockExpr e
441− case e of
442− HsLam NoExt _ -> True
443− HsDo NoExt _ _ -> True
444− HsLamCase NoExt _ -> True
445− _ -> False
446isPrefixBlock _ = False
443isPrefixBlock _ = False
444+
445+-- | Similar to 'isPrefixBlock', but just for checking 'HsExpr' directly.
446+
447+isPrefixBlockExpr :: HsExpr GhcPs -> Bool
448+isPrefixBlockExpr = \case
449+ HsLam NoExt _ -> True
450+ HsDo NoExt _ _ -> True
451+ HsLamCase NoExt _ -> True
452+ _ -> False