Improve block-comment behaviour (newlines after or not)

ghc92
Lennart Spitzner 2023-03-26 20:20:45 +00:00
parent 7c329d391b
commit 05270ecb45
2 changed files with 32 additions and 14 deletions

View File

@ -7,7 +7,7 @@ recorddot1 = a.b.c
#test getfield
{-# LANGUAGE OverloadedRecordDot #-}
recorddot2 =
{-before-}a.b.c{-after-}
{-before-} a.b.c {-after-}
#test projection
{-# LANGUAGE OverloadedRecordDot #-}

View File

@ -119,24 +119,42 @@ layoutWriteComment
-> m ()
layoutWriteComment absolute isBlock dp commentLines s = do -- TODO92 we don't move to comment pos at all!
let (y, x) = case dp of
GHC.SameLine c -> (0, c)
GHC.DifferentLine l c -> (l, c)
GHC.SameLine c -> (0, c)
GHC.DifferentLine l c -> (l, c)
state <- mGet
mTell $ Text.Builder.fromString $ replicate y '\n' ++ replicate (if absolute && (y > 0) then x-1 else x) ' '
mTell $ Text.Builder.fromString $ replicate y '\n' ++ replicate
(if absolute && (y > 0) then x - 1 else x)
' '
mTell $ Text.Builder.fromText s
traceLocal ("layoutMoveToCommentPos", y, x, commentLines, _lstate_plannedSpace state, lstate_baseY state)
traceLocal
( "layoutMoveToCommentPos"
, y
, x
, commentLines
, _lstate_plannedSpace state
, lstate_baseY state
)
mSet state
{ _lstate_plannedSpace = if isBlock
then PlannedSameline 0
{ _lstate_plannedSpace = if isBlock
then case _lstate_plannedSpace state of
PlannedNone -> PlannedSameline 1
p@PlannedSameline{} -> p
PlannedNewline l ->
if l <= y then PlannedSameline 1 else PlannedNewline (l - y)
PlannedDelta l i ->
if l <= y then PlannedSameline 1 else PlannedDelta (l - y) i
else case _lstate_plannedSpace state of
PlannedNone -> PlannedDelta 1 (_lstate_curY state)
PlannedSameline i -> PlannedDelta 1 (_lstate_curY state + i)
PlannedNone -> PlannedDelta 1 (_lstate_curY state)
PlannedSameline i -> PlannedDelta 1 (_lstate_curY state + i)
p@PlannedNewline{} -> p
p@PlannedDelta{} -> p
, _lstate_commentNewlines =
_lstate_commentNewlines state + y + commentLines - 1
, _lstate_curY = if y == 0 then _lstate_curY state + x + Text.length s
else x + Text.length s
p@PlannedDelta{} -> p
, _lstate_commentNewlines = _lstate_commentNewlines state
+ y
+ commentLines
- 1
, _lstate_curY = if y == 0
then _lstate_curY state + x + Text.length s
else x + Text.length s
}