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:
parent
5ee44d4642
commit
45b34c7444
@ -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.
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user