diff --git a/semantic.cabal b/semantic.cabal index 9c2f77e59..8a36b55be 100644 --- a/semantic.cabal +++ b/semantic.cabal @@ -72,7 +72,6 @@ common dependencies , these >= 0.7 && <1 , unix ^>= 2.7.2.2 , proto-lens == 0.5.1.0 - , proto-lens-json == 0.3.0.0 , proto-lens-runtime == 0.5.0.0 , lingo >= 0.2.0.0 diff --git a/src/Proto/Semantic_JSON.hs b/src/Proto/Semantic_JSON.hs index e8458ec36..cce56fe77 100644 --- a/src/Proto/Semantic_JSON.hs +++ b/src/Proto/Semantic_JSON.hs @@ -2,11 +2,17 @@ {-# OPTIONS_GHC -Wno-orphans #-} module Proto.Semantic_JSON where -import Control.Lens hiding ((.=)) -import Data.Aeson as A -import Data.ProtoLens (defMessage) -import Proto.Semantic as P -import Proto.Semantic_Fields as P +import Control.Lens hiding ((.=)) +import Control.Monad (msum) +import Data.Aeson as A +import qualified Data.Aeson.Encoding as E +import Data.Aeson.Types (parseField) +import Data.ProtoLens (defMessage) +import qualified Data.Text as T +import Prelude hiding (error, span) +import Proto.Semantic as P +import Proto.Semantic_Fields as P + instance FromJSON PingRequest where parseJSON = withObject "PingRequest" $ \obj -> do @@ -41,3 +47,456 @@ instance ToJSON PingResponse where <> "hostname" .= (x^.hostname) <> "timestamp" .= (x^.timestamp) <> "sha" .= (x^.sha) + +instance FromJSON ParseTreeRequest where + parseJSON = withObject "ParseTreeRequest" $ \obj -> do + blobs <- obj .: "blobs" + pure $ defMessage & P.blobs .~ blobs + +instance ToJSON ParseTreeRequest where + toJSON x = object [ "blobs" .= (x^.blobs) ] + toEncoding x = pairs $ "blobs" .= (x^.blobs) + +instance FromJSON Blob where + parseJSON = withObject "Blob" $ \obj -> do + content <- obj .: "content" + path <- obj .: "path" + language <- obj .: "language" + pure $ defMessage + & P.content .~ content + & P.path .~ path + & P.language .~ language + +instance ToJSON Blob where + toJSON x = object + [ "content" .= (x^.content) + , "path" .= (x^.path) + , "language" .= (x^.language) + ] + toEncoding x = pairs $ + "content" .= (x^.content) + <> "path" .= (x^.path) + <> "language" .= (x^.language) + +instance FromJSON ParseTreeSymbolResponse where + parseJSON = withObject "ParseTreeSymbolResponse" $ \obj -> do + files <- obj .: "files" + pure $ defMessage & P.files .~ files + +instance ToJSON ParseTreeSymbolResponse where + toJSON x = object [ "files" .= (x^.files) ] + toEncoding x = pairs $ "files" .= (x^.files) + +instance FromJSON ParseTreeGraphResponse where + parseJSON = withObject "ParseTreeGraphResponse" $ \obj -> do + files <- obj .: "files" + pure $ defMessage & P.files .~ files + +instance ToJSON ParseTreeGraphResponse where + toJSON x = object [ "files" .= (x^.files) ] + toEncoding x = pairs $ "files" .= (x^.files) + +instance FromJSON ParseTreeFileGraph where + parseJSON = withObject "ParseTreeFileGraph" $ \obj -> do + path <- obj .: "path" + language <- obj .: "language" + vertices <- obj .: "vertices" + edges <- obj .: "edges" + errors <- obj .: "errors" + pure $ defMessage + & P.path .~ path + & P.language .~ language + & P.vertices .~ vertices + & P.edges .~ edges + & P.errors .~ errors + +instance ToJSON ParseTreeFileGraph where + toJSON x = object + [ "path" .= (x^.path) + , "language" .= (x^.language) + , "vertices" .= (x^.vertices) + , "edges" .= (x^.edges) + , "errors" .= (x^.errors) + ] + toEncoding x = pairs $ + "path" .= (x^.path) + <> "language" .= (x^.language) + <> "vertices" .= (x^.vertices) + <> "edges" .= (x^.edges) + <> "errors" .= (x^.errors) + +instance FromJSON TermEdge where + parseJSON = withObject "TermEdge" $ \obj -> do + source <- obj .: "source" + target <- obj .: "target" + pure $ defMessage & P.source .~ source & P.target .~ target + +instance ToJSON TermEdge where + toJSON x = object [ "source" .= (x^.source), "target" .= (x^.target) ] + toEncoding x = pairs $ "source" .= (x^.source) <> "target" .= (x^.target) + +instance FromJSON TermVertex where + parseJSON = withObject "TermVertex" $ \obj -> do + vertexId <- obj .: "vertexId" + term <- obj .: "term" + span <- obj .: "span" + pure $ defMessage + & P.vertexId .~ vertexId + & P.term .~ term + & P.span .~ span + +instance ToJSON TermVertex where + toJSON x = object + [ "vertexId" .= (x^.vertexId) + , "term" .= (x^.term) + , "span" .= (x^.span) + ] + toEncoding x = pairs $ + "vertexId" .= (x^.vertexId) + <> "term" .= (x^.term) + <> "span" .= (x^.span) + +instance FromJSON File where + parseJSON = withObject "File" $ \obj -> do + path <- obj .: "path" + language <- obj .: "language" + symbols <- obj .: "symbols" + errors <- obj .: "errors" + blobOid <- obj .: "blobOid" + pure $ defMessage + & P.path .~ path + & P.language .~ language + & P.symbols .~ symbols + & P.errors .~ errors + & P.blobOid .~ blobOid + +instance ToJSON File where + toJSON x = object + [ "path" .= (x^.path) + , "language" .= (x^.language) + , "symbols" .= (x^.symbols) + , "errors" .= (x^.errors) + , "blobOid" .= (x^.blobOid) + ] + toEncoding x = pairs $ + "path" .= (x^.path) + <> "language" .= (x^.language) + <> "symbols" .= (x^.symbols) + <> "errors" .= (x^.errors) + <> "blobOid" .= (x^.blobOid) + +instance FromJSON Symbol where + parseJSON = withObject "Symbol" $ \obj -> do + symbol <- obj .: "symbol" + kind <- obj .: "kind" + line <- obj .: "line" + span <- obj .: "span" + docs <- obj .: "docs" + pure $ defMessage + & P.symbol .~ symbol + & P.kind .~ kind + & P.line .~ line + & P.span .~ span + & P.docs .~ docs + +instance ToJSON Symbol where + toJSON x = object + [ "symbol" .= (x^.symbol) + , "kind" .= (x^.kind) + , "line" .= (x^.line) + , "span" .= (x^.span) + , "docs" .= (x^.docs) + ] + toEncoding x = pairs $ + "symbol" .= (x^.symbol) + <> "kind" .= (x^.kind) + <> "line" .= (x^.line) + <> "span" .= (x^.span) + <> "docs" .= (x^.docs) + +instance FromJSON Span where + parseJSON = withObject "Span" $ \obj -> do + start <- obj .: "start" + end <- obj .: "end" + pure $ defMessage & P.start .~ start & P.end .~ end + +instance ToJSON Span where + toJSON x = object [ "start" .= (x^.start) , "end" .= (x^.end) ] + toEncoding x = pairs $ "start" .= (x^.start) <> "end" .= (x^.end) + +instance FromJSON Position where + parseJSON = withObject "Position" $ \obj -> do + line <- obj .: "line" + column <- obj .: "column" + pure $ defMessage & P.line .~ line & P.column .~ column + +instance ToJSON Position where + toJSON x = object [ "line" .= (x^.line) , "column" .= (x^.column) ] + toEncoding x = pairs $ "line" .= (x^.line) <> "column" .= (x^.column) + +instance FromJSON Docstring where + parseJSON = withObject "Docstring" $ \obj -> do + docstring <- obj .: "docstring" + pure $ defMessage & P.docstring .~ docstring + +instance ToJSON Docstring where + toJSON x = object [ "docstring" .= (x^.docstring) ] + toEncoding x = pairs $ "docstring" .= (x^.docstring) + +instance FromJSON ParseError where + parseJSON = withObject "ParseError" $ \obj -> do + error <- obj .: "error" + pure $ defMessage & P.error .~ error + +instance ToJSON ParseError where + toJSON x = object [ "error" .= (x^.error) ] + toEncoding x = pairs $ "error" .= (x^.error) + +instance FromJSON DiffTreeRequest where + parseJSON = withObject "DiffTreeRequest" $ \obj -> do + blobs <- obj .: "blobs" + pure $ defMessage & P.blobs .~ blobs + +instance ToJSON DiffTreeRequest where + toJSON x = object [ "blobs" .= (x^.blobs) ] + toEncoding x = pairs $ "blobs" .= (x^.blobs) + +instance FromJSON BlobPair where + parseJSON = withObject "BlobPair" $ \obj -> do + before <- obj .: "before" + after <- obj .: "after" + pure $ defMessage & P.before .~ before & P.after .~ after + +instance ToJSON BlobPair where + toJSON x = object [ "before" .= (x^.before), "after" .= (x^.after) ] + toEncoding x = pairs $ "before" .= (x^.before) <> "after" .= (x^.after) + +instance FromJSON DiffTreeTOCResponse where + parseJSON = withObject "DiffTreeTOCResponse" $ \obj -> do + files <- obj .: "files" + pure $ defMessage & P.files .~ files + +instance ToJSON DiffTreeTOCResponse where + toJSON x = object [ "files" .= (x^.files) ] + toEncoding x = pairs $ "files" .= (x^.files) + +instance FromJSON TOCSummaryFile where + parseJSON = withObject "TOCSummaryFile" $ \obj -> do + path <- obj .: "path" + language <- obj .: "language" + changes <- obj .: "changes" + errors <- obj .: "errors" + pure $ defMessage + & P.path .~ path + & P.language .~ language + & P.changes .~ changes + & P.errors .~ errors + +instance ToJSON TOCSummaryFile where + toJSON x = object + [ "path" .= (x^.path) + , "language" .= (x^.language) + , "changes" .= (x^.changes) + , "errors" .= (x^.errors) + ] + toEncoding x = pairs $ + "path" .= (x^.path) + <> "language" .= (x^.language) + <> "changes" .= (x^.changes) + <> "errors" .= (x^.errors) + +instance FromJSON TOCSummaryChange where + parseJSON = withObject "TOCSummaryChange" $ \obj -> do + category <- obj .: "category" + term <- obj .: "term" + span <- obj .: "span" + changeType <- obj .: "changeType" + pure $ defMessage + & P.category .~ category + & P.term .~ term + & P.span .~ span + & P.changeType .~ changeType + +instance ToJSON TOCSummaryChange where + toJSON x = object + [ "category" .= (x^.category) + , "term" .= (x^.term) + , "span" .= (x^.span) + , "changeType" .= (x^.changeType) + ] + toEncoding x = pairs $ + "category" .= (x^.category) + <> "term" .= (x^.term) + <> "span" .= (x^.span) + <> "changeType" .= (x^.changeType) + +instance FromJSON TOCSummaryError where + parseJSON = withObject "TOCSummaryError" $ \obj -> do + error <- obj .: "error" + span <- obj .: "span" + pure $ defMessage & P.error .~ error & P.span .~ span + +instance ToJSON TOCSummaryError where + toJSON x = object [ "error" .= (x^.error), "span" .= (x^.span) ] + toEncoding x = pairs $ "error" .= (x^.error) <> "span" .= (x^.span) + +instance FromJSON ChangeType where + parseJSON (A.String "NONE") = pure NONE + parseJSON (A.String "ADDED") = pure ADDED + parseJSON (A.String "REMOVED") = pure REMOVED + parseJSON (A.String "MODIFIED") = pure MODIFIED + parseJSON _ = fail "unexpected ChangeType" + +instance ToJSON ChangeType where + toJSON x = A.String . T.toUpper . T.pack $ show x + toEncoding x = E.text . T.toUpper . T.pack $ show x + +instance FromJSON DiffTreeGraphResponse where + parseJSON = withObject "DiffTreeGraphResponse" $ \obj -> do + files <- obj .: "files" + pure $ defMessage & P.files .~ files + +instance ToJSON DiffTreeGraphResponse where + toJSON x = object [ "files" .= (x^.files) ] + toEncoding x = pairs $ "files" .= (x^.files) + +instance FromJSON DiffTreeFileGraph where + parseJSON = withObject "DiffTreeFileGraph" $ \obj -> do + path <- obj .: "path" + language <- obj .: "language" + vertices <- obj .: "vertices" + edges <- obj .: "edges" + errors <- obj .: "errors" + pure $ defMessage + & P.path .~ path + & P.language .~ language + & P.vertices .~ vertices + & P.edges .~ edges + & P.errors .~ errors + +instance ToJSON DiffTreeFileGraph where + toJSON x = object + [ "path" .= (x^.path) + , "language" .= (x^.language) + , "vertices" .= (x^.vertices) + , "edges" .= (x^.edges) + , "errors" .= (x^.errors) + ] + toEncoding x = pairs $ + "path" .= (x^.path) + <> "language" .= (x^.language) + <> "vertices" .= (x^.vertices) + <> "edges" .= (x^.edges) + <> "errors" .= (x^.errors) + +instance FromJSON DiffTreeEdge where + parseJSON = withObject "DiffTreeEdge" $ \obj -> do + source <- obj .: "source" + target <- obj .: "target" + pure $ defMessage & P.source .~ source & P.target .~ target + +instance ToJSON DiffTreeEdge where + toJSON x = object [ "source" .= (x^.source), "target" .= (x^.target) ] + toEncoding x = pairs $ "source" .= (x^.source) <> "target" .= (x^.target) + +instance FromJSON DiffTreeVertex where + parseJSON = withObject "DiffTreeVertex" $ \obj -> do + diffVertexId <- obj .: "diffVertexId" + diffTerm <- obj .: "diffTerm" + pure $ defMessage + & P.diffVertexId .~ diffVertexId + & P.maybe'diffTerm .~ diffTerm + +instance ToJSON DiffTreeVertex where + toJSON x = object + [ "diffVertexId" .= (x^.diffVertexId) + , "diffTerm" .= (x^.maybe'diffTerm) + ] + toEncoding x = pairs $ + "diffVertexId" .= (x^.diffVertexId) + <> "diffTerm" .= (x^.maybe'diffTerm) + +instance FromJSON DiffTreeVertex'DiffTerm where + parseJSON = withObject "DiffTreeVertexDiffTerm" $ \obj -> msum + [ + DiffTreeVertex'Deleted <$> parseField obj "deleted" + , DiffTreeVertex'Inserted <$> parseField obj "inserted" + , DiffTreeVertex'Replaced <$> parseField obj "replaced" + , DiffTreeVertex'Merged <$> parseField obj "merged" + ] + +instance ToJSON DiffTreeVertex'DiffTerm where + toJSON (DiffTreeVertex'Deleted x) = object [ "deleted" .= x ] + toJSON (DiffTreeVertex'Inserted x) = object [ "inserted" .= x ] + toJSON (DiffTreeVertex'Replaced x) = object [ "replaced" .= x ] + toJSON (DiffTreeVertex'Merged x) = object [ "merged" .= x ] + toEncoding (DiffTreeVertex'Deleted x) = pairs $ "deleted" .= x + toEncoding (DiffTreeVertex'Inserted x) = pairs $ "inserted" .= x + toEncoding (DiffTreeVertex'Replaced x) = pairs $ "replaced" .= x + toEncoding (DiffTreeVertex'Merged x) = pairs $ "merged" .= x + +instance FromJSON MergedTerm where + parseJSON = withObject "MergedTerm" $ \obj -> do + term <- obj .: "term" + beforeSpan <- obj .: "beforeSpan" + afterSpan <- obj .: "afterSpan" + pure $ defMessage + & P.term .~ term + & P.beforeSpan .~ beforeSpan + & P.afterSpan .~ afterSpan + +instance ToJSON MergedTerm where + toJSON x = object + [ "term" .= (x^.term) + , "beforeSpan" .= (x^.beforeSpan) + , "afterSpan" .= (x^.afterSpan) + ] + toEncoding x = pairs $ + "term" .= (x^.term) + <> "beforeSpan" .= (x^.beforeSpan) + <> "afterSpan" .= (x^.afterSpan) + +instance FromJSON ReplacedTerm where + parseJSON = withObject "ReplacedTerm" $ \obj -> do + beforeTerm <- obj .: "beforeTerm" + beforeSpan <- obj .: "beforeSpan" + afterTerm <- obj .: "afterTerm" + afterSpan <- obj .: "afterSpan" + pure $ defMessage + & P.beforeTerm .~ beforeTerm + & P.beforeSpan .~ beforeSpan + & P.afterTerm .~ afterTerm + & P.afterSpan .~ afterSpan + +instance ToJSON ReplacedTerm where + toJSON x = object + [ "beforeTerm" .= (x^.beforeTerm) + , "beforeSpan" .= (x^.beforeSpan) + , "afterTerm" .= (x^.afterTerm) + , "afterSpan" .= (x^.afterSpan) + ] + toEncoding x = pairs $ + "beforeTerm" .= (x^.beforeTerm) + <> "beforeSpan" .= (x^.beforeSpan) + <> "afterTerm" .= (x^.afterTerm) + <> "afterSpan" .= (x^.afterSpan) + +instance FromJSON InsertedTerm where + parseJSON = withObject "InsertedTerm" $ \obj -> do + term <- obj .: "term" + span <- obj .: "span" + pure $ defMessage & P.term .~ term & P.span .~ span + +instance ToJSON InsertedTerm where + toJSON x = object [ "term" .= (x^.term), "span" .= (x^.span) ] + toEncoding x = pairs $ "term" .= (x^.term) <> "span" .= (x^.span) + +instance FromJSON DeletedTerm where + parseJSON = withObject "DeletedTerm" $ \obj -> do + term <- obj .: "term" + span <- obj .: "span" + pure $ defMessage & P.term .~ term & P.span .~ span + +instance ToJSON DeletedTerm where + toJSON x = object [ "term" .= (x^.term), "span" .= (x^.span) ] + toEncoding x = pairs $ "term" .= (x^.term) <> "span" .= (x^.span) diff --git a/src/Semantic/Api/Diffs.hs b/src/Semantic/Api/Diffs.hs index e34018643..18957a425 100644 --- a/src/Semantic/Api/Diffs.hs +++ b/src/Semantic/Api/Diffs.hs @@ -31,6 +31,7 @@ import Parsing.Parser import Prologue import Proto.Semantic as P hiding (Blob, BlobPair) import Proto.Semantic_Fields as P +import Proto.Semantic_JSON() import Rendering.Graph import Rendering.JSON hiding (JSON) import qualified Rendering.JSON @@ -52,7 +53,7 @@ data DiffOutputFormat parseDiffBuilder :: (Traversable t, DiffEffects sig m) => DiffOutputFormat -> t BlobPair -> m Builder parseDiffBuilder DiffJSONTree = distributeFoldMap (jsonDiff renderJSONTree) >=> serialize Format.JSON -- NB: Serialize happens at the top level for these two JSON formats to collect results of multiple blob pairs. -parseDiffBuilder DiffJSONGraph = diffGraph >=> serialize Format.JSONPB +parseDiffBuilder DiffJSONGraph = diffGraph >=> serialize Format.JSON parseDiffBuilder DiffSExpression = distributeFoldMap sexpDiff parseDiffBuilder DiffShow = distributeFoldMap showDiff parseDiffBuilder DiffDotGraph = distributeFoldMap dotGraphDiff diff --git a/src/Semantic/Api/Terms.hs b/src/Semantic/Api/Terms.hs index 12a9c2ac4..b76ac22ff 100644 --- a/src/Semantic/Api/Terms.hs +++ b/src/Semantic/Api/Terms.hs @@ -35,6 +35,7 @@ import Parsing.Parser import Prologue import Proto.Semantic as P hiding (Blob) import Proto.Semantic_Fields as P +import Proto.Semantic_JSON() import Rendering.Graph import Rendering.JSON hiding (JSON) import qualified Rendering.JSON @@ -87,7 +88,7 @@ data TermOutputFormat parseTermBuilder :: (Traversable t, Member Distribute sig, ParseEffects sig m, MonadIO m) => TermOutputFormat -> t Blob -> m Builder parseTermBuilder TermJSONTree = distributeFoldMap jsonTerm >=> serialize Format.JSON -- NB: Serialize happens at the top level for these two JSON formats to collect results of multiple blobs. -parseTermBuilder TermJSONGraph = termGraph >=> serialize Format.JSONPB +parseTermBuilder TermJSONGraph = termGraph >=> serialize Format.JSON parseTermBuilder TermSExpression = distributeFoldMap sexpTerm parseTermBuilder TermDotGraph = distributeFoldMap dotGraphTerm parseTermBuilder TermShow = distributeFoldMap showTerm diff --git a/src/Semantic/CLI.hs b/src/Semantic/CLI.hs index 7d761e04e..efa8f65fc 100644 --- a/src/Semantic/CLI.hs +++ b/src/Semantic/CLI.hs @@ -32,6 +32,7 @@ import Control.Exception (Exception(..), throwTo) import Data.Typeable (Typeable) import System.Posix.Signals import System.Mem.Weak (deRefWeak) +import Proto.Semantic_JSON() newtype SignalException = SignalException Signal deriving (Show, Typeable) @@ -92,7 +93,7 @@ diffCommand = command "diff" (info diffArgumentsParser (progDesc "Compute change renderer <- flag (parseDiffBuilder DiffSExpression) (parseDiffBuilder DiffSExpression) (long "sexpression" <> help "Output s-expression diff tree (default)") <|> flag' (parseDiffBuilder DiffJSONTree) (long "json" <> help "Output JSON diff trees") <|> flag' (parseDiffBuilder DiffJSONGraph) (long "json-graph" <> help "Output JSON diff trees") - <|> flag' (diffSummaryBuilder JSONPB) (long "toc" <> help "Output JSON table of contents diff summary") + <|> flag' (diffSummaryBuilder JSON) (long "toc" <> help "Output JSON table of contents diff summary") <|> flag' (parseDiffBuilder DiffDotGraph) (long "dot" <> help "Output the diff as a DOT graph") <|> flag' (parseDiffBuilder DiffShow) (long "show" <> help "Output using the Show instance (debug only, format subject to change without notice)") filesOrStdin <- Right <$> some (Both <$> argument filePathReader (metavar "FILE_A") <*> argument filePathReader (metavar "FILE_B")) <|> pure (Left stdin) @@ -119,7 +120,7 @@ parseCommand = command "parse" (info parseArgumentsParser (progDesc "Generate pa <|> flag' (parseTermBuilder TermJSONGraph) ( long "json-graph" <> help "Output JSON adjacency list") - <|> flag' (parseSymbolsBuilder JSONPB) + <|> flag' (parseSymbolsBuilder JSON) ( long "symbols" <> long "json-symbols" <> help "Output JSON symbol list") diff --git a/src/Semantic/Proto/SemanticPB.hs b/src/Semantic/Proto/SemanticPB.hs deleted file mode 100644 index 0a5106edd..000000000 --- a/src/Semantic/Proto/SemanticPB.hs +++ /dev/null @@ -1,1368 +0,0 @@ --- Code generated by protoc-gen-haskell 0.1.0, DO NOT EDIT. -{-# LANGUAGE DerivingVia, DeriveAnyClass, DuplicateRecordFields #-} -{-# OPTIONS_GHC -Wno-unused-imports -Wno-missing-export-lists #-} -module Semantic.Proto.SemanticPB where - -import Control.DeepSeq -import Control.Monad (msum) -import qualified Data.Aeson as A -import qualified Data.Aeson.Encoding as E -import Data.ByteString (ByteString) -import Data.Int -import Data.Text (Text) -import qualified Data.Text as T -import Data.Vector (Vector) -import Data.Word -import GHC.Generics -import Proto3.Suite (decodeMessageField, encodeMessageField, nestedvec, packedvec) -import qualified Proto3.Suite as Proto3 -import Proto3.Suite.JSONPB as JSONPB -import Proto3.Wire (at, oneof) - -data PingRequest = PingRequest - { service :: Text - } deriving stock (Eq, Ord, Show, Generic) - deriving anyclass (Proto3.Named, NFData) - -instance FromJSONPB PingRequest where - parseJSONPB = A.withObject "PingRequest" $ \obj -> PingRequest - <$> obj .: "service" - -instance ToJSONPB PingRequest where - toJSONPB PingRequest{..} = object - [ - "service" .= service - ] - toEncodingPB PingRequest{..} = pairs - [ - "service" .= service - ] - -instance FromJSON PingRequest where - parseJSON = parseJSONPB - -instance ToJSON PingRequest where - toJSON = toAesonValue - toEncoding = toAesonEncoding - -instance Proto3.Message PingRequest where - encodeMessage _ PingRequest{..} = mconcat - [ - encodeMessageField 1 service - ] - decodeMessage _ = PingRequest - <$> at decodeMessageField 1 - dotProto = undefined - -data PingResponse = PingResponse - { status :: Text - , hostname :: Text - , timestamp :: Text - , sha :: Text - } deriving stock (Eq, Ord, Show, Generic) - deriving anyclass (Proto3.Named, NFData) - -instance FromJSONPB PingResponse where - parseJSONPB = A.withObject "PingResponse" $ \obj -> PingResponse - <$> obj .: "status" - <*> obj .: "hostname" - <*> obj .: "timestamp" - <*> obj .: "sha" - -instance ToJSONPB PingResponse where - toJSONPB PingResponse{..} = object - [ - "status" .= status - , "hostname" .= hostname - , "timestamp" .= timestamp - , "sha" .= sha - ] - toEncodingPB PingResponse{..} = pairs - [ - "status" .= status - , "hostname" .= hostname - , "timestamp" .= timestamp - , "sha" .= sha - ] - -instance FromJSON PingResponse where - parseJSON = parseJSONPB - -instance ToJSON PingResponse where - toJSON = toAesonValue - toEncoding = toAesonEncoding - -instance Proto3.Message PingResponse where - encodeMessage _ PingResponse{..} = mconcat - [ - encodeMessageField 1 status - , encodeMessageField 2 hostname - , encodeMessageField 3 timestamp - , encodeMessageField 4 sha - ] - decodeMessage _ = PingResponse - <$> at decodeMessageField 1 - <*> at decodeMessageField 2 - <*> at decodeMessageField 3 - <*> at decodeMessageField 4 - dotProto = undefined - -data ParseTreeRequest = ParseTreeRequest - { blobs :: Vector Blob - } deriving stock (Eq, Ord, Show, Generic) - deriving anyclass (Proto3.Named, NFData) - -instance FromJSONPB ParseTreeRequest where - parseJSONPB = A.withObject "ParseTreeRequest" $ \obj -> ParseTreeRequest - <$> obj .: "blobs" - -instance ToJSONPB ParseTreeRequest where - toJSONPB ParseTreeRequest{..} = object - [ - "blobs" .= blobs - ] - toEncodingPB ParseTreeRequest{..} = pairs - [ - "blobs" .= blobs - ] - -instance FromJSON ParseTreeRequest where - parseJSON = parseJSONPB - -instance ToJSON ParseTreeRequest where - toJSON = toAesonValue - toEncoding = toAesonEncoding - -instance Proto3.Message ParseTreeRequest where - encodeMessage _ ParseTreeRequest{..} = mconcat - [ - encodeMessageField 1 (Proto3.NestedVec blobs) - ] - decodeMessage _ = ParseTreeRequest - <$> (nestedvec <$> at decodeMessageField 1) - dotProto = undefined - -data ParseTreeSymbolResponse = ParseTreeSymbolResponse - { files :: Vector File - } deriving stock (Eq, Ord, Show, Generic) - deriving anyclass (Proto3.Named, NFData) - -instance FromJSONPB ParseTreeSymbolResponse where - parseJSONPB = A.withObject "ParseTreeSymbolResponse" $ \obj -> ParseTreeSymbolResponse - <$> obj .: "files" - -instance ToJSONPB ParseTreeSymbolResponse where - toJSONPB ParseTreeSymbolResponse{..} = object - [ - "files" .= files - ] - toEncodingPB ParseTreeSymbolResponse{..} = pairs - [ - "files" .= files - ] - -instance FromJSON ParseTreeSymbolResponse where - parseJSON = parseJSONPB - -instance ToJSON ParseTreeSymbolResponse where - toJSON = toAesonValue - toEncoding = toAesonEncoding - -instance Proto3.Message ParseTreeSymbolResponse where - encodeMessage _ ParseTreeSymbolResponse{..} = mconcat - [ - encodeMessageField 1 (Proto3.NestedVec files) - ] - decodeMessage _ = ParseTreeSymbolResponse - <$> (nestedvec <$> at decodeMessageField 1) - dotProto = undefined - -data ParseTreeGraphResponse = ParseTreeGraphResponse - { files :: Vector ParseTreeFileGraph - } deriving stock (Eq, Ord, Show, Generic) - deriving anyclass (Proto3.Named, NFData) - -instance FromJSONPB ParseTreeGraphResponse where - parseJSONPB = A.withObject "ParseTreeGraphResponse" $ \obj -> ParseTreeGraphResponse - <$> obj .: "files" - -instance ToJSONPB ParseTreeGraphResponse where - toJSONPB ParseTreeGraphResponse{..} = object - [ - "files" .= files - ] - toEncodingPB ParseTreeGraphResponse{..} = pairs - [ - "files" .= files - ] - -instance FromJSON ParseTreeGraphResponse where - parseJSON = parseJSONPB - -instance ToJSON ParseTreeGraphResponse where - toJSON = toAesonValue - toEncoding = toAesonEncoding - -instance Proto3.Message ParseTreeGraphResponse where - encodeMessage _ ParseTreeGraphResponse{..} = mconcat - [ - encodeMessageField 1 (Proto3.NestedVec files) - ] - decodeMessage _ = ParseTreeGraphResponse - <$> (nestedvec <$> at decodeMessageField 1) - dotProto = undefined - -data ParseTreeFileGraph = ParseTreeFileGraph - { path :: Text - , language :: Text - , vertices :: Vector TermVertex - , edges :: Vector TermEdge - , errors :: Vector ParseError - } deriving stock (Eq, Ord, Show, Generic) - deriving anyclass (Proto3.Named, NFData) - -instance FromJSONPB ParseTreeFileGraph where - parseJSONPB = A.withObject "ParseTreeFileGraph" $ \obj -> ParseTreeFileGraph - <$> obj .: "path" - <*> obj .: "language" - <*> obj .: "vertices" - <*> obj .: "edges" - <*> obj .: "errors" - -instance ToJSONPB ParseTreeFileGraph where - toJSONPB ParseTreeFileGraph{..} = object - [ - "path" .= path - , "language" .= language - , "vertices" .= vertices - , "edges" .= edges - , "errors" .= errors - ] - toEncodingPB ParseTreeFileGraph{..} = pairs - [ - "path" .= path - , "language" .= language - , "vertices" .= vertices - , "edges" .= edges - , "errors" .= errors - ] - -instance FromJSON ParseTreeFileGraph where - parseJSON = parseJSONPB - -instance ToJSON ParseTreeFileGraph where - toJSON = toAesonValue - toEncoding = toAesonEncoding - -instance Proto3.Message ParseTreeFileGraph where - encodeMessage _ ParseTreeFileGraph{..} = mconcat - [ - encodeMessageField 1 path - , encodeMessageField 2 language - , encodeMessageField 3 (Proto3.NestedVec vertices) - , encodeMessageField 4 (Proto3.NestedVec edges) - , encodeMessageField 5 (Proto3.NestedVec errors) - ] - decodeMessage _ = ParseTreeFileGraph - <$> at decodeMessageField 1 - <*> at decodeMessageField 2 - <*> (nestedvec <$> at decodeMessageField 3) - <*> (nestedvec <$> at decodeMessageField 4) - <*> (nestedvec <$> at decodeMessageField 5) - dotProto = undefined - -data TermEdge = TermEdge - { source :: Int32 - , target :: Int32 - } deriving stock (Eq, Ord, Show, Generic) - deriving anyclass (Proto3.Named, NFData) - -instance FromJSONPB TermEdge where - parseJSONPB = A.withObject "TermEdge" $ \obj -> TermEdge - <$> obj .: "source" - <*> obj .: "target" - -instance ToJSONPB TermEdge where - toJSONPB TermEdge{..} = object - [ - "source" .= source - , "target" .= target - ] - toEncodingPB TermEdge{..} = pairs - [ - "source" .= source - , "target" .= target - ] - -instance FromJSON TermEdge where - parseJSON = parseJSONPB - -instance ToJSON TermEdge where - toJSON = toAesonValue - toEncoding = toAesonEncoding - -instance Proto3.Message TermEdge where - encodeMessage _ TermEdge{..} = mconcat - [ - encodeMessageField 1 source - , encodeMessageField 2 target - ] - decodeMessage _ = TermEdge - <$> at decodeMessageField 1 - <*> at decodeMessageField 2 - dotProto = undefined - -data TermVertex = TermVertex - { vertexId :: Int32 - , term :: Text - , span :: Maybe Span - } deriving stock (Eq, Ord, Show, Generic) - deriving anyclass (Proto3.Named, NFData) - -instance FromJSONPB TermVertex where - parseJSONPB = A.withObject "TermVertex" $ \obj -> TermVertex - <$> obj .: "vertexId" - <*> obj .: "term" - <*> obj .: "span" - -instance ToJSONPB TermVertex where - toJSONPB TermVertex{..} = object - [ - "vertexId" .= vertexId - , "term" .= term - , "span" .= span - ] - toEncodingPB TermVertex{..} = pairs - [ - "vertexId" .= vertexId - , "term" .= term - , "span" .= span - ] - -instance FromJSON TermVertex where - parseJSON = parseJSONPB - -instance ToJSON TermVertex where - toJSON = toAesonValue - toEncoding = toAesonEncoding - -instance Proto3.Message TermVertex where - encodeMessage _ TermVertex{..} = mconcat - [ - encodeMessageField 1 vertexId - , encodeMessageField 2 term - , encodeMessageField 3 (Proto3.Nested span) - ] - decodeMessage _ = TermVertex - <$> at decodeMessageField 1 - <*> at decodeMessageField 2 - <*> at decodeMessageField 3 - dotProto = undefined - -data ParseError = ParseError - { error :: Text - } deriving stock (Eq, Ord, Show, Generic) - deriving anyclass (Proto3.Named, NFData) - -instance FromJSONPB ParseError where - parseJSONPB = A.withObject "ParseError" $ \obj -> ParseError - <$> obj .: "error" - -instance ToJSONPB ParseError where - toJSONPB ParseError{..} = object - [ - "error" .= error - ] - toEncodingPB ParseError{..} = pairs - [ - "error" .= error - ] - -instance FromJSON ParseError where - parseJSON = parseJSONPB - -instance ToJSON ParseError where - toJSON = toAesonValue - toEncoding = toAesonEncoding - -instance Proto3.Message ParseError where - encodeMessage _ ParseError{..} = mconcat - [ - encodeMessageField 1 error - ] - decodeMessage _ = ParseError - <$> at decodeMessageField 1 - dotProto = undefined - -data DiffTreeRequest = DiffTreeRequest - { blobs :: Vector BlobPair - } deriving stock (Eq, Ord, Show, Generic) - deriving anyclass (Proto3.Named, NFData) - -instance FromJSONPB DiffTreeRequest where - parseJSONPB = A.withObject "DiffTreeRequest" $ \obj -> DiffTreeRequest - <$> obj .: "blobs" - -instance ToJSONPB DiffTreeRequest where - toJSONPB DiffTreeRequest{..} = object - [ - "blobs" .= blobs - ] - toEncodingPB DiffTreeRequest{..} = pairs - [ - "blobs" .= blobs - ] - -instance FromJSON DiffTreeRequest where - parseJSON = parseJSONPB - -instance ToJSON DiffTreeRequest where - toJSON = toAesonValue - toEncoding = toAesonEncoding - -instance Proto3.Message DiffTreeRequest where - encodeMessage _ DiffTreeRequest{..} = mconcat - [ - encodeMessageField 1 (Proto3.NestedVec blobs) - ] - decodeMessage _ = DiffTreeRequest - <$> (nestedvec <$> at decodeMessageField 1) - dotProto = undefined - -data DiffTreeTOCResponse = DiffTreeTOCResponse - { files :: Vector TOCSummaryFile - } deriving stock (Eq, Ord, Show, Generic) - deriving anyclass (Proto3.Named, NFData) - -instance FromJSONPB DiffTreeTOCResponse where - parseJSONPB = A.withObject "DiffTreeTOCResponse" $ \obj -> DiffTreeTOCResponse - <$> obj .: "files" - -instance ToJSONPB DiffTreeTOCResponse where - toJSONPB DiffTreeTOCResponse{..} = object - [ - "files" .= files - ] - toEncodingPB DiffTreeTOCResponse{..} = pairs - [ - "files" .= files - ] - -instance FromJSON DiffTreeTOCResponse where - parseJSON = parseJSONPB - -instance ToJSON DiffTreeTOCResponse where - toJSON = toAesonValue - toEncoding = toAesonEncoding - -instance Proto3.Message DiffTreeTOCResponse where - encodeMessage _ DiffTreeTOCResponse{..} = mconcat - [ - encodeMessageField 1 (Proto3.NestedVec files) - ] - decodeMessage _ = DiffTreeTOCResponse - <$> (nestedvec <$> at decodeMessageField 1) - dotProto = undefined - -data TOCSummaryFile = TOCSummaryFile - { path :: Text - , language :: Text - , changes :: Vector TOCSummaryChange - , errors :: Vector TOCSummaryError - } deriving stock (Eq, Ord, Show, Generic) - deriving anyclass (Proto3.Named, NFData) - -instance FromJSONPB TOCSummaryFile where - parseJSONPB = A.withObject "TOCSummaryFile" $ \obj -> TOCSummaryFile - <$> obj .: "path" - <*> obj .: "language" - <*> obj .: "changes" - <*> obj .: "errors" - -instance ToJSONPB TOCSummaryFile where - toJSONPB TOCSummaryFile{..} = object - [ - "path" .= path - , "language" .= language - , "changes" .= changes - , "errors" .= errors - ] - toEncodingPB TOCSummaryFile{..} = pairs - [ - "path" .= path - , "language" .= language - , "changes" .= changes - , "errors" .= errors - ] - -instance FromJSON TOCSummaryFile where - parseJSON = parseJSONPB - -instance ToJSON TOCSummaryFile where - toJSON = toAesonValue - toEncoding = toAesonEncoding - -instance Proto3.Message TOCSummaryFile where - encodeMessage _ TOCSummaryFile{..} = mconcat - [ - encodeMessageField 1 path - , encodeMessageField 2 language - , encodeMessageField 3 (Proto3.NestedVec changes) - , encodeMessageField 4 (Proto3.NestedVec errors) - ] - decodeMessage _ = TOCSummaryFile - <$> at decodeMessageField 1 - <*> at decodeMessageField 2 - <*> (nestedvec <$> at decodeMessageField 3) - <*> (nestedvec <$> at decodeMessageField 4) - dotProto = undefined - -data TOCSummaryChange = TOCSummaryChange - { category :: Text - , term :: Text - , span :: Maybe Span - , changeType :: ChangeType - } deriving stock (Eq, Ord, Show, Generic) - deriving anyclass (Proto3.Named, NFData) - -instance FromJSONPB TOCSummaryChange where - parseJSONPB = A.withObject "TOCSummaryChange" $ \obj -> TOCSummaryChange - <$> obj .: "category" - <*> obj .: "term" - <*> obj .: "span" - <*> obj .: "changeType" - -instance ToJSONPB TOCSummaryChange where - toJSONPB TOCSummaryChange{..} = object - [ - "category" .= category - , "term" .= term - , "span" .= span - , "changeType" .= changeType - ] - toEncodingPB TOCSummaryChange{..} = pairs - [ - "category" .= category - , "term" .= term - , "span" .= span - , "changeType" .= changeType - ] - -instance FromJSON TOCSummaryChange where - parseJSON = parseJSONPB - -instance ToJSON TOCSummaryChange where - toJSON = toAesonValue - toEncoding = toAesonEncoding - -instance Proto3.Message TOCSummaryChange where - encodeMessage _ TOCSummaryChange{..} = mconcat - [ - encodeMessageField 1 category - , encodeMessageField 2 term - , encodeMessageField 3 (Proto3.Nested span) - , encodeMessageField 4 changeType - ] - decodeMessage _ = TOCSummaryChange - <$> at decodeMessageField 1 - <*> at decodeMessageField 2 - <*> at decodeMessageField 3 - <*> at decodeMessageField 4 - dotProto = undefined - -data TOCSummaryError = TOCSummaryError - { error :: Text - , span :: Maybe Span - } deriving stock (Eq, Ord, Show, Generic) - deriving anyclass (Proto3.Named, NFData) - -instance FromJSONPB TOCSummaryError where - parseJSONPB = A.withObject "TOCSummaryError" $ \obj -> TOCSummaryError - <$> obj .: "error" - <*> obj .: "span" - -instance ToJSONPB TOCSummaryError where - toJSONPB TOCSummaryError{..} = object - [ - "error" .= error - , "span" .= span - ] - toEncodingPB TOCSummaryError{..} = pairs - [ - "error" .= error - , "span" .= span - ] - -instance FromJSON TOCSummaryError where - parseJSON = parseJSONPB - -instance ToJSON TOCSummaryError where - toJSON = toAesonValue - toEncoding = toAesonEncoding - -instance Proto3.Message TOCSummaryError where - encodeMessage _ TOCSummaryError{..} = mconcat - [ - encodeMessageField 1 error - , encodeMessageField 2 (Proto3.Nested span) - ] - decodeMessage _ = TOCSummaryError - <$> at decodeMessageField 1 - <*> at decodeMessageField 2 - dotProto = undefined - -data DiffTreeGraphResponse = DiffTreeGraphResponse - { files :: Vector DiffTreeFileGraph - } deriving stock (Eq, Ord, Show, Generic) - deriving anyclass (Proto3.Named, NFData) - -instance FromJSONPB DiffTreeGraphResponse where - parseJSONPB = A.withObject "DiffTreeGraphResponse" $ \obj -> DiffTreeGraphResponse - <$> obj .: "files" - -instance ToJSONPB DiffTreeGraphResponse where - toJSONPB DiffTreeGraphResponse{..} = object - [ - "files" .= files - ] - toEncodingPB DiffTreeGraphResponse{..} = pairs - [ - "files" .= files - ] - -instance FromJSON DiffTreeGraphResponse where - parseJSON = parseJSONPB - -instance ToJSON DiffTreeGraphResponse where - toJSON = toAesonValue - toEncoding = toAesonEncoding - -instance Proto3.Message DiffTreeGraphResponse where - encodeMessage _ DiffTreeGraphResponse{..} = mconcat - [ - encodeMessageField 1 (Proto3.NestedVec files) - ] - decodeMessage _ = DiffTreeGraphResponse - <$> (nestedvec <$> at decodeMessageField 1) - dotProto = undefined - -data DiffTreeFileGraph = DiffTreeFileGraph - { path :: Text - , language :: Text - , vertices :: Vector DiffTreeVertex - , edges :: Vector DiffTreeEdge - , errors :: Vector ParseError - } deriving stock (Eq, Ord, Show, Generic) - deriving anyclass (Proto3.Named, NFData) - -instance FromJSONPB DiffTreeFileGraph where - parseJSONPB = A.withObject "DiffTreeFileGraph" $ \obj -> DiffTreeFileGraph - <$> obj .: "path" - <*> obj .: "language" - <*> obj .: "vertices" - <*> obj .: "edges" - <*> obj .: "errors" - -instance ToJSONPB DiffTreeFileGraph where - toJSONPB DiffTreeFileGraph{..} = object - [ - "path" .= path - , "language" .= language - , "vertices" .= vertices - , "edges" .= edges - , "errors" .= errors - ] - toEncodingPB DiffTreeFileGraph{..} = pairs - [ - "path" .= path - , "language" .= language - , "vertices" .= vertices - , "edges" .= edges - , "errors" .= errors - ] - -instance FromJSON DiffTreeFileGraph where - parseJSON = parseJSONPB - -instance ToJSON DiffTreeFileGraph where - toJSON = toAesonValue - toEncoding = toAesonEncoding - -instance Proto3.Message DiffTreeFileGraph where - encodeMessage _ DiffTreeFileGraph{..} = mconcat - [ - encodeMessageField 1 path - , encodeMessageField 2 language - , encodeMessageField 3 (Proto3.NestedVec vertices) - , encodeMessageField 4 (Proto3.NestedVec edges) - , encodeMessageField 5 (Proto3.NestedVec errors) - ] - decodeMessage _ = DiffTreeFileGraph - <$> at decodeMessageField 1 - <*> at decodeMessageField 2 - <*> (nestedvec <$> at decodeMessageField 3) - <*> (nestedvec <$> at decodeMessageField 4) - <*> (nestedvec <$> at decodeMessageField 5) - dotProto = undefined - -data DiffTreeEdge = DiffTreeEdge - { source :: Int32 - , target :: Int32 - } deriving stock (Eq, Ord, Show, Generic) - deriving anyclass (Proto3.Named, NFData) - -instance FromJSONPB DiffTreeEdge where - parseJSONPB = A.withObject "DiffTreeEdge" $ \obj -> DiffTreeEdge - <$> obj .: "source" - <*> obj .: "target" - -instance ToJSONPB DiffTreeEdge where - toJSONPB DiffTreeEdge{..} = object - [ - "source" .= source - , "target" .= target - ] - toEncodingPB DiffTreeEdge{..} = pairs - [ - "source" .= source - , "target" .= target - ] - -instance FromJSON DiffTreeEdge where - parseJSON = parseJSONPB - -instance ToJSON DiffTreeEdge where - toJSON = toAesonValue - toEncoding = toAesonEncoding - -instance Proto3.Message DiffTreeEdge where - encodeMessage _ DiffTreeEdge{..} = mconcat - [ - encodeMessageField 1 source - , encodeMessageField 2 target - ] - decodeMessage _ = DiffTreeEdge - <$> at decodeMessageField 1 - <*> at decodeMessageField 2 - dotProto = undefined - -data DiffTreeVertexDiffTerm - = Deleted (Maybe DeletedTerm) - | Inserted (Maybe InsertedTerm) - | Replaced (Maybe ReplacedTerm) - | Merged (Maybe MergedTerm) - deriving stock (Eq, Ord, Show, Generic) - deriving anyclass (Proto3.Message, Proto3.Named, NFData) - -instance FromJSONPB DiffTreeVertexDiffTerm where - parseJSONPB = A.withObject "DiffTreeVertexDiffTerm" $ \obj -> msum - [ - Deleted <$> parseField obj "deleted" - , Inserted <$> parseField obj "inserted" - , Replaced <$> parseField obj "replaced" - , Merged <$> parseField obj "merged" - ] - -instance ToJSONPB DiffTreeVertexDiffTerm where - toJSONPB (Deleted x) = object [ "deleted" .= x ] - toJSONPB (Inserted x) = object [ "inserted" .= x ] - toJSONPB (Replaced x) = object [ "replaced" .= x ] - toJSONPB (Merged x) = object [ "merged" .= x ] - toEncodingPB (Deleted x) = pairs [ "deleted" .= x ] - toEncodingPB (Inserted x) = pairs [ "inserted" .= x ] - toEncodingPB (Replaced x) = pairs [ "replaced" .= x ] - toEncodingPB (Merged x) = pairs [ "merged" .= x ] - -instance FromJSON DiffTreeVertexDiffTerm where - parseJSON = parseJSONPB - -instance ToJSON DiffTreeVertexDiffTerm where - toJSON = toAesonValue - toEncoding = toAesonEncoding - -data DiffTreeVertex = DiffTreeVertex - { diffVertexId :: Int32 - , diffTerm :: Maybe DiffTreeVertexDiffTerm - } deriving stock (Eq, Ord, Show, Generic) - deriving anyclass (Proto3.Named, NFData) - -instance FromJSONPB DiffTreeVertex where - parseJSONPB = A.withObject "DiffTreeVertex" $ \obj -> DiffTreeVertex - <$> obj .: "diffVertexId" - <*> obj .: "diffTerm" - -instance ToJSONPB DiffTreeVertex where - toJSONPB DiffTreeVertex{..} = object - [ - "diffVertexId" .= diffVertexId - , "diffTerm" .= diffTerm - ] - toEncodingPB DiffTreeVertex{..} = pairs - [ - "diffVertexId" .= diffVertexId - , "diffTerm" .= diffTerm - ] - -instance FromJSON DiffTreeVertex where - parseJSON = parseJSONPB - -instance ToJSON DiffTreeVertex where - toJSON = toAesonValue - toEncoding = toAesonEncoding - -instance Proto3.Message DiffTreeVertex where - encodeMessage _ DiffTreeVertex{..} = mconcat - [ - encodeMessageField 1 diffVertexId - , case diffTerm of - Nothing -> mempty - Just (Deleted deleted) -> encodeMessageField 2 deleted - Just (Inserted inserted) -> encodeMessageField 3 inserted - Just (Replaced replaced) -> encodeMessageField 4 replaced - Just (Merged merged) -> encodeMessageField 5 merged - ] - decodeMessage _ = DiffTreeVertex - <$> at decodeMessageField 1 - <*> oneof - Nothing - [ - (2, Just . Deleted <$> decodeMessageField) - , (3, Just . Inserted <$> decodeMessageField) - , (4, Just . Replaced <$> decodeMessageField) - , (5, Just . Merged <$> decodeMessageField) - ] - dotProto = undefined - -data DeletedTerm = DeletedTerm - { term :: Text - , span :: Maybe Span - } deriving stock (Eq, Ord, Show, Generic) - deriving anyclass (Proto3.Named, NFData) - -instance FromJSONPB DeletedTerm where - parseJSONPB = A.withObject "DeletedTerm" $ \obj -> DeletedTerm - <$> obj .: "term" - <*> obj .: "span" - -instance ToJSONPB DeletedTerm where - toJSONPB DeletedTerm{..} = object - [ - "term" .= term - , "span" .= span - ] - toEncodingPB DeletedTerm{..} = pairs - [ - "term" .= term - , "span" .= span - ] - -instance FromJSON DeletedTerm where - parseJSON = parseJSONPB - -instance ToJSON DeletedTerm where - toJSON = toAesonValue - toEncoding = toAesonEncoding - -instance Proto3.Message DeletedTerm where - encodeMessage _ DeletedTerm{..} = mconcat - [ - encodeMessageField 1 term - , encodeMessageField 2 (Proto3.Nested span) - ] - decodeMessage _ = DeletedTerm - <$> at decodeMessageField 1 - <*> at decodeMessageField 2 - dotProto = undefined - -data InsertedTerm = InsertedTerm - { term :: Text - , span :: Maybe Span - } deriving stock (Eq, Ord, Show, Generic) - deriving anyclass (Proto3.Named, NFData) - -instance FromJSONPB InsertedTerm where - parseJSONPB = A.withObject "InsertedTerm" $ \obj -> InsertedTerm - <$> obj .: "term" - <*> obj .: "span" - -instance ToJSONPB InsertedTerm where - toJSONPB InsertedTerm{..} = object - [ - "term" .= term - , "span" .= span - ] - toEncodingPB InsertedTerm{..} = pairs - [ - "term" .= term - , "span" .= span - ] - -instance FromJSON InsertedTerm where - parseJSON = parseJSONPB - -instance ToJSON InsertedTerm where - toJSON = toAesonValue - toEncoding = toAesonEncoding - -instance Proto3.Message InsertedTerm where - encodeMessage _ InsertedTerm{..} = mconcat - [ - encodeMessageField 1 term - , encodeMessageField 2 (Proto3.Nested span) - ] - decodeMessage _ = InsertedTerm - <$> at decodeMessageField 1 - <*> at decodeMessageField 2 - dotProto = undefined - -data ReplacedTerm = ReplacedTerm - { beforeTerm :: Text - , beforeSpan :: Maybe Span - , afterTerm :: Text - , afterSpan :: Maybe Span - } deriving stock (Eq, Ord, Show, Generic) - deriving anyclass (Proto3.Named, NFData) - -instance FromJSONPB ReplacedTerm where - parseJSONPB = A.withObject "ReplacedTerm" $ \obj -> ReplacedTerm - <$> obj .: "beforeTerm" - <*> obj .: "beforeSpan" - <*> obj .: "afterTerm" - <*> obj .: "afterSpan" - -instance ToJSONPB ReplacedTerm where - toJSONPB ReplacedTerm{..} = object - [ - "beforeTerm" .= beforeTerm - , "beforeSpan" .= beforeSpan - , "afterTerm" .= afterTerm - , "afterSpan" .= afterSpan - ] - toEncodingPB ReplacedTerm{..} = pairs - [ - "beforeTerm" .= beforeTerm - , "beforeSpan" .= beforeSpan - , "afterTerm" .= afterTerm - , "afterSpan" .= afterSpan - ] - -instance FromJSON ReplacedTerm where - parseJSON = parseJSONPB - -instance ToJSON ReplacedTerm where - toJSON = toAesonValue - toEncoding = toAesonEncoding - -instance Proto3.Message ReplacedTerm where - encodeMessage _ ReplacedTerm{..} = mconcat - [ - encodeMessageField 1 beforeTerm - , encodeMessageField 2 (Proto3.Nested beforeSpan) - , encodeMessageField 3 afterTerm - , encodeMessageField 4 (Proto3.Nested afterSpan) - ] - decodeMessage _ = ReplacedTerm - <$> at decodeMessageField 1 - <*> at decodeMessageField 2 - <*> at decodeMessageField 3 - <*> at decodeMessageField 4 - dotProto = undefined - -data MergedTerm = MergedTerm - { term :: Text - , beforeSpan :: Maybe Span - , afterSpan :: Maybe Span - } deriving stock (Eq, Ord, Show, Generic) - deriving anyclass (Proto3.Named, NFData) - -instance FromJSONPB MergedTerm where - parseJSONPB = A.withObject "MergedTerm" $ \obj -> MergedTerm - <$> obj .: "term" - <*> obj .: "beforeSpan" - <*> obj .: "afterSpan" - -instance ToJSONPB MergedTerm where - toJSONPB MergedTerm{..} = object - [ - "term" .= term - , "beforeSpan" .= beforeSpan - , "afterSpan" .= afterSpan - ] - toEncodingPB MergedTerm{..} = pairs - [ - "term" .= term - , "beforeSpan" .= beforeSpan - , "afterSpan" .= afterSpan - ] - -instance FromJSON MergedTerm where - parseJSON = parseJSONPB - -instance ToJSON MergedTerm where - toJSON = toAesonValue - toEncoding = toAesonEncoding - -instance Proto3.Message MergedTerm where - encodeMessage _ MergedTerm{..} = mconcat - [ - encodeMessageField 1 term - , encodeMessageField 2 (Proto3.Nested beforeSpan) - , encodeMessageField 3 (Proto3.Nested afterSpan) - ] - decodeMessage _ = MergedTerm - <$> at decodeMessageField 1 - <*> at decodeMessageField 2 - <*> at decodeMessageField 3 - dotProto = undefined - -data Blob = Blob - { content :: Text - , path :: Text - , language :: Text - } deriving stock (Eq, Ord, Show, Generic) - deriving anyclass (Proto3.Named, NFData) - -instance FromJSONPB Blob where - parseJSONPB = A.withObject "Blob" $ \obj -> Blob - <$> obj .: "content" - <*> obj .: "path" - <*> obj .: "language" - -instance ToJSONPB Blob where - toJSONPB Blob{..} = object - [ - "content" .= content - , "path" .= path - , "language" .= language - ] - toEncodingPB Blob{..} = pairs - [ - "content" .= content - , "path" .= path - , "language" .= language - ] - -instance FromJSON Blob where - parseJSON = parseJSONPB - -instance ToJSON Blob where - toJSON = toAesonValue - toEncoding = toAesonEncoding - -instance Proto3.Message Blob where - encodeMessage _ Blob{..} = mconcat - [ - encodeMessageField 1 content - , encodeMessageField 2 path - , encodeMessageField 3 language - ] - decodeMessage _ = Blob - <$> at decodeMessageField 1 - <*> at decodeMessageField 2 - <*> at decodeMessageField 3 - dotProto = undefined - -data BlobPair = BlobPair - { before :: Maybe Blob - , after :: Maybe Blob - } deriving stock (Eq, Ord, Show, Generic) - deriving anyclass (Proto3.Named, NFData) - -instance FromJSONPB BlobPair where - parseJSONPB = A.withObject "BlobPair" $ \obj -> BlobPair - <$> obj .: "before" - <*> obj .: "after" - -instance ToJSONPB BlobPair where - toJSONPB BlobPair{..} = object - [ - "before" .= before - , "after" .= after - ] - toEncodingPB BlobPair{..} = pairs - [ - "before" .= before - , "after" .= after - ] - -instance FromJSON BlobPair where - parseJSON = parseJSONPB - -instance ToJSON BlobPair where - toJSON = toAesonValue - toEncoding = toAesonEncoding - -instance Proto3.Message BlobPair where - encodeMessage _ BlobPair{..} = mconcat - [ - encodeMessageField 1 (Proto3.Nested before) - , encodeMessageField 2 (Proto3.Nested after) - ] - decodeMessage _ = BlobPair - <$> at decodeMessageField 1 - <*> at decodeMessageField 2 - dotProto = undefined - -data File = File - { path :: Text - , language :: Text - , symbols :: Vector Symbol - , errors :: Vector ParseError - , blobOid :: Text - } deriving stock (Eq, Ord, Show, Generic) - deriving anyclass (Proto3.Named, NFData) - -instance FromJSONPB File where - parseJSONPB = A.withObject "File" $ \obj -> File - <$> obj .: "path" - <*> obj .: "language" - <*> obj .: "symbols" - <*> obj .: "errors" - <*> obj .: "blobOid" - -instance ToJSONPB File where - toJSONPB File{..} = object - [ - "path" .= path - , "language" .= language - , "symbols" .= symbols - , "errors" .= errors - , "blobOid" .= blobOid - ] - toEncodingPB File{..} = pairs - [ - "path" .= path - , "language" .= language - , "symbols" .= symbols - , "errors" .= errors - , "blobOid" .= blobOid - ] - -instance FromJSON File where - parseJSON = parseJSONPB - -instance ToJSON File where - toJSON = toAesonValue - toEncoding = toAesonEncoding - -instance Proto3.Message File where - encodeMessage _ File{..} = mconcat - [ - encodeMessageField 1 path - , encodeMessageField 2 language - , encodeMessageField 3 (Proto3.NestedVec symbols) - , encodeMessageField 4 (Proto3.NestedVec errors) - , encodeMessageField 5 blobOid - ] - decodeMessage _ = File - <$> at decodeMessageField 1 - <*> at decodeMessageField 2 - <*> (nestedvec <$> at decodeMessageField 3) - <*> (nestedvec <$> at decodeMessageField 4) - <*> at decodeMessageField 5 - dotProto = undefined - -data Symbol = Symbol - { symbol :: Text - , kind :: Text - , line :: Text - , span :: Maybe Span - , docs :: Maybe Docstring - } deriving stock (Eq, Ord, Show, Generic) - deriving anyclass (Proto3.Named, NFData) - -instance FromJSONPB Symbol where - parseJSONPB = A.withObject "Symbol" $ \obj -> Symbol - <$> obj .: "symbol" - <*> obj .: "kind" - <*> obj .: "line" - <*> obj .: "span" - <*> obj .: "docs" - -instance ToJSONPB Symbol where - toJSONPB Symbol{..} = object - [ - "symbol" .= symbol - , "kind" .= kind - , "line" .= line - , "span" .= span - , "docs" .= docs - ] - toEncodingPB Symbol{..} = pairs - [ - "symbol" .= symbol - , "kind" .= kind - , "line" .= line - , "span" .= span - , "docs" .= docs - ] - -instance FromJSON Symbol where - parseJSON = parseJSONPB - -instance ToJSON Symbol where - toJSON = toAesonValue - toEncoding = toAesonEncoding - -instance Proto3.Message Symbol where - encodeMessage _ Symbol{..} = mconcat - [ - encodeMessageField 1 symbol - , encodeMessageField 2 kind - , encodeMessageField 3 line - , encodeMessageField 4 (Proto3.Nested span) - , encodeMessageField 5 (Proto3.Nested docs) - ] - decodeMessage _ = Symbol - <$> at decodeMessageField 1 - <*> at decodeMessageField 2 - <*> at decodeMessageField 3 - <*> at decodeMessageField 4 - <*> at decodeMessageField 5 - dotProto = undefined - -data Docstring = Docstring - { docstring :: Text - } deriving stock (Eq, Ord, Show, Generic) - deriving anyclass (Proto3.Named, NFData) - -instance FromJSONPB Docstring where - parseJSONPB = A.withObject "Docstring" $ \obj -> Docstring - <$> obj .: "docstring" - -instance ToJSONPB Docstring where - toJSONPB Docstring{..} = object - [ - "docstring" .= docstring - ] - toEncodingPB Docstring{..} = pairs - [ - "docstring" .= docstring - ] - -instance FromJSON Docstring where - parseJSON = parseJSONPB - -instance ToJSON Docstring where - toJSON = toAesonValue - toEncoding = toAesonEncoding - -instance Proto3.Message Docstring where - encodeMessage _ Docstring{..} = mconcat - [ - encodeMessageField 1 docstring - ] - decodeMessage _ = Docstring - <$> at decodeMessageField 1 - dotProto = undefined - -data Position = Position - { line :: Int32 - , column :: Int32 - } deriving stock (Eq, Ord, Show, Generic) - deriving anyclass (Proto3.Named, NFData) - -instance FromJSONPB Position where - parseJSONPB = A.withObject "Position" $ \obj -> Position - <$> obj .: "line" - <*> obj .: "column" - -instance ToJSONPB Position where - toJSONPB Position{..} = object - [ - "line" .= line - , "column" .= column - ] - toEncodingPB Position{..} = pairs - [ - "line" .= line - , "column" .= column - ] - -instance FromJSON Position where - parseJSON = parseJSONPB - -instance ToJSON Position where - toJSON = toAesonValue - toEncoding = toAesonEncoding - -instance Proto3.Message Position where - encodeMessage _ Position{..} = mconcat - [ - encodeMessageField 1 line - , encodeMessageField 2 column - ] - decodeMessage _ = Position - <$> at decodeMessageField 1 - <*> at decodeMessageField 2 - dotProto = undefined - -data Span = Span - { start :: Maybe Position - , end :: Maybe Position - } deriving stock (Eq, Ord, Show, Generic) - deriving anyclass (Proto3.Named, NFData) - -instance FromJSONPB Span where - parseJSONPB = A.withObject "Span" $ \obj -> Span - <$> obj .: "start" - <*> obj .: "end" - -instance ToJSONPB Span where - toJSONPB Span{..} = object - [ - "start" .= start - , "end" .= end - ] - toEncodingPB Span{..} = pairs - [ - "start" .= start - , "end" .= end - ] - -instance FromJSON Span where - parseJSON = parseJSONPB - -instance ToJSON Span where - toJSON = toAesonValue - toEncoding = toAesonEncoding - -instance Proto3.Message Span where - encodeMessage _ Span{..} = mconcat - [ - encodeMessageField 1 (Proto3.Nested start) - , encodeMessageField 2 (Proto3.Nested end) - ] - decodeMessage _ = Span - <$> at decodeMessageField 1 - <*> at decodeMessageField 2 - dotProto = undefined - -data ChangeType - = None - | Added - | Removed - | Modified - deriving stock (Eq, Ord, Show, Enum, Bounded, Generic) - deriving anyclass (Proto3.Named, Proto3.MessageField, NFData) - deriving Proto3.Primitive via Proto3.PrimitiveEnum ChangeType - -instance Proto3.HasDefault ChangeType where def = None - -instance FromJSONPB ChangeType where - parseJSONPB (JSONPB.String "NONE") = pure None - parseJSONPB (JSONPB.String "ADDED") = pure Added - parseJSONPB (JSONPB.String "REMOVED") = pure Removed - parseJSONPB (JSONPB.String "MODIFIED") = pure Modified - parseJSONPB x = typeMismatch "ChangeType" x - -instance ToJSONPB ChangeType where - toJSONPB x _ = A.String . T.toUpper . T.pack $ show x - toEncodingPB x _ = E.text . T.toUpper . T.pack $ show x - -instance FromJSON ChangeType where - parseJSON = parseJSONPB - -instance ToJSON ChangeType where - toJSON = toAesonValue - toEncoding = toAesonEncoding diff --git a/src/Serializing/Format.hs b/src/Serializing/Format.hs index c80860cb9..45974a518 100644 --- a/src/Serializing/Format.hs +++ b/src/Serializing/Format.hs @@ -15,7 +15,6 @@ import Language.Haskell.HsColour import Language.Haskell.HsColour.Colourise import Prologue import Data.ProtoLens.Encoding as Proto -import Data.ProtoLens.JSON as Proto (messageToEncoding) import Data.ProtoLens.Message (Message) import Serializing.SExpression import Text.Show.Pretty @@ -23,7 +22,6 @@ import Text.Show.Pretty data Format input where DOT :: (Ord vertex, ToGraph graph, ToVertex graph ~ vertex) => Style vertex Builder -> Format graph JSON :: ToJSON input => Format input - JSONPB :: Message input => Format input SExpression :: (Recursive input, ToSExpression (Base input)) => Options -> Format input Show :: Show input => Format input Proto :: Message input => Format input @@ -36,5 +34,4 @@ runSerialize _ JSON = (<> "\n") . fromEncoding . toEncodin runSerialize _ (SExpression opts) = serializeSExpression opts runSerialize Colourful Show = (<> "\n") . stringUtf8 . hscolour TTY defaultColourPrefs False False "" False . ppShow runSerialize Plain Show = (<> "\n") . stringUtf8 . show -runSerialize _ JSONPB = fromEncoding . Proto.messageToEncoding -runSerialize _ Proto = Proto.buildMessage -- lazyByteString . Proto3.toLazyByteString +runSerialize _ Proto = Proto.buildMessage diff --git a/test/Rendering/TOC/Spec.hs b/test/Rendering/TOC/Spec.hs index 7d94a1dad..1a5ff719a 100644 --- a/test/Rendering/TOC/Spec.hs +++ b/test/Rendering/TOC/Spec.hs @@ -147,22 +147,22 @@ spec = do describe "diff with ToCDiffRenderer'" $ do it "produces JSON output" $ do blobs <- blobsForPaths (Both (Path.relFile "ruby/toc/methods.A.rb") (Path.relFile "ruby/toc/methods.B.rb")) - output <- runTaskOrDie (diffSummaryBuilder Format.JSONPB [blobs]) + output <- runTaskOrDie (diffSummaryBuilder Format.JSON [blobs]) runBuilder output `shouldBe` ("{\"files\":[{\"path\":\"test/fixtures/ruby/toc/methods.A.rb -> test/fixtures/ruby/toc/methods.B.rb\",\"language\":\"Ruby\",\"changes\":[{\"category\":\"Method\",\"term\":\"self.foo\",\"span\":{\"start\":{\"line\":1,\"column\":1},\"end\":{\"line\":2,\"column\":4}},\"changeType\":\"ADDED\"},{\"category\":\"Method\",\"term\":\"bar\",\"span\":{\"start\":{\"line\":4,\"column\":1},\"end\":{\"line\":6,\"column\":4}},\"changeType\":\"MODIFIED\"},{\"category\":\"Method\",\"term\":\"baz\",\"span\":{\"start\":{\"line\":4,\"column\":1},\"end\":{\"line\":5,\"column\":4}},\"changeType\":\"REMOVED\"}]}]}\n" :: ByteString) it "produces JSON output if there are parse errors" $ do blobs <- blobsForPaths (Both (Path.relFile "ruby/toc/methods.A.rb") (Path.relFile "ruby/toc/methods.X.rb")) - output <- runTaskOrDie (diffSummaryBuilder Format.JSONPB [blobs]) + output <- runTaskOrDie (diffSummaryBuilder Format.JSON [blobs]) runBuilder output `shouldBe` ("{\"files\":[{\"path\":\"test/fixtures/ruby/toc/methods.A.rb -> test/fixtures/ruby/toc/methods.X.rb\",\"language\":\"Ruby\",\"changes\":[{\"category\":\"Method\",\"term\":\"bar\",\"span\":{\"start\":{\"line\":1,\"column\":1},\"end\":{\"line\":2,\"column\":4}},\"changeType\":\"REMOVED\"},{\"category\":\"Method\",\"term\":\"baz\",\"span\":{\"start\":{\"line\":4,\"column\":1},\"end\":{\"line\":5,\"column\":4}},\"changeType\":\"REMOVED\"}],\"errors\":[{\"error\":\"expected end of input nodes, but got ParseError\",\"span\":{\"start\":{\"line\":1,\"column\":1},\"end\":{\"line\":2,\"column\":3}}}]}]}\n" :: ByteString) it "ignores anonymous functions" $ do blobs <- blobsForPaths (Both (Path.relFile "ruby/toc/lambda.A.rb") (Path.relFile "ruby/toc/lambda.B.rb")) - output <- runTaskOrDie (diffSummaryBuilder Format.JSONPB [blobs]) + output <- runTaskOrDie (diffSummaryBuilder Format.JSON [blobs]) runBuilder output `shouldBe` ("{\"files\":[{\"path\":\"test/fixtures/ruby/toc/lambda.A.rb -> test/fixtures/ruby/toc/lambda.B.rb\",\"language\":\"Ruby\"}]}\n" :: ByteString) it "summarizes Markdown headings" $ do blobs <- blobsForPaths (Both (Path.relFile "markdown/toc/headings.A.md") (Path.relFile "markdown/toc/headings.B.md")) - output <- runTaskOrDie (diffSummaryBuilder Format.JSONPB [blobs]) + output <- runTaskOrDie (diffSummaryBuilder Format.JSON [blobs]) runBuilder output `shouldBe` ("{\"files\":[{\"path\":\"test/fixtures/markdown/toc/headings.A.md -> test/fixtures/markdown/toc/headings.B.md\",\"language\":\"Markdown\",\"changes\":[{\"category\":\"Heading 1\",\"term\":\"Introduction\",\"span\":{\"start\":{\"line\":1,\"column\":1},\"end\":{\"line\":3,\"column\":16}},\"changeType\":\"REMOVED\"},{\"category\":\"Heading 2\",\"term\":\"Two\",\"span\":{\"start\":{\"line\":5,\"column\":1},\"end\":{\"line\":7,\"column\":4}},\"changeType\":\"MODIFIED\"},{\"category\":\"Heading 3\",\"term\":\"This heading is new\",\"span\":{\"start\":{\"line\":9,\"column\":1},\"end\":{\"line\":11,\"column\":10}},\"changeType\":\"ADDED\"},{\"category\":\"Heading 1\",\"term\":\"Final\",\"span\":{\"start\":{\"line\":13,\"column\":1},\"end\":{\"line\":14,\"column\":4}},\"changeType\":\"ADDED\"}]}]}\n" :: ByteString) diff --git a/test/Semantic/CLI/Spec.hs b/test/Semantic/CLI/Spec.hs index ca139c668..d910348b7 100644 --- a/test/Semantic/CLI/Spec.hs +++ b/test/Semantic/CLI/Spec.hs @@ -55,7 +55,7 @@ parseFixtures = , ("json", run . parseTermBuilder TermJSONTree, path, prefix Path.file "parse-tree.json") , ("json", run . parseTermBuilder TermJSONTree, path', prefix Path.file "parse-trees.json") , ("json", run . parseTermBuilder TermJSONTree, [], prefix Path.file "parse-tree-empty.json") - , ("symbols", run . parseSymbolsBuilder Serializing.Format.JSONPB, path'', prefix Path.file "parse-tree.symbols.json") + , ("symbols", run . parseSymbolsBuilder Serializing.Format.JSON, path'', prefix Path.file "parse-tree.symbols.json") , ("protobuf symbols", run . parseSymbolsBuilder Serializing.Format.Proto, path'', prefix Path.file "parse-tree.symbols.protobuf.bin") ] where path = [File "test/fixtures/ruby/corpus/and-or.A.rb" Ruby] @@ -68,7 +68,7 @@ diffFixtures :: [(String, [BlobPair] -> TaskEff Builder, [Both File], Path.RelFi diffFixtures = [ ("json diff", parseDiffBuilder DiffJSONTree, pathMode, prefix Path.file "diff-tree.json") , ("s-expression diff", parseDiffBuilder DiffSExpression, pathMode, Path.relFile "test/fixtures/ruby/corpus/method-declaration.diffA-B.txt") - , ("toc summaries diff", diffSummaryBuilder Serializing.Format.JSONPB, pathMode, prefix Path.file "diff-tree.toc.json") + , ("toc summaries diff", diffSummaryBuilder Serializing.Format.JSON, pathMode, prefix Path.file "diff-tree.toc.json") , ("protobuf diff", diffSummaryBuilder Serializing.Format.Proto, pathMode, prefix Path.file "diff-tree.toc.protobuf.bin") ] where pathMode = [Both (File "test/fixtures/ruby/corpus/method-declaration.A.rb" Ruby) (File "test/fixtures/ruby/corpus/method-declaration.B.rb" Ruby)]