Deny one layout for OpApp cases unless precedence<=1

Previously allowed: `foo = abc + def-as-par`
Still allowed:      `foo = abc $ def-as-par`
Still allowed:      `foo = abc <&> \x -> def-as-par`
ghc92
Lennart Spitzner 2023-05-08 10:51:27 +00:00
parent e7cdff440d
commit 7bf2879ac0
3 changed files with 60 additions and 46 deletions

View File

@ -329,11 +329,13 @@ func =
foooooooooooooooooooooooooooooooo
#test opapp-specialcasing-3
func = fooooooooooooooooooooooooooooooooo + foooooooooooooooooooooooooooooooo
[ foooooooooooooooooooooooooooooooo
, foooooooooooooooooooooooooooooooo
, foooooooooooooooooooooooooooooooo
]
func =
fooooooooooooooooooooooooooooooooo
+ foooooooooooooooooooooooooooooooo
[ foooooooooooooooooooooooooooooooo
, foooooooooooooooooooooooooooooooo
, foooooooooooooooooooooooooooooooo
]
#test opapp-indenting
parserPrim =
@ -966,3 +968,8 @@ func =
)
<$> mylist
)
#test operator newline behaviour
func =
fromIntegral aaaaaaaaaaaaaaaaaaa
/ fromIntegral (aaaaaaaaaaaaaaaaaaa + bbbbbbbbbbbbbbbbbb)

View File

@ -1278,11 +1278,13 @@ func =
foooooooooooooooooooooooooooooooo
#test opapp-specialcasing-3
func = fooooooooooooooooooooooooooooooooo + foooooooooooooooooooooooooooooooo
[ foooooooooooooooooooooooooooooooo
, foooooooooooooooooooooooooooooooo
, foooooooooooooooooooooooooooooooo
]
func =
fooooooooooooooooooooooooooooooooo
+ foooooooooooooooooooooooooooooooo
[ foooooooooooooooooooooooooooooooo
, foooooooooooooooooooooooooooooooo
, foooooooooooooooooooooooooooooooo
]
#test opapp-indenting
parserPrim =

View File

@ -198,6 +198,9 @@ layoutOpTree allowSinglelinePar = \case
pure (pure op, subDoc)
sharedOpsFlat <- flattenList docOps
sharedOps <- simpleTransform docOps
let lastWrap = if getPrec fixity <= 1
then docForceParSpacing
else docForceSingleline
coreAlternative hasParen
locO
locC
@ -205,11 +208,12 @@ layoutOpTree allowSinglelinePar = \case
docL
sharedOps
sharedOpsFlat
docForceParSpacing
lastWrap
OpLeaf l -> pure l
where
isPrec0 = \case
Fixity _ prec _ -> prec == 0
isPrec0 x = getPrec x == 0
getPrec = \case
Fixity _ prec _ -> prec
coreAlternative
:: Bool
-> Maybe GHC.RealSrcLoc
@ -268,33 +272,35 @@ layoutOpTree allowSinglelinePar = \case
$ wrapParenIfSl hasParen
$ docSetParSpacing
$ docSeq
([docForceSingleline docL] ++ case splitFirstLast sharedOpsFlat of
FirstLastEmpty -> []
FirstLastSingleton (od, ed) ->
[docSeparator, docForceSingleline od, docSeparator, lastWrap ed]
FirstLast (od1, ed1) ems (odN, edN) ->
( [ docSeparator
, docForceSingleline od1
, docSeparator
, docForceSingleline ed1
]
++ join
[ [ docSeparator
, docForceSingleline od
([docForceSingleline docL] ++ case splitFirstLast sharedOpsFlat of
FirstLastEmpty -> []
FirstLastSingleton (od, ed) ->
[ docSeparator
, docForceSingleline od
, docSeparator
, lastWrap ed
]
FirstLast (od1, ed1) ems (odN, edN) ->
( [ docSeparator
, docForceSingleline od1
, docSeparator
, docForceSingleline ed
, docForceSingleline ed1
]
| (od, ed) <- ems
]
++ [ docSeparator
, docForceSingleline odN
, docSeparator
, lastWrap edN
]
++ join
[ [ docSeparator
, docForceSingleline od
, docSeparator
, docForceSingleline ed
]
| (od, ed) <- ems
]
++ [ docSeparator
, docForceSingleline odN
, docSeparator
, lastWrap edN
]
)
)
)
-- this case rather leads to some unfortunate layouting than to anything
-- useful; disabling for now. (it interfers with cols stuff.)
-- one
-- + two
-- + three
@ -308,15 +314,14 @@ layoutOpTree allowSinglelinePar = \case
IndentPolicyMultiple -> docForceSingleline
IndentPolicyFree -> id
let curIsPrec0 = case fixity of
Nothing -> False
Nothing -> False
Just (Fixity _ prec _) -> prec == 0
case sharedOps of
[(od, ed)] | curIsPrec0 ->
addAlternativeCond (not hasParen && isSingleOp)
$ docSetParSpacing
$ docPar
(docHandleComms locO $ docForceSingleline $ docL)
(docSeq [od, docSeparator, singlelineUnlessFree ed])
$ docPar (docHandleComms locO $ docForceSingleline $ docL)
(docSeq [od, docSeparator, singlelineUnlessFree ed])
_ -> pure ()
-- > ( one
-- > + two
@ -334,9 +339,9 @@ layoutOpTree allowSinglelinePar = \case
-- > + three
addAlternative
$ wrapParenMlIf
hasParen
hasParen
-- ((if not hasParen then docAddBaseY BrIndentRegular else id) docL)
(if hasParen then docSetBaseY docL else docL)
((if hasParen then sharedOps else sharedOpsFlat) <&> \(od, ed) ->
docCols ColOpPrefix [appSep od, docSetBaseY ed]
)
(if hasParen then docSetBaseY docL else docL)
((if hasParen then sharedOps else sharedOpsFlat) <&> \(od, ed) ->
docCols ColOpPrefix [appSep od, docSetBaseY ed]
)