Fix calculation of changed lines

This commit is contained in:
Ng Zhi An 2018-12-17 00:19:49 -08:00
parent 7d2c519d64
commit a8d88dfe98
1 changed files with 10 additions and 10 deletions

View File

@ -24,6 +24,7 @@ import ShellCheck.Interface
import ShellCheck.Formatter.Format import ShellCheck.Formatter.Format
import Control.Monad import Control.Monad
import Data.Ord
import Data.IORef import Data.IORef
import Data.List import Data.List
import Data.Maybe import Data.Maybe
@ -156,16 +157,15 @@ fixedString :: PositionedComment -> [String] -> [String]
fixedString comment fileLines = fixedString comment fileLines =
case (pcFix comment) of case (pcFix comment) of
Nothing -> [""] Nothing -> [""]
Just fix -> Just fix -> case (fixReplacements fix) of
let (start, end) = affectedRange (fixReplacements fix) in [] -> []
reps ->
-- applyReplacement returns the full update file, we really only care about the changed lines -- applyReplacement returns the full update file, we really only care about the changed lines
-- so we calculate overlapping lines using replacements -- so we calculate overlapping lines using replacements
drop start $ take end $ applyFix fix fileLines drop start $ take end $ applyFix fix fileLines
where where
affectedRange rs = _affectedRange rs 1 1 start = (fromIntegral $ minimum $ map (posLine . repStartPos) reps) - 1
_affectedRange [] s e = (fromIntegral s, fromIntegral e) end = fromIntegral $ maximum $ map (posLine . repEndPos) reps
_affectedRange (rep:xs) s e =
_affectedRange xs (min s (posLine (repStartPos rep))) (max e (posLine (repEndPos rep)))
cuteIndent :: PositionedComment -> String cuteIndent :: PositionedComment -> String
cuteIndent comment = cuteIndent comment =