Change behaviour: Less par-spacing for function application

ghc92
Lennart Spitzner 2023-03-19 18:13:06 +00:00
parent 3121ccacfe
commit 83b13d61a0
7 changed files with 125 additions and 107 deletions

View File

@ -40,14 +40,16 @@ describe "app" $ do
func = klajsdas klajsdas klajsdas func = klajsdas klajsdas klajsdas
#test 2 #test 2
func = lakjsdlajsdljasdlkjasldjasldjasldjalsdjlaskjd func =
lakjsdlajsdljasdlkjasldjasldjasldjalsdjlaskjd
lakjsdlajsdljasdlkjasldjasldjasldjalsdjlaskjd lakjsdlajsdljasdlkjasldjasldjasldjalsdjlaskjd
lakjsdlajsdljasdlkjasldjasldjasldjalsdjlaskjd
lakjsdlajsdljasdlkjasldjasldjasldjalsdjlaskjd
#test 3 #test 3
func = lakjsdlajsdljasdlkjasldjasldjasldjalsdjlaskjd lakjsdlajsdljas func =
lakjsdlajsdljas lakjsdlajsdljasdlkjasldjasldjasldjalsdjlaskjd lakjsdlajsdljas
lakjsdlajsdljas lakjsdlajsdljas
lakjsdlajsdljas
### ###
#group expression.basic.sections #group expression.basic.sections

View File

@ -71,12 +71,10 @@ func x
#test multiple-clauses-3 #test multiple-clauses-3
func x func x
| very long guard, another rather long guard that refers to x = nontrivial | very long guard, another rather long guard that refers to x
expression = nontrivial expression foo bar alsdkjlasdjlasj
foo | otherwise
bar = 0
alsdkjlasdjlasj
| otherwise = 0
#test multiple-clauses-4 #test multiple-clauses-4
func x func x

View File

