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,12 +40,14 @@ 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 =
lakjsdlajsdljasdlkjasldjasldjasldjalsdjlaskjd lakjsdlajsdljas
lakjsdlajsdljas lakjsdlajsdljas
lakjsdlajsdljas lakjsdlajsdljas

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,7 +306,8 @@ 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)) <-
optionMaybe
[ case divPart of [ case divPart of
Nothing -> Left $ Text.Read.read digits Nothing -> Left $ Text.Read.read digits
Just ddigits -> Just ddigits ->
@ -317,8 +319,9 @@ parserCompactLocation =
] ]
#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
@ -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 -> max (defLen - 0.05) (defLen * 0.95) -- TODO | otherwise
-> max (defLen - 0.05) (defLen * 0.95) -- TODO
return True return True
#test issue 49 #test issue 49
@ -656,7 +661,8 @@ jaicyhHumzo btrKpeyiFej mava = do
#test issue 214 #test issue 214
-- brittany { lconfig_indentPolicy: IndentPolicyMultiple } -- brittany { lconfig_indentPolicy: IndentPolicyMultiple }
foo = bar foo =
bar
arg1 -- this is the first argument arg1 -- this is the first argument
arg2 -- this is the second argument arg2 -- this is the second argument
arg3 -- this is the third argument, now I'll skip one comment arg3 -- this is the third argument, now I'll skip one comment

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,12 +504,14 @@ 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 =
lakjsdlajsdljasdlkjasldjasldjasldjalsdjlaskjd
lakjsdlajsdljas lakjsdlajsdljas
lakjsdlajsdljas lakjsdlajsdljas
lakjsdlajsdljas lakjsdlajsdljas
@ -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,7 +1253,8 @@ 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)) <-
optionMaybe
[ case divPart of [ case divPart of
Nothing -> Left $ Text.Read.read digits Nothing -> Left $ Text.Read.read digits
Just ddigits -> Just ddigits ->
@ -1264,7 +1266,9 @@ parserCompactLocation =
] ]
#test opapp-specialcasing-1 #test opapp-specialcasing-1
func = fooooooooooooooooooooooooooooooooo $ foooooooooooooooooooooooooooooooo func =
fooooooooooooooooooooooooooooooooo
$ foooooooooooooooooooooooooooooooo
foooooooooooooooooooooooooooooooo foooooooooooooooooooooooooooooooo
foooooooooooooooooooooooooooooooo foooooooooooooooooooooooooooooooo
@ -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 -> max (defLen - 0.05) (defLen * 0.95) -- TODO | otherwise
-> max (defLen - 0.05) (defLen * 0.95) -- TODO
return True return True
#test issue 49 #test issue 49

View File

@ -34,7 +34,8 @@ 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 =
asdyf8asdf
"ajsdfas" "ajsdfas"
[ asjdf asyhf $ do [ asjdf asyhf $ do
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, [ToBriDocM BriDocNumbered]) -> (LHsExpr GhcPs, [(EpAnnCO, LHsExpr GhcPs)])
gather list = \case gather list = \case
L _ (HsApp epAnn l r) -> gather L _ (HsApp epAnn l r) -> gather ((epAnn, r) : list) l
(docHandleComms epAnn $ layoutExpr r : list) l
x -> (x, list) x -> (x, list)
let (headE, paramEs) = gather let (headE, paramEs) = gather [] lexpr
[] let colsOrSequence = case headE of
lexpr
let
colsOrSequence = case headE of
L _ (HsVar _ (L _ (Unqual occname))) -> L _ (HsVar _ (L _ (Unqual occname))) ->
docCols (ColApp $ Text.pack $ occNameString occname) docCols (ColApp $ Text.pack $ occNameString occname)
_ -> docSeq _ -> docSeq
headDoc <- shareDoc $ layoutExpr headE headDoc <- shareDoc $ layoutExpr headE
paramDocs <- shareDoc `mapM` paramEs paramDocs <- forM paramEs $ \(epAnn, e) ->
shareDoc $ docHandleComms epAnn $ layoutExpr e
let hasComments = hasAnyCommentsConnected exp1 let hasComments = hasAnyCommentsConnected exp1
runFilteredAlternative $ do runFilteredAlternative $ do
-- foo x y -- foo x y
@ -195,7 +191,14 @@ layoutExpr lexpr@(L _ expr) = do
-- foo -- foo
-- x -- x
-- y -- y
addAlternative $ docSetParSpacing $ docAddBaseY BrIndentRegular $ docPar addAlternative $ do
let checkAllowPar = \case
(_, 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) (docForceSingleline headDoc)
(docNonBottomSpacing $ docLines paramDocs) (docNonBottomSpacing $ docLines paramDocs)
-- ( multi -- ( multi
@ -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