Stop using single-line layout for records defs with comms

ghc92
Lennart Spitzner 2023-06-26 15:59:17 +02:00
parent d3d3b90558
commit b6da307ecc
2 changed files with 12 additions and 2 deletions

View File

@ -61,7 +61,6 @@ data
} }
#test record single line layout #test record single line layout
#pending config flag is disabled for now
{-# LANGUAGE ScopedTypeVariables #-} {-# LANGUAGE ScopedTypeVariables #-}
-- brittany { lconfig_allowSinglelineRecord: true } -- brittany { lconfig_allowSinglelineRecord: true }
data MyRecord = forall a . Show a => MyCons { foo :: a -> a, i :: Int } data MyRecord = forall a . Show a => MyCons { foo :: a -> a, i :: Int }
@ -73,6 +72,15 @@ data MyRecord = forall a . Show a => Bar
{ foo :: abittoolongbutnotvery -> abittoolongbutnotvery { foo :: abittoolongbutnotvery -> abittoolongbutnotvery
} }
#test avoid single-line record if there are comments
-- brittany { lconfig_allowSinglelineRecord: true }
data MyRecord = MyRecord
{ a :: Int
-- ^ comment 1
, b :: Int
-- ^ comment 2
}
#test record forall constraint multiline #test record forall constraint multiline
{-# LANGUAGE ScopedTypeVariables #-} {-# LANGUAGE ScopedTypeVariables #-}
data MyRecord data MyRecord

View File

@ -455,7 +455,9 @@ createDetailsDoc consNameStr details = case details of
let ((fName1, fType1), fDocR) = case mkFieldDocs fields of let ((fName1, fType1), fDocR) = case mkFieldDocs fields of
(doc1:docR) -> (doc1, docR) (doc1:docR) -> (doc1, docR)
_ -> error "cannot happen (TM)" _ -> error "cannot happen (TM)"
allowSingleline <- mAsk <&> _conf_layout .> _lconfig_allowSinglelineRecord .> confUnpack allowSingleline <- do
allowViaConf <- mAsk <&> _conf_layout .> _lconfig_allowSinglelineRecord .> confUnpack
pure (allowViaConf && not (hasAnyCommentsBelow epAnn))
docAddBaseY BrIndentRegular $ runFilteredAlternative $ do docAddBaseY BrIndentRegular $ runFilteredAlternative $ do
-- single-line: { i :: Int, b :: Bool } -- single-line: { i :: Int, b :: Bool }
addAlternativeCond allowSingleline $ docSeq addAlternativeCond allowSingleline $ docSeq