mirror of
https://github.com/github/semantic.git
synced 2024-12-21 05:41:54 +03:00
Add language field to JSONSummary
This commit is contained in:
parent
7fdc32b77c
commit
9d2119ffc8
@ -33,6 +33,7 @@ import Data.These
|
|||||||
import Data.Union
|
import Data.Union
|
||||||
import Diff
|
import Diff
|
||||||
import Info
|
import Info
|
||||||
|
import Language
|
||||||
import Patch
|
import Patch
|
||||||
import Prologue
|
import Prologue
|
||||||
import qualified Data.List as List
|
import qualified Data.List as List
|
||||||
@ -62,14 +63,15 @@ data JSONSummary
|
|||||||
{ summaryCategoryName :: Text
|
{ summaryCategoryName :: Text
|
||||||
, summaryTermName :: Text
|
, summaryTermName :: Text
|
||||||
, summarySpan :: Span
|
, summarySpan :: Span
|
||||||
|
, summaryLanguage :: Language
|
||||||
, summaryChangeType :: Text
|
, summaryChangeType :: Text
|
||||||
}
|
}
|
||||||
| ErrorSummary { error :: Text, errorSpan :: Span }
|
| ErrorSummary { error :: Text, errorSpan :: Span, errorLanguage :: Language }
|
||||||
deriving (Generic, Eq, Show)
|
deriving (Generic, Eq, Show)
|
||||||
|
|
||||||
instance ToJSON JSONSummary where
|
instance ToJSON JSONSummary where
|
||||||
toJSON JSONSummary{..} = object [ "changeType" .= summaryChangeType, "category" .= summaryCategoryName, "term" .= summaryTermName, "span" .= summarySpan ]
|
toJSON JSONSummary{..} = object [ "changeType" .= summaryChangeType, "category" .= summaryCategoryName, "term" .= summaryTermName, "span" .= summarySpan, "language" .= summaryLanguage ]
|
||||||
toJSON ErrorSummary{..} = object [ "error" .= error, "span" .= errorSpan ]
|
toJSON ErrorSummary{..} = object [ "error" .= error, "span" .= errorSpan, "language" .= errorLanguage ]
|
||||||
|
|
||||||
isValidSummary :: JSONSummary -> Bool
|
isValidSummary :: JSONSummary -> Bool
|
||||||
isValidSummary ErrorSummary{} = False
|
isValidSummary ErrorSummary{} = False
|
||||||
@ -171,19 +173,19 @@ dedupe = foldl' go []
|
|||||||
similarDeclaration = (==) `on` fmap (toLower . declarationIdentifier) . getDeclaration
|
similarDeclaration = (==) `on` fmap (toLower . declarationIdentifier) . getDeclaration
|
||||||
|
|
||||||
-- | Construct a 'JSONSummary' from an 'Entry'. Returns 'Nothing' for 'Unchanged' patches.
|
-- | Construct a 'JSONSummary' from an 'Entry'. Returns 'Nothing' for 'Unchanged' patches.
|
||||||
entrySummary :: (HasField fields (Maybe Declaration), HasField fields Span) => Entry (Record fields) -> Maybe JSONSummary
|
entrySummary :: (HasField fields (Maybe Declaration), HasField fields Span) => Language -> Entry (Record fields) -> Maybe JSONSummary
|
||||||
entrySummary entry = case entry of
|
entrySummary language entry = case entry of
|
||||||
Unchanged _ -> Nothing
|
Unchanged _ -> Nothing
|
||||||
Changed a -> recordSummary a "modified"
|
Changed a -> recordSummary language a "modified"
|
||||||
Deleted a -> recordSummary a "removed"
|
Deleted a -> recordSummary language a "removed"
|
||||||
Inserted a -> recordSummary a "added"
|
Inserted a -> recordSummary language a "added"
|
||||||
Replaced a -> recordSummary a "modified"
|
Replaced a -> recordSummary language a "modified"
|
||||||
|
|
||||||
-- | Construct a 'JSONSummary' from a node annotation and a change type label.
|
-- | Construct a 'JSONSummary' from a node annotation and a change type label.
|
||||||
recordSummary :: (HasField fields (Maybe Declaration), HasField fields Span) => Record fields -> Text -> Maybe JSONSummary
|
recordSummary :: (HasField fields (Maybe Declaration), HasField fields Span) => Language -> Record fields -> Text -> Maybe JSONSummary
|
||||||
recordSummary record = case getDeclaration record of
|
recordSummary language record = case getDeclaration record of
|
||||||
Just (ErrorDeclaration text) -> Just . const (ErrorSummary text (sourceSpan record))
|
Just (ErrorDeclaration text) -> Just . const (ErrorSummary text (sourceSpan record) language)
|
||||||
Just declaration -> Just . JSONSummary (toCategoryName declaration) (declarationIdentifier declaration) (sourceSpan record)
|
Just declaration -> Just . JSONSummary (toCategoryName declaration) (declarationIdentifier declaration) (sourceSpan record) language
|
||||||
Nothing -> const Nothing
|
Nothing -> const Nothing
|
||||||
|
|
||||||
renderToCDiff :: (HasField fields (Maybe Declaration), HasField fields Span, Traversable f) => Both Blob -> Diff f (Record fields) -> Summaries
|
renderToCDiff :: (HasField fields (Maybe Declaration), HasField fields Span, Traversable f) => Both Blob -> Diff f (Record fields) -> Summaries
|
||||||
@ -201,11 +203,11 @@ renderToCTerm blob = uncurry Summaries . bimap toMap toMap . List.partition isVa
|
|||||||
where toMap [] = mempty
|
where toMap [] = mempty
|
||||||
toMap as = Map.singleton (toS (blobPath blob)) (toJSON <$> as)
|
toMap as = Map.singleton (toS (blobPath blob)) (toJSON <$> as)
|
||||||
|
|
||||||
diffTOC :: (HasField fields (Maybe Declaration), HasField fields Span, Traversable f) => Diff f (Record fields) -> [JSONSummary]
|
diffTOC :: (HasField fields (Maybe Declaration), HasField fields Span, Traversable f) => Language -> Diff f (Record fields) -> [JSONSummary]
|
||||||
diffTOC = mapMaybe entrySummary . dedupe . tableOfContentsBy declaration
|
diffTOC language = mapMaybe (entrySummary language) . dedupe . tableOfContentsBy declaration
|
||||||
|
|
||||||
termToC :: (HasField fields (Maybe Declaration), HasField fields Span, Traversable f) => Term f (Record fields) -> [JSONSummary]
|
termToC :: (HasField fields (Maybe Declaration), HasField fields Span, Traversable f) => Language -> Term f (Record fields) -> [JSONSummary]
|
||||||
termToC = mapMaybe (flip recordSummary "unchanged") . termTableOfContentsBy declaration
|
termToC language = mapMaybe (flip (recordSummary language) "unchanged") . termTableOfContentsBy declaration
|
||||||
|
|
||||||
-- The user-facing category name
|
-- The user-facing category name
|
||||||
toCategoryName :: Declaration -> Text
|
toCategoryName :: Declaration -> Text
|
||||||
|
Loading…
Reference in New Issue
Block a user