Minor refactoring

pull/325/head
Lennart Spitzner 2020-04-05 15:30:12 +02:00 committed by Joe Hermaszewski
parent 63de13b0b4
commit 614bf3424d
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

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,7 +470,10 @@ 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
moveToY :: MonadMultiState LayoutState m => Int -> m ()
moveToY y = mModify $ \state ->
let upd = case _lstate_curYOrAddNewline state of let upd = case _lstate_curYOrAddNewline state of
Left i -> if y == 0 then Left i else Right y Left i -> if y == 0 then Left i else Right y
Right i -> Right $ max y i Right i -> Right $ max y i

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