From 556bc896a6a6367128be95b49d3f9de4a3126b44 Mon Sep 17 00:00:00 2001 From: Lennart Spitzner Date: Mon, 24 Apr 2023 15:40:15 +0000 Subject: [PATCH] Refactor WriteBriDoc FlushCommentsPrior code slightly --- .../Brittany/Internal/S4_WriteBriDoc.hs | 34 +++++++++---------- 1 file changed, 16 insertions(+), 18 deletions(-) diff --git a/source/library/Language/Haskell/Brittany/Internal/S4_WriteBriDoc.hs b/source/library/Language/Haskell/Brittany/Internal/S4_WriteBriDoc.hs index ff1cfe1..76768db 100644 --- a/source/library/Language/Haskell/Brittany/Internal/S4_WriteBriDoc.hs +++ b/source/library/Language/Haskell/Brittany/Internal/S4_WriteBriDoc.hs @@ -277,24 +277,22 @@ layoutBriDocM = \case comms <- takeBefore loc printComments comms mModify (\s -> s + CommentCounter (length comms)) - do - state <- mGet - mModify $ \s -> s { _lstate_markerForDelta = Nothing } - case _lstate_markerForDelta state of - Just m -> do - let p1 = (srcLocLine m, srcLocCol m) - let p2 = (srcLocLine loc, srcLocCol loc) - let newlinePlanned = case _lstate_plannedSpace state of - PlannedNone -> False - PlannedSameline{} -> False - PlannedNewline{} -> True - PlannedDelta{} -> True - -- traceShow (m, ExactPrint.pos2delta p1 p2) $ pure () - case ExactPrint.pos2delta p1 p2 of - SameLine{} -> pure () - DifferentLine n _ | newlinePlanned -> layoutWriteNewlines n - | otherwise -> pure () - _ -> pure () + mModify $ \s -> s + { _lstate_markerForDelta = Nothing + , _lstate_plannedSpace = case _lstate_markerForDelta s of + Nothing -> _lstate_plannedSpace s + Just m -> + let p1 = (srcLocLine m, srcLocCol m) + p2 = (srcLocLine loc, srcLocCol loc) + -- traceShow (m, ExactPrint.pos2delta p1 p2) $ pure () + in case ExactPrint.pos2delta p1 p2 of + SameLine{} -> _lstate_plannedSpace s + DifferentLine n _ -> case _lstate_plannedSpace s of + PlannedNone -> PlannedNone + PlannedSameline i -> PlannedSameline i + PlannedNewline{} -> PlannedNewline n + PlannedDelta{} -> PlannedNewline n + } layoutBriDocM bd BDFlushCommentsPost loc shouldMark bd -> do layoutBriDocM bd