Support same-line let decl when indentAmount>=4
parent
dd53948a23
commit
4973298f30
|
@ -13,7 +13,10 @@ 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 Language.Haskell.Brittany.Internal.Config.Types
|
||||||
|
|
||||||
import GHC ( runGhc, GenLocated(L), moduleNameString )
|
import GHC ( runGhc
|
||||||
|
, GenLocated(L)
|
||||||
|
, moduleNameString
|
||||||
|
)
|
||||||
import HsSyn
|
import HsSyn
|
||||||
import Name
|
import Name
|
||||||
import qualified FastString
|
import qualified FastString
|
||||||
|
@ -28,6 +31,8 @@ import {-# SOURCE #-} Language.Haskell.Brittany.Internal.Layouters.Expr
|
||||||
layoutStmt :: ToBriDoc' (StmtLR GhcPs GhcPs (LHsExpr GhcPs))
|
layoutStmt :: ToBriDoc' (StmtLR GhcPs GhcPs (LHsExpr GhcPs))
|
||||||
layoutStmt lstmt@(L _ stmt) = do
|
layoutStmt lstmt@(L _ stmt) = do
|
||||||
indentPolicy <- mAsk <&> _conf_layout .> _lconfig_indentPolicy .> confUnpack
|
indentPolicy <- mAsk <&> _conf_layout .> _lconfig_indentPolicy .> confUnpack
|
||||||
|
indentAmount :: Int <-
|
||||||
|
mAsk <&> _conf_layout .> _lconfig_indentAmount .> confUnpack
|
||||||
docWrapNode lstmt $ case stmt of
|
docWrapNode lstmt $ case stmt of
|
||||||
LastStmt body False _ -> do
|
LastStmt body False _ -> do
|
||||||
layoutExpr body
|
layoutExpr body
|
||||||
|
@ -47,21 +52,24 @@ layoutStmt lstmt@(L _ stmt) = do
|
||||||
$ docPar (docLit $ Text.pack "<-") (expDoc)
|
$ docPar (docLit $ Text.pack "<-") (expDoc)
|
||||||
]
|
]
|
||||||
]
|
]
|
||||||
LetStmt binds -> layoutLocalBinds binds >>= \case
|
LetStmt binds -> do
|
||||||
Nothing -> docLit $ Text.pack "let" -- i just tested
|
let isFree = indentPolicy == IndentPolicyFree
|
||||||
-- it, and it is
|
let indentFourPlus = indentAmount >= 4
|
||||||
-- indeed allowed.
|
layoutLocalBinds binds >>= \case
|
||||||
-- heh.
|
Nothing -> docLit $ Text.pack "let"
|
||||||
|
-- i just tested the above, and it is indeed allowed. heh.
|
||||||
Just [] -> docLit $ Text.pack "let" -- this probably never happens
|
Just [] -> docLit $ Text.pack "let" -- this probably never happens
|
||||||
Just [bindDoc] -> docAlt
|
Just [bindDoc] -> docAlt
|
||||||
[ -- let bind = expr
|
[ -- let bind = expr
|
||||||
docCols
|
docCols
|
||||||
ColDoLet
|
ColDoLet
|
||||||
[ appSep $ docLit $ Text.pack "let"
|
[ appSep $ docLit $ Text.pack "let"
|
||||||
, let f = case indentPolicy of
|
, let
|
||||||
|
f = case indentPolicy of
|
||||||
IndentPolicyFree -> docSetBaseAndIndent
|
IndentPolicyFree -> docSetBaseAndIndent
|
||||||
IndentPolicyLeft -> docForceSingleline
|
IndentPolicyLeft -> docForceSingleline
|
||||||
IndentPolicyMultiple -> docForceSingleline
|
IndentPolicyMultiple | indentFourPlus -> docSetBaseAndIndent
|
||||||
|
| otherwise -> docForceSingleline
|
||||||
in f $ return bindDoc
|
in f $ return bindDoc
|
||||||
]
|
]
|
||||||
, -- let
|
, -- let
|
||||||
|
@ -74,17 +82,20 @@ layoutStmt lstmt@(L _ stmt) = do
|
||||||
-- let aaa = expra
|
-- let aaa = expra
|
||||||
-- bbb = exprb
|
-- bbb = exprb
|
||||||
-- ccc = exprc
|
-- ccc = exprc
|
||||||
-- TODO: Allow this for IndentPolicyMultiple when indentAmount = 4
|
addAlternativeCond (isFree || indentFourPlus) $ docSeq
|
||||||
addAlternativeCond (indentPolicy == IndentPolicyFree) $ docSeq
|
|
||||||
[ appSep $ docLit $ Text.pack "let"
|
[ appSep $ docLit $ Text.pack "let"
|
||||||
, docSetBaseAndIndent $ docLines $ return <$> bindDocs
|
, let f = if indentFourPlus
|
||||||
|
then docEnsureIndent BrIndentRegular
|
||||||
|
else docSetBaseAndIndent
|
||||||
|
in f $ docLines $ return <$> bindDocs
|
||||||
]
|
]
|
||||||
-- let
|
-- let
|
||||||
-- aaa = expra
|
-- aaa = expra
|
||||||
-- bbb = exprb
|
-- bbb = exprb
|
||||||
-- ccc = exprc
|
-- ccc = exprc
|
||||||
addAlternative $ docAddBaseY BrIndentRegular $ docPar
|
addAlternativeCond (not indentFourPlus)
|
||||||
(docLit $ Text.pack "let")
|
$ docAddBaseY BrIndentRegular
|
||||||
|
$ docPar (docLit $ Text.pack "let")
|
||||||
(docSetBaseAndIndent $ docLines $ return <$> bindDocs)
|
(docSetBaseAndIndent $ docLines $ return <$> bindDocs)
|
||||||
RecStmt stmts _ _ _ _ _ _ _ _ _ -> runFilteredAlternative $ do
|
RecStmt stmts _ _ _ _ _ _ _ _ _ -> runFilteredAlternative $ do
|
||||||
-- rec stmt1
|
-- rec stmt1
|
||||||
|
|
Loading…
Reference in New Issue