Refactor WriteBriDoc FlushCommentsPrior code slightly

ghc92
Lennart Spitzner 2023-04-24 15:40:15 +00:00
parent d2a48ba559
commit 556bc896a6
1 changed files with 16 additions and 18 deletions

View File

@ -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