1
1
mirror of https://github.com/github/semantic.git synced 2024-12-23 23:11:50 +03:00

🔥 Summary’s dependency on Renderer.

This commit is contained in:
Rob Rix 2017-03-31 16:37:08 -04:00
parent 5ee44d4642
commit 45b34c7444
2 changed files with 14 additions and 4 deletions

View File

@ -170,7 +170,7 @@ renderDiff args = case format args of
Patch -> (PatchOutput .) . patch
SExpression -> (SExpressionOutput .) . sExpression TreeOnly
JSON -> json
Summary -> summary
Summary -> (SummaryOutput .) . summary
TOC -> toc
-- | Prints a rendered diff to stdio or a filepath given a parser, arguments and two source blobs.

View File

@ -25,7 +25,6 @@ import qualified Text.PrettyPrint.Leijen.Text as P
import Data.Aeson
import SourceSpan
import Source hiding (null)
import Renderer
import qualified Data.Map as Map
import qualified Data.List as List
@ -101,8 +100,8 @@ data DiffSummary a = DiffSummary {
parentAnnotation :: [Either (Category, Text) (Category, Text)]
} deriving (Eq, Functor, Show, Generic)
summary :: (HasDefaultFields fields) => Renderer (Record fields)
summary blobs diff = SummaryOutput $ Map.fromList [
summary :: HasDefaultFields fields => Both SourceBlob -> Diff (Syntax Text) (Record fields) -> Map Text (Map Text [Value])
summary blobs diff = Map.fromList [
("changes", changes),
("errors", errors)
]
@ -113,6 +112,17 @@ summary blobs diff = SummaryOutput $ Map.fromList [
summaryKey = toSummaryKey (path <$> blobs)
summaries = diffSummaries blobs diff
-- Returns a key representing the filename. If the filenames are different,
-- return 'before -> after'.
toSummaryKey :: Both FilePath -> Text
toSummaryKey = runBothWith $ \before after ->
toS $ case (before, after) of
("", after) -> after
(before, "") -> before
(before, after) | before == after -> after
(before, after) | not (null before) && not (null after) -> before <> " -> " <> after
(_, _) -> mempty
-- Returns a list of diff summary texts given two source blobs and a diff.
diffSummaries :: (StringConv leaf Text, HasDefaultFields fields) => Both SourceBlob -> SyntaxDiff leaf fields -> [JSONSummary Text SourceSpans]
diffSummaries blobs diff = summaryToTexts =<< diffToDiffSummaries (source <$> blobs) diff