@ -169,9 +169,10 @@ readMergePersConfig path shouldCreate conf = do
Right x -> return x Right x -> return x
return $ fileConf Semigroup.<> conf return $ fileConf Semigroup.<> conf
| shouldCreate -> do | shouldCreate -> do
liftIO $ ByteString.writeFile path $ Data.Yaml.encode $ cMap liftIO
(Option . Just . runIdentity) $ ByteString.writeFile path
staticDefaultConfig $ Data.Yaml.encode
$ cMap (Option . Just . runIdentity) staticDefaultConfig
return $ conf return $ conf
| otherwise -> do | otherwise -> do
return conf return conf
@ -305,21 +306,23 @@ parserCompactLocation =
[ try [ try
$ [ ParseRelAbs (Text.Read.read digits) _ _ $ [ ParseRelAbs (Text.Read.read digits) _ _
| digits <- many1 digit | digits <- many1 digit
, rel1 :: Maybe (Either Int (Ratio Int)) <- optionMaybe , rel1 :: Maybe (Either Int (Ratio Int)) <-
[ case divPart of optionMaybe
Nothing -> Left $ Text.Read.read digits [ case divPart of
Just ddigits -> Nothing -> Left $ Text.Read.read digits
Right $ Text.Read.read digits % Text.Read.read ddigits Just ddigits ->
| digits <- many1 digit Right $ Text.Read.read digits % Text.Read.read ddigits
, divPart <- optionMaybe (string "/" *> many1 digit) | digits <- many1 digit
] , divPart <- optionMaybe (string "/" *> many1 digit)
]
] ]
] ]
#test opapp-specialcasing-1 #test opapp-specialcasing-1
func = fooooooooooooooooooooooooooooooooo $ foooooooooooooooooooooooooooooooo func =
foooooooooooooooooooooooooooooooo fooooooooooooooooooooooooooooooooo
foooooooooooooooooooooooooooooooo $ foooooooooooooooooooooooooooooooo foooooooooooooooooooooooooooooooo
foooooooooooooooooooooooooooooooo
#test opapp-specialcasing-2 #test opapp-specialcasing-2
func = func =
@ -338,8 +341,9 @@ func = fooooooooooooooooooooooooooooooooo + foooooooooooooooooooooooooooooooo
parserPrim = parserPrim =
[ r [ r
| r <- | r <-
[ SGPPrimFloat $ bool id (0 -) minus $ readGnok "parserPrim" [ SGPPrimFloat
(d1 ++ d2 ++ d3 ++ d4) $ bool id (0 -) minus
$ readGnok "parserPrim" (d1 ++ d2 ++ d3 ++ d4)
| d2 <- string "." | d2 <- string "."
, d3 <- many1 (oneOf "0123456789") , d3 <- many1 (oneOf "0123456789")
, _ <- string "f" , _ <- string "f"
@ -444,8 +448,9 @@ layoutPatternBindFinal alignmentToken binderDoc mPatDoc clauseDocs = do
[ docLines [ docLines
$ [ docForceSingleline $ [ docForceSingleline
$ docSeq (patPartInline ++ [guardPart, return binderDoc]) $ docSeq (patPartInline ++ [guardPart, return binderDoc])
, docEnsureIndent BrIndentRegular $ docForceSingleline $ return , docEnsureIndent BrIndentRegular
body $ docForceSingleline
$ return body
] ]
++ wherePartMultiLine ++ wherePartMultiLine
| [(guards, body, _bodyRaw)] <- [clauseDocs] | [(guards, body, _bodyRaw)] <- [clauseDocs]
@ -457,10 +462,10 @@ layoutPatternBindFinal alignmentToken binderDoc mPatDoc clauseDocs = do
func = do func = do
let foo = if let foo = if
| Constuctoooooooooooooooooooooooooooooooooooor `elem` artics -- TODO | Constuctoooooooooooooooooooooooooooooooooooor `elem` artics -- TODO
-> max -> max (defLen - 0.2) -- TODO
(defLen - 0.2) -- TODO (defLen * 0.8)
(defLen * 0.8) | otherwise
| otherwise -> max (defLen - 0.05) (defLen * 0.95) -- TODO -> max (defLen - 0.05) (defLen * 0.95) -- TODO
return True return True
#test issue 49 #test issue 49
@ -656,13 +661,14 @@ jaicyhHumzo btrKpeyiFej mava = do
#test issue 214 #test issue 214
-- brittany { lconfig_indentPolicy: IndentPolicyMultiple } -- brittany { lconfig_indentPolicy: IndentPolicyMultiple }
foo = bar foo =
arg1 -- this is the first argument bar
arg2 -- this is the second argument arg1 -- this is the first argument
arg3 -- this is the third argument, now I'll skip one comment arg2 -- this is the second argument
arg4 arg3 -- this is the third argument, now I'll skip one comment
arg5 -- this is the fifth argument arg4
arg6 -- this is the sixth argument arg5 -- this is the fifth argument
arg6 -- this is the sixth argument
#test issue 234 #test issue 234

View File

@ -430,12 +430,10 @@ func x
#test multiple-clauses-3 #test multiple-clauses-3
func x func x
| very long guard, another rather long guard that refers to x = nontrivial | very long guard, another rather long guard that refers to x
expression = nontrivial expression foo bar alsdkjlasdjlasj
foo | otherwise
bar = 0
alsdkjlasdjlasj
| otherwise = 0
#test multiple-clauses-4 #test multiple-clauses-4
func x func x
@ -506,15 +504,17 @@ describe "app" $ do
func = klajsdas klajsdas klajsdas func = klajsdas klajsdas klajsdas
#test 2 #test 2
func = lakjsdlajsdljasdlkjasldjasldjasldjalsdjlaskjd func =
lakjsdlajsdljasdlkjasldjasldjasldjalsdjlaskjd
lakjsdlajsdljasdlkjasldjasldjasldjalsdjlaskjd lakjsdlajsdljasdlkjasldjasldjasldjalsdjlaskjd
lakjsdlajsdljasdlkjasldjasldjasldjalsdjlaskjd
lakjsdlajsdljasdlkjasldjasldjasldjalsdjlaskjd
#test 3 #test 3
func = lakjsdlajsdljasdlkjasldjasldjasldjalsdjlaskjd func =
lakjsdlajsdljas lakjsdlajsdljasdlkjasldjasldjasldjalsdjlaskjd
lakjsdlajsdljas lakjsdlajsdljas
lakjsdlajsdljas lakjsdlajsdljas
lakjsdlajsdljas
### ###
#group context-free/expression.basic.sections #group context-free/expression.basic.sections
@ -1108,9 +1108,10 @@ readMergePersConfig path shouldCreate conf = do
Right x -> return x Right x -> return x
return $ fileConf Semigroup.<> conf return $ fileConf Semigroup.<> conf
| shouldCreate -> do | shouldCreate -> do
liftIO $ ByteString.writeFile path $ Data.Yaml.encode $ cMap liftIO
(Option . Just . runIdentity) $ ByteString.writeFile path
staticDefaultConfig $ Data.Yaml.encode
$ cMap (Option . Just . runIdentity) staticDefaultConfig
return $ conf return $ conf
| otherwise -> do | otherwise -> do
return conf return conf
@ -1252,21 +1253,24 @@ parserCompactLocation =
[ try [ try
$ [ ParseRelAbs (Text.Read.read digits) _ _ $ [ ParseRelAbs (Text.Read.read digits) _ _
| digits <- many1 digit | digits <- many1 digit
, rel1 :: Maybe (Either Int (Ratio Int)) <- optionMaybe , rel1 :: Maybe (Either Int (Ratio Int)) <-
[ case divPart of optionMaybe
Nothing -> Left $ Text.Read.read digits [ case divPart of
Just ddigits -> Nothing -> Left $ Text.Read.read digits
Right $ Text.Read.read digits % Text.Read.read ddigits Just ddigits ->
| digits <- many1 digit Right $ Text.Read.read digits % Text.Read.read ddigits
, divPart <- optionMaybe (string "/" *> many1 digit) | digits <- many1 digit
] , divPart <- optionMaybe (string "/" *> many1 digit)
]
] ]
] ]
#test opapp-specialcasing-1 #test opapp-specialcasing-1
func = fooooooooooooooooooooooooooooooooo $ foooooooooooooooooooooooooooooooo func =
foooooooooooooooooooooooooooooooo fooooooooooooooooooooooooooooooooo
foooooooooooooooooooooooooooooooo $ foooooooooooooooooooooooooooooooo
foooooooooooooooooooooooooooooooo
foooooooooooooooooooooooooooooooo
#test opapp-specialcasing-2 #test opapp-specialcasing-2
func = func =
@ -1286,9 +1290,9 @@ func = fooooooooooooooooooooooooooooooooo + foooooooooooooooooooooooooooooooo
parserPrim = parserPrim =
[ r [ r
| r <- | r <-
[ SGPPrimFloat $ bool id (0 -) minus $ readGnok [ SGPPrimFloat
"parserPrim" $ bool id (0 -) minus
(d1 ++ d2 ++ d3 ++ d4) $ readGnok "parserPrim" (d1 ++ d2 ++ d3 ++ d4)
| d2 <- string "." | d2 <- string "."
, d3 <- many1 (oneOf "0123456789") , d3 <- many1 (oneOf "0123456789")
, _ <- string "f" , _ <- string "f"
@ -1370,8 +1374,9 @@ layoutPatternBindFinal alignmentToken binderDoc mPatDoc clauseDocs = do
[ docLines [ docLines
$ [ docForceSingleline $ [ docForceSingleline
$ docSeq (patPartInline ++ [guardPart, return binderDoc]) $ docSeq (patPartInline ++ [guardPart, return binderDoc])
, docEnsureIndent BrIndentRegular $ docForceSingleline $ return , docEnsureIndent BrIndentRegular
body $ docForceSingleline
$ return body
] ]
++ wherePartMultiLine ++ wherePartMultiLine
| [(guards, body, _bodyRaw)] <- [clauseDocs] | [(guards, body, _bodyRaw)] <- [clauseDocs]
@ -1384,10 +1389,10 @@ func = do
let let
foo = if foo = if
| Constuctoooooooooooooooooooooooooooooooooooor `elem` artics -- TODO | Constuctoooooooooooooooooooooooooooooooooooor `elem` artics -- TODO
-> max -> max (defLen - 0.2) -- TODO
(defLen - 0.2) -- TODO (defLen * 0.8)
(defLen * 0.8) | otherwise
| otherwise -> max (defLen - 0.05) (defLen * 0.95) -- TODO -> max (defLen - 0.05) (defLen * 0.95) -- TODO
return True return True
#test issue 49 #test issue 49

View File

@ -34,9 +34,10 @@ foo = do
#test nested do-block #test nested do-block
-- brittany { lconfig_indentAmount: 4, lconfig_indentPolicy: IndentPolicyMultiple } -- brittany { lconfig_indentAmount: 4, lconfig_indentPolicy: IndentPolicyMultiple }
foo = asdyf8asdf foo =
"ajsdfas" asdyf8asdf
[ asjdf asyhf $ do "ajsdfas"
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa [ asjdf asyhf $ do
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
] aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
]

View File

@ -545,7 +545,7 @@ layoutPatternBindFinal alignmentToken binderDoc mPatDoc clauses mWhereDocs hasCo
++ wherePartMultiLine ++ wherePartMultiLine
-- multiple clauses, each with the guard(s) in a single line, body -- multiple clauses, each with the guard(s) in a single line, body
-- as a paragraph -- as a paragraph
addAlternative addAlternativeCond (not hasComments)
$ docLines $ docLines
$ [ docAddBaseY BrIndentRegular $ [ docAddBaseY BrIndentRegular
$ patPartParWrap $ patPartParWrap

View File

@ -139,25 +139,21 @@ layoutExpr lexpr@(L _ expr) = do
<$> funcPatDocs <$> funcPatDocs
) )
HsApp _ exp1 _ -> do HsApp _ exp1 _ -> do
let let gather
gather :: [(EpAnnCO, LHsExpr GhcPs)]
:: [ToBriDocM BriDocNumbered] -> LHsExpr GhcPs
-> LHsExpr GhcPs -> (LHsExpr GhcPs, [(EpAnnCO, LHsExpr GhcPs)])
-> (LHsExpr GhcPs, [ToBriDocM BriDocNumbered]) gather list = \case
gather list = \case L _ (HsApp epAnn l r) -> gather ((epAnn, r) : list) l
L _ (HsApp epAnn l r) -> gather x -> (x, list)
(docHandleComms epAnn $ layoutExpr r : list) l let (headE, paramEs) = gather [] lexpr
x -> (x, list) let colsOrSequence = case headE of
let (headE, paramEs) = gather L _ (HsVar _ (L _ (Unqual occname))) ->
[] docCols (ColApp $ Text.pack $ occNameString occname)
lexpr _ -> docSeq
let headDoc <- shareDoc $ layoutExpr headE
colsOrSequence = case headE of paramDocs <- forM paramEs $ \(epAnn, e) ->
L _ (HsVar _ (L _ (Unqual occname))) -> shareDoc $ docHandleComms epAnn $ layoutExpr e
docCols (ColApp $ Text.pack $ occNameString occname)
_ -> docSeq
headDoc <- shareDoc $ layoutExpr headE
paramDocs <- shareDoc `mapM` paramEs
let hasComments = hasAnyCommentsConnected exp1 let hasComments = hasAnyCommentsConnected exp1
runFilteredAlternative $ do runFilteredAlternative $ do
-- foo x y -- foo x y
@ -195,9 +191,16 @@ layoutExpr lexpr@(L _ expr) = do
-- foo -- foo
-- x -- x
-- y -- y
addAlternative $ docSetParSpacing $ docAddBaseY BrIndentRegular $ docPar addAlternative $ do
(docForceSingleline headDoc) let checkAllowPar = \case
(docNonBottomSpacing $ docLines paramDocs) (_, L _ ExplicitTuple{}) -> True
(_, L _ ExplicitList{}) -> True
(_, L _ HsPar{}) -> True
_ -> False
let wrap = if all checkAllowPar paramEs then docSetParSpacing else id
wrap $ docAddBaseY BrIndentRegular $ docPar
(docForceSingleline headDoc)
(docNonBottomSpacing $ docLines paramDocs)
-- ( multi -- ( multi
-- line -- line
-- function -- function
@ -654,11 +657,14 @@ layoutExpr lexpr@(L _ expr) = do
, docAddBaseY BrIndentRegular , docAddBaseY BrIndentRegular
$ docPar elseDoc elseExprDoc $ docPar elseDoc elseExprDoc
] ]
HsMultiIf _ cases -> do HsMultiIf epAnn cases -> do
binderDoc <- docLit $ Text.pack "->" binderDoc <- docLit $ Text.pack "->"
let hasComments = hasAnyCommentsBelow lexpr let hasComments =
hasAnyCommentsBelow epAnn
|| any (\(L _ (GRHS gEpAnn _ _)) -> hasAnyCommentsBelow gEpAnn) cases
let posIf = obtainAnnPos epAnn AnnIf
docSetParSpacing $ docAddBaseY BrIndentRegular $ docPar docSetParSpacing $ docAddBaseY BrIndentRegular $ docPar
(docLit $ Text.pack "if") (docHandleComms posIf $ docLit $ Text.pack "if")
(layoutPatternBindFinal (layoutPatternBindFinal
Nothing Nothing
binderDoc binderDoc