Add left indent support for statements
This aligns left indent style `let` statements with their expression form.pull/66/head
parent
de5f0401f3
commit
a13a137f68
|
@ -11,6 +11,7 @@ where
|
||||||
|
|
||||||
import Language.Haskell.Brittany.Internal.Types
|
import Language.Haskell.Brittany.Internal.Types
|
||||||
import Language.Haskell.Brittany.Internal.LayouterBasics
|
import Language.Haskell.Brittany.Internal.LayouterBasics
|
||||||
|
import Language.Haskell.Brittany.Internal.Config.Types
|
||||||
|
|
||||||
import RdrName ( RdrName(..) )
|
import RdrName ( RdrName(..) )
|
||||||
import GHC ( runGhc, GenLocated(L), moduleNameString )
|
import GHC ( runGhc, GenLocated(L), moduleNameString )
|
||||||
|
@ -27,6 +28,7 @@ import {-# SOURCE #-} Language.Haskell.Brittany.Internal.Layouters.Expr
|
||||||
|
|
||||||
layoutStmt :: ToBriDoc' (StmtLR RdrName RdrName (LHsExpr RdrName))
|
layoutStmt :: ToBriDoc' (StmtLR RdrName RdrName (LHsExpr RdrName))
|
||||||
layoutStmt lstmt@(L _ stmt) = do
|
layoutStmt lstmt@(L _ stmt) = do
|
||||||
|
indentPolicy <- mAsk <&> _conf_layout .> _lconfig_indentPolicy .> confUnpack
|
||||||
docWrapNode lstmt $ case stmt of
|
docWrapNode lstmt $ case stmt of
|
||||||
LastStmt body False _ -> do
|
LastStmt body False _ -> do
|
||||||
layoutExpr body
|
layoutExpr body
|
||||||
|
@ -62,15 +64,17 @@ layoutStmt lstmt@(L _ stmt) = do
|
||||||
(docLit $ Text.pack "let")
|
(docLit $ Text.pack "let")
|
||||||
(docSetBaseAndIndent $ return bindDoc)
|
(docSetBaseAndIndent $ return bindDoc)
|
||||||
]
|
]
|
||||||
Just bindDocs -> docAlt
|
Just bindDocs ->
|
||||||
[ docSeq
|
let letSeq = docSeq
|
||||||
[ appSep $ docLit $ Text.pack "let"
|
[ appSep $ docLit $ Text.pack "let"
|
||||||
, docSetBaseAndIndent $ docLines $ return <$> bindDocs
|
, docSetBaseAndIndent $ docLines $ return <$> bindDocs
|
||||||
]
|
]
|
||||||
, docAddBaseY BrIndentRegular $ docPar
|
letRegular = docAddBaseY BrIndentRegular $ docPar
|
||||||
(docLit $ Text.pack "let")
|
(docLit $ Text.pack "let")
|
||||||
(docSetBaseAndIndent $ docLines $ return <$> bindDocs)
|
(docSetBaseAndIndent $ docLines $ return <$> bindDocs)
|
||||||
]
|
in case indentPolicy of
|
||||||
|
IndentPolicyLeft -> docAlt [letRegular]
|
||||||
|
_ -> docAlt [letSeq, letRegular]
|
||||||
RecStmt stmts _ _ _ _ _ _ _ _ _ -> do
|
RecStmt stmts _ _ _ _ _ _ _ _ _ -> do
|
||||||
docSeq
|
docSeq
|
||||||
[ docLit (Text.pack "rec")
|
[ docLit (Text.pack "rec")
|
||||||
|
|
Loading…
Reference in New Issue