Fix non-idempotent newlines with comment + where (#263)
parent
434854f8f3
commit
6724760f40
|
@ -770,3 +770,15 @@ vakjkeSulxudbFokvir = Duotpo
|
||||||
, -- N.B.
|
, -- N.B.
|
||||||
.. -- x
|
.. -- x
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#test issue 263
|
||||||
|
|
||||||
|
func = abc + def
|
||||||
|
-- a
|
||||||
|
-- b
|
||||||
|
|
||||||
|
-- comment
|
||||||
|
|
||||||
|
where
|
||||||
|
abc = 13
|
||||||
|
def = 1
|
||||||
|
|
|
@ -651,6 +651,7 @@ layoutBriDoc briDoc = do
|
||||||
, _lstate_comments = anns
|
, _lstate_comments = anns
|
||||||
, _lstate_commentCol = Nothing
|
, _lstate_commentCol = Nothing
|
||||||
, _lstate_addSepSpace = Nothing
|
, _lstate_addSepSpace = Nothing
|
||||||
|
, _lstate_commentNewlines = 0
|
||||||
}
|
}
|
||||||
|
|
||||||
state' <- MultiRWSS.withMultiStateS state $ layoutBriDocM briDoc'
|
state' <- MultiRWSS.withMultiStateS state $ layoutBriDocM briDoc'
|
||||||
|
|
|
@ -279,12 +279,14 @@ layoutBriDocM = \case
|
||||||
, keyword == kw1
|
, keyword == kw1
|
||||||
]
|
]
|
||||||
-- mTell $ Seq.fromList ["KWDP: " ++ show annKey ++ " " ++ show mAnn]
|
-- mTell $ Seq.fromList ["KWDP: " ++ show annKey ++ " " ++ show mAnn]
|
||||||
pure $ case relevant of
|
case relevant of
|
||||||
[] -> Nothing
|
[] -> pure Nothing
|
||||||
(dp:_) -> Just dp
|
(ExactPrint.Types.DP (y, x):_) -> do
|
||||||
|
mSet state { _lstate_commentNewlines = 0 }
|
||||||
|
pure $ Just (y - _lstate_commentNewlines state, x)
|
||||||
case mDP of
|
case mDP of
|
||||||
Nothing -> pure ()
|
Nothing -> pure ()
|
||||||
Just (ExactPrint.Types.DP (y, x)) ->
|
Just (y, x) ->
|
||||||
layoutMoveToCommentPos y (if shouldRestoreIndent then x else 0)
|
layoutMoveToCommentPos y (if shouldRestoreIndent then x else 0)
|
||||||
layoutBriDocM bd
|
layoutBriDocM bd
|
||||||
BDNonBottomSpacing _ bd -> layoutBriDocM bd
|
BDNonBottomSpacing _ bd -> layoutBriDocM bd
|
||||||
|
|
|
@ -200,6 +200,7 @@ layoutMoveToCommentPos y x = do
|
||||||
Nothing -> case _lstate_curYOrAddNewline state of
|
Nothing -> case _lstate_curYOrAddNewline state of
|
||||||
Left i -> i + fromMaybe 0 (_lstate_addSepSpace state)
|
Left i -> i + fromMaybe 0 (_lstate_addSepSpace state)
|
||||||
Right{} -> lstate_baseY state
|
Right{} -> lstate_baseY state
|
||||||
|
, _lstate_commentNewlines = _lstate_commentNewlines state + y
|
||||||
}
|
}
|
||||||
|
|
||||||
-- | does _not_ add spaces to again reach the current base column.
|
-- | does _not_ add spaces to again reach the current base column.
|
||||||
|
@ -217,6 +218,7 @@ layoutWriteNewline = do
|
||||||
Left{} -> Right 1
|
Left{} -> Right 1
|
||||||
Right i -> Right (i + 1)
|
Right i -> Right (i + 1)
|
||||||
, _lstate_addSepSpace = Nothing
|
, _lstate_addSepSpace = Nothing
|
||||||
|
, _lstate_commentNewlines = 0
|
||||||
}
|
}
|
||||||
|
|
||||||
layoutWriteEnsureNewlineBlock
|
layoutWriteEnsureNewlineBlock
|
||||||
|
@ -574,7 +576,9 @@ layoutIndentRestorePostComment = do
|
||||||
#if INSERTTRACES
|
#if INSERTTRACES
|
||||||
tellDebugMessShow ("layoutIndentRestorePostComment", mCommentCol)
|
tellDebugMessShow ("layoutIndentRestorePostComment", mCommentCol)
|
||||||
#endif
|
#endif
|
||||||
mModify $ \s -> s { _lstate_commentCol = Nothing }
|
mModify $ \s -> s { _lstate_commentCol = Nothing
|
||||||
|
, _lstate_commentNewlines = 0
|
||||||
|
}
|
||||||
case (mCommentCol, eCurYAddNL) of
|
case (mCommentCol, eCurYAddNL) of
|
||||||
(Just commentCol, Left{}) -> do
|
(Just commentCol, Left{}) -> do
|
||||||
layoutWriteEnsureNewlineBlock
|
layoutWriteEnsureNewlineBlock
|
||||||
|
|
|
@ -84,6 +84,11 @@ data LayoutState = LayoutState
|
||||||
-- -- captures if the layouter currently is in a new line, i.e. if the
|
-- -- captures if the layouter currently is in a new line, i.e. if the
|
||||||
-- -- current line only contains (indentation) spaces.
|
-- -- current line only contains (indentation) spaces.
|
||||||
-- this is mostly superseeded by curYOrAddNewline, iirc.
|
-- this is mostly superseeded by curYOrAddNewline, iirc.
|
||||||
|
, _lstate_commentNewlines :: Int -- number of newlines inserted due to
|
||||||
|
-- move-to-DP at a start of a comment.
|
||||||
|
-- Necessary because some keyword DPs
|
||||||
|
-- are relative to the last non-comment
|
||||||
|
-- entity (for some reason)
|
||||||
}
|
}
|
||||||
|
|
||||||
lstate_baseY :: LayoutState -> Int
|
lstate_baseY :: LayoutState -> Int
|
||||||
|
@ -102,6 +107,7 @@ instance Show LayoutState where
|
||||||
++ ",indLevelLinger=" ++ show (_lstate_indLevelLinger state)
|
++ ",indLevelLinger=" ++ show (_lstate_indLevelLinger state)
|
||||||
++ ",commentCol=" ++ show (_lstate_commentCol state)
|
++ ",commentCol=" ++ show (_lstate_commentCol state)
|
||||||
++ ",addSepSpace=" ++ show (_lstate_addSepSpace state)
|
++ ",addSepSpace=" ++ show (_lstate_addSepSpace state)
|
||||||
|
++ ",commentNewlines=" ++ show (_lstate_commentNewlines state)
|
||||||
++ "}"
|
++ "}"
|
||||||
|
|
||||||
-- data NewLineState = NewLineStateInit -- initial state. we do not know if in a
|
-- data NewLineState = NewLineStateInit -- initial state. we do not know if in a
|
||||||
|
|
Loading…
Reference in New Issue