Minor refactoring

imports-sorted
Lennart Spitzner 2020-04-05 15:30:12 +02:00
parent 5508817cb0
commit f302574bde
3 changed files with 29 additions and 20 deletions

View File

@ -156,7 +156,9 @@ layoutBriDocM = \case
BDAnnotationPrior annKey bd -> do BDAnnotationPrior annKey bd -> do
state <- mGet state <- mGet
let m = _lstate_comments state let m = _lstate_comments state
let allowMTEL = Data.Either.isRight (_lstate_curYOrAddNewline state) let moveToExactLocationAction = case _lstate_curYOrAddNewline state of
Left{} -> pure ()
Right{} -> moveToExactAnn annKey
mAnn <- do mAnn <- do
let mAnn = ExactPrint.annPriorComments <$> Map.lookup annKey m let mAnn = ExactPrint.annPriorComments <$> Map.lookup annKey m
mSet $ state mSet $ state
@ -167,8 +169,8 @@ layoutBriDocM = \case
} }
return mAnn return mAnn
case mAnn of case mAnn of
Nothing -> when allowMTEL $ moveToExactAnn annKey Nothing -> moveToExactLocationAction
Just [] -> when allowMTEL $ moveToExactAnn annKey Just [] -> moveToExactLocationAction
Just priors -> do Just priors -> do
-- layoutResetSepSpace -- layoutResetSepSpace
priors priors
@ -184,7 +186,7 @@ layoutBriDocM = \case
-- layoutMoveToIndentCol y -- layoutMoveToIndentCol y
layoutWriteAppendMultiline commentLines layoutWriteAppendMultiline commentLines
-- mModify $ \s -> s { _lstate_curYOrAddNewline = Right 0 } -- mModify $ \s -> s { _lstate_curYOrAddNewline = Right 0 }
when allowMTEL $ moveToExactAnn annKey moveToExactLocationAction
layoutBriDocM bd layoutBriDocM bd
BDAnnotationKW annKey keyword bd -> do BDAnnotationKW annKey keyword bd -> do
layoutBriDocM bd layoutBriDocM bd
@ -373,7 +375,7 @@ briDocIsMultiLine briDoc = rec briDoc
BDSetParSpacing bd -> rec bd BDSetParSpacing bd -> rec bd
BDForceParSpacing bd -> rec bd BDForceParSpacing bd -> rec bd
BDNonBottomSpacing _ bd -> rec bd BDNonBottomSpacing _ bd -> rec bd
BDDebug _ bd -> rec bd BDDebug _ bd -> rec bd
-- In theory -- In theory
-- ========= -- =========

View File

@ -28,6 +28,7 @@ module Language.Haskell.Brittany.Internal.BackendUtils
, layoutMoveToCommentPos , layoutMoveToCommentPos
, layoutIndentRestorePostComment , layoutIndentRestorePostComment
, moveToExactAnn , moveToExactAnn
, moveToY
, ppmMoveToExactLoc , ppmMoveToExactLoc
, layoutWritePriorComments , layoutWritePriorComments
, layoutWritePostComments , layoutWritePostComments
@ -469,20 +470,23 @@ moveToExactAnn annKey = do
-- curY <- mGet <&> _lstate_curY -- curY <- mGet <&> _lstate_curY
let ExactPrint.DP (y, _x) = ExactPrint.annEntryDelta ann let ExactPrint.DP (y, _x) = ExactPrint.annEntryDelta ann
-- mModify $ \state -> state { _lstate_addNewline = Just x } -- mModify $ \state -> state { _lstate_addNewline = Just x }
mModify $ \state -> moveToY y
let upd = case _lstate_curYOrAddNewline state of
Left i -> if y == 0 then Left i else Right y moveToY :: MonadMultiState LayoutState m => Int -> m ()
Right i -> Right $ max y i moveToY y = mModify $ \state ->
in state let upd = case _lstate_curYOrAddNewline state of
{ _lstate_curYOrAddNewline = upd Left i -> if y == 0 then Left i else Right y
, _lstate_addSepSpace = if Data.Either.isRight upd Right i -> Right $ max y i
then in state
_lstate_commentCol state { _lstate_curYOrAddNewline = upd
<|> _lstate_addSepSpace state , _lstate_addSepSpace = if Data.Either.isRight upd
<|> Just (lstate_baseY state) then
else Nothing _lstate_commentCol state
, _lstate_commentCol = Nothing <|> _lstate_addSepSpace state
} <|> Just (lstate_baseY state)
else Nothing
, _lstate_commentCol = Nothing
}
-- fixMoveToLineByIsNewline :: MonadMultiState -- fixMoveToLineByIsNewline :: MonadMultiState
-- LayoutState m => Int -> m Int -- LayoutState m => Int -> m Int
-- fixMoveToLineByIsNewline x = do -- fixMoveToLineByIsNewline x = do

View File

@ -73,6 +73,8 @@ module Language.Haskell.Brittany.Internal.LayouterBasics
, hasAnyRegularCommentsRest , hasAnyRegularCommentsRest
, hasAnnKeywordComment , hasAnnKeywordComment
, hasAnnKeyword , hasAnnKeyword
, astAnn
, allocNodeIndex
) )
where where
@ -575,7 +577,8 @@ docSeparator = allocateNode BDFSeparator
docAnnotationPrior docAnnotationPrior
:: AnnKey -> ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered :: AnnKey -> ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
docAnnotationPrior annKey bdm = allocateNode . BDFAnnotationPrior annKey =<< bdm docAnnotationPrior annKey bdm =
allocateNode . BDFAnnotationPrior annKey =<< bdm
docAnnotationKW docAnnotationKW
:: AnnKey :: AnnKey