Update OpApp layouting options

- Allow par-spacing for single-operator 1+n-line layout
- Tweak when to flatten operators, i.e. when to allow a flat one-line-each
  layout for the operator sequence "$ $ $ + +".
ghc92
Lennart Spitzner 2023-04-21 12:22:30 +00:00
parent 99e5aacb5e
commit 7ab6a207ae
4 changed files with 34 additions and 15 deletions

View File

@ -2,11 +2,8 @@
#test monad-comprehension-case-of #test monad-comprehension-case-of
func = func = foooooo
foooooo $ [ case foooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo of
$ [ case
foooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo
of
_ -> True _ -> True
] ]

View File

@ -164,14 +164,16 @@ doop =
#expected #expected
-- brittany { lconfig_fixityBasedAddAlignParens: True } -- brittany { lconfig_fixityBasedAddAlignParens: True }
doop = doop =
( some long invocation == loooooooooongman + (third nested expression) - 4 ( ( some long invocation == loooooooooongman + (third nested expression) - 4
&& {- meow -} 5 - 6 > 7 `mod` loooooooooongwoman && {- meow -} 5 - 6 > 7 `mod` loooooooooongwoman
)
|| ill just invoke a function with these args || ill just invoke a function with these args
|| ( foo || ( foo
&& dooasdoiaosdoi ** oaisdoioasido && ( dooasdoiaosdoi ** oaisdoioasido
<= asduiuaisduiasdu + asdahjsd + ahsjdhjhasd <= asduiuaisduiasdu + asdahjsd + ahsjdhjhasd
) )
) )
)
#golden multiline mixed op expression 1 #golden multiline mixed op expression 1
-- brittany { lconfig_fixityBasedAddAlignParens: True } -- brittany { lconfig_fixityBasedAddAlignParens: True }

View File

@ -319,8 +319,7 @@ parserCompactLocation =
] ]
#test opapp-specialcasing-1 #test opapp-specialcasing-1
func = func = fooooooooooooooooooooooooooooooooo
fooooooooooooooooooooooooooooooooo
$ foooooooooooooooooooooooooooooooo foooooooooooooooooooooooooooooooo $ foooooooooooooooooooooooooooooooo foooooooooooooooooooooooooooooooo
foooooooooooooooooooooooooooooooo foooooooooooooooooooooooooooooooo

View File

@ -222,6 +222,7 @@ layoutOpTree allowSinglelinePar = \case
-> ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
coreAlternative hasParen locO locC fixity docL sharedOps sharedOpsFlat lastWrap coreAlternative hasParen locO locC fixity docL sharedOps sharedOpsFlat lastWrap
= do = do
indentPolicy <- askLayoutConf _lconfig_indentPolicy
let wrapParenIfSl x inner = if x then wrapParenSl inner else docSetParSpacing inner let wrapParenIfSl x inner = if x then wrapParenSl inner else docSetParSpacing inner
wrapParenSl inner = docAlt wrapParenSl inner = docAlt
[ docSeq [ docSeq
@ -253,6 +254,8 @@ layoutOpTree allowSinglelinePar = \case
Nothing -> False Nothing -> False
Just (Fixity _ prec _) -> prec > 0 Just (Fixity _ prec _) -> prec > 0
let isSingleOp = length sharedOps == 1 && length sharedOpsFlat == 1
runFilteredAlternative $ do runFilteredAlternative $ do
-- > one + two + three -- > one + two + three
-- or -- or
@ -262,7 +265,7 @@ layoutOpTree allowSinglelinePar = \case
$ wrapParenIfSl hasParen $ wrapParenIfSl hasParen
$ docSetParSpacing $ docSetParSpacing
$ docSeq $ docSeq
([docForceSingleline docL] ++ case splitFirstLast sharedOps of ([docForceSingleline docL] ++ case splitFirstLast sharedOpsFlat of
FirstLastEmpty -> [] FirstLastEmpty -> []
FirstLastSingleton (od, ed) -> FirstLastSingleton (od, ed) ->
[docSeparator, docForceSingleline od, docSeparator, lastWrap ed] [docSeparator, docForceSingleline od, docSeparator, lastWrap ed]
@ -289,11 +292,29 @@ layoutOpTree allowSinglelinePar = \case
) )
-- this case rather leads to some unfortunate layouting than to anything -- this case rather leads to some unfortunate layouting than to anything
-- useful; disabling for now. (it interfers with cols stuff.) -- useful; disabling for now. (it interfers with cols stuff.)
addAlternativeCond (not hasParen) $ docPar -- one
-- + two
-- + three
addAlternativeCond (not hasParen && not isSingleOp) $ docPar
(docHandleComms locO $ docForceSingleline $ docL) (docHandleComms locO $ docForceSingleline $ docL)
(docFlushCommsPost False locC $ docLines $ sharedOps <&> \(od, ed) -> (docFlushCommsPost False locC $ docLines $ sharedOps <&> \(od, ed) ->
docCols ColOpPrefix [appSep od, docForceSingleline ed] docCols ColOpPrefix [appSep od, docForceSingleline ed]
) )
let singlelineUnlessFree = case indentPolicy of
IndentPolicyLeft -> docForceSingleline
IndentPolicyMultiple -> docForceSingleline
IndentPolicyFree -> id
let curIsPrec0 = case fixity of
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])
_ -> pure ()
-- > ( one -- > ( one
-- > + two -- > + two
-- > + three -- > + three