Realign virtual tabs when applying fix

Fix an off-by-one error, in the case that is commented `should never happen`.
It happens when the end of a range is the at the end of a line.
In that case we should update the real column count (probably just by +1)
instead of returning it.

I modified makeNonVirtual to use a helper, realign, that works on
Ranged. That way we can share the code to realign a PositionedComment
and also a Replacement.

Fixes #1420
This commit is contained in:
Ng Zhi An 2018-12-22 15:42:28 +08:00
parent 9acc8fcb53
commit 461be74976
3 changed files with 43 additions and 12 deletions

View file

@ -16,20 +16,38 @@ class Ranged a where
yEnd = end y
xStart = start x
xEnd = end x
-- Set a new start and end position on a Ranged
setRange :: (Position, Position) -> a -> a
instance Ranged PositionedComment where
start = pcStartPos
end = pcEndPos
setRange (s, e) pc = pc {
pcStartPos = s,
pcEndPos = e
}
instance Ranged Replacement where
start = repStartPos
end = repEndPos
setRange (s, e) r = r {
repStartPos = s,
repEndPos = e
}
instance Ranged a => Ranged [a] where
start [] = newPosition
start xs = (minimum . map start) xs
end [] = newPosition
end xs = (maximum . map end) xs
setRange (s, e) rs = map (setRange (s, e)) rs
instance Ranged Fix where
start = start . fixReplacements
end = end . fixReplacements
setRange (s, e) f = f {
fixReplacements = setRange (s, e) (fixReplacements f)
}
-- The Monoid instance for Fix merges replacements that do not overlap.
instance Monoid Fix where