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
state <- mGet
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
let mAnn = ExactPrint.annPriorComments <$> Map.lookup annKey m
mSet $ state
@ -167,8 +169,8 @@ layoutBriDocM = \case
}
return mAnn
case mAnn of
Nothing -> when allowMTEL $ moveToExactAnn annKey
Just [] -> when allowMTEL $ moveToExactAnn annKey
Nothing -> moveToExactLocationAction
Just [] -> moveToExactLocationAction
Just priors -> do
-- layoutResetSepSpace
priors
@ -184,7 +186,7 @@ layoutBriDocM = \case
-- layoutMoveToIndentCol y
layoutWriteAppendMultiline commentLines
-- mModify $ \s -> s { _lstate_curYOrAddNewline = Right 0 }
when allowMTEL $ moveToExactAnn annKey
moveToExactLocationAction
layoutBriDocM bd
BDAnnotationKW annKey keyword bd -> do
layoutBriDocM bd

View File

@ -28,6 +28,7 @@ module Language.Haskell.Brittany.Internal.BackendUtils
, layoutMoveToCommentPos
, layoutIndentRestorePostComment
, moveToExactAnn
, moveToY
, ppmMoveToExactLoc
, layoutWritePriorComments
, layoutWritePostComments
@ -469,7 +470,10 @@ moveToExactAnn annKey = do
-- curY <- mGet <&> _lstate_curY
let ExactPrint.DP (y, _x) = ExactPrint.annEntryDelta ann
-- 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
Left i -> if y == 0 then Left i else Right y
Right i -> Right $ max y i

View File

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