Minor refactoring
parent
63de13b0b4
commit
614bf3424d
|
@ -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
|
||||
|
@ -373,7 +375,7 @@ briDocIsMultiLine briDoc = rec briDoc
|
|||
BDSetParSpacing bd -> rec bd
|
||||
BDForceParSpacing bd -> rec bd
|
||||
BDNonBottomSpacing _ bd -> rec bd
|
||||
BDDebug _ bd -> rec bd
|
||||
BDDebug _ bd -> rec bd
|
||||
|
||||
-- In theory
|
||||
-- =========
|
||||
|
|
|
@ -28,6 +28,7 @@ module Language.Haskell.Brittany.Internal.BackendUtils
|
|||
, layoutMoveToCommentPos
|
||||
, layoutIndentRestorePostComment
|
||||
, moveToExactAnn
|
||||
, moveToY
|
||||
, ppmMoveToExactLoc
|
||||
, layoutWritePriorComments
|
||||
, layoutWritePostComments
|
||||
|
@ -469,20 +470,23 @@ moveToExactAnn annKey = do
|
|||
-- curY <- mGet <&> _lstate_curY
|
||||
let ExactPrint.DP (y, _x) = ExactPrint.annEntryDelta ann
|
||||
-- mModify $ \state -> state { _lstate_addNewline = Just x }
|
||||
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
|
||||
in state
|
||||
{ _lstate_curYOrAddNewline = upd
|
||||
, _lstate_addSepSpace = if Data.Either.isRight upd
|
||||
then
|
||||
_lstate_commentCol state
|
||||
<|> _lstate_addSepSpace state
|
||||
<|> Just (lstate_baseY state)
|
||||
else Nothing
|
||||
, _lstate_commentCol = Nothing
|
||||
}
|
||||
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
|
||||
in state
|
||||
{ _lstate_curYOrAddNewline = upd
|
||||
, _lstate_addSepSpace = if Data.Either.isRight upd
|
||||
then
|
||||
_lstate_commentCol state
|
||||
<|> _lstate_addSepSpace state
|
||||
<|> Just (lstate_baseY state)
|
||||
else Nothing
|
||||
, _lstate_commentCol = Nothing
|
||||
}
|
||||
-- fixMoveToLineByIsNewline :: MonadMultiState
|
||||
-- LayoutState m => Int -> m Int
|
||||
-- fixMoveToLineByIsNewline x = do
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue