mirror of
https://github.com/github/semantic.git
synced 2024-12-23 23:11:50 +03:00
Swap the order of the operands to splitDiffByLines.
This commit is contained in:
parent
3a555df147
commit
bb00235f4c
@ -37,8 +37,8 @@ hasChanges :: Line (SplitDiff leaf Info) -> Bool
|
||||
hasChanges = or . fmap (or . (True <$))
|
||||
|
||||
-- | Split a diff, which may span multiple lines, into rows of split diffs.
|
||||
splitDiffByLines :: Diff leaf Info -> Both (Source Char) -> [Row (SplitDiff leaf Info, Range)]
|
||||
splitDiffByLines diff sources = case diff of
|
||||
splitDiffByLines :: Both (Source Char) -> Diff leaf Info -> [Row (SplitDiff leaf Info, Range)]
|
||||
splitDiffByLines sources diff = case diff of
|
||||
Free (Annotated annotation syntax) -> splitAnnotatedByLines sources (ranges annotation) (Diff.categories <$> annotation) syntax
|
||||
Pure patch -> splitPatchByLines sources patch
|
||||
where ranges annotations = characterRange <$> annotations
|
||||
@ -81,7 +81,7 @@ splitAnnotatedByLines sources ranges categories syntax = case syntax of
|
||||
fmap (wrapRowContents (makeBranchTerm (\ info -> Free . Annotated info . constructor) <$> categories <*> previous)) . adjoin $ rows ++ (zipWithDefaults makeRow (pure mempty) (fmap (pure . (,) Nothing) <$> (actualLineRanges <$> (Range <$> previous <*> (end <$> ranges)) <*> sources)))
|
||||
|
||||
childRows :: (Copointed f, Functor f) => ([Row (Maybe (f (SplitDiff leaf Info)), Range)], Both Int) -> f (Diff leaf Info) -> ([Row (Maybe (f (SplitDiff leaf Info)), Range)], Both Int)
|
||||
childRows (rows, previous) child = let childRows = splitDiffByLines (copoint child) sources in
|
||||
childRows (rows, previous) child = let childRows = splitDiffByLines sources (copoint child) in
|
||||
-- We depend on source ranges increasing monotonically. If a child invalidates that, e.g. if it’s a move in a Keyed node, we don’t output rows for it in this iteration. (It will still show up in the diff as context rows.) This works around https://github.com/github/semantic-diff/issues/488.
|
||||
if or $ (<) . start <$> (unionLineRangesFrom <$> (rangeAt <$> previous) <*> sequenceA (unRow <$> childRows)) <*> previous
|
||||
then (rows, previous)
|
||||
|
@ -28,7 +28,7 @@ import Term
|
||||
-- | Render a diff to a string representing its JSON.
|
||||
json :: Renderer a ByteString
|
||||
json diff sources = toLazyByteString . fromEncoding . pairs $
|
||||
"rows" .= annotateRows (splitDiffByLines diff (source <$> sources))
|
||||
"rows" .= annotateRows (splitDiffByLines (source <$> sources) diff)
|
||||
<> "oids" .= (oid <$> sources)
|
||||
<> "paths" .= (path <$> sources)
|
||||
where annotateRows = fmap (fmap NumberedLine) . Prelude.reverse . numberedRows
|
||||
|
@ -90,7 +90,7 @@ header blobs hunk = filepathHeader ++ blobOidHeader ++ maybeOffsetHeader
|
||||
-- | Render a diff as a series of hunks.
|
||||
hunks :: Renderer a [Hunk (SplitDiff a Info)]
|
||||
hunks _ blobs | Both (True, True) <- Source.null . source <$> blobs = [Hunk { offset = mempty, changes = [], trailingContext = [] }]
|
||||
hunks diff blobs = hunksInRows (Both (1, 1)) $ fmap Prelude.fst <$> splitDiffByLines diff (source <$> blobs)
|
||||
hunks diff blobs = hunksInRows (Both (1, 1)) $ fmap Prelude.fst <$> splitDiffByLines (source <$> blobs) diff
|
||||
|
||||
-- | Given beginning line numbers, turn rows in a split diff into hunks in a
|
||||
-- | patch.
|
||||
|
@ -61,7 +61,7 @@ split diff blobs = renderHtml
|
||||
. mconcat $ numberedLinesToMarkup <$> reverse numbered
|
||||
where
|
||||
sources = Source.source <$> blobs
|
||||
numbered = numberedRows (fmap Prelude.fst <$> splitDiffByLines diff sources)
|
||||
numbered = numberedRows (fmap Prelude.fst <$> splitDiffByLines sources diff)
|
||||
maxNumber = case numbered of
|
||||
[] -> 0
|
||||
(row : _) -> runBothWith max $ Prelude.fst <$> row
|
||||
|
Loading…
Reference in New Issue
Block a user