diff --git a/.licenses/semantic/cabal/cmark-gfm.txt b/.licenses/semantic/cabal/cmark-gfm.txt index db015432c..75ba799c3 100644 --- a/.licenses/semantic/cabal/cmark-gfm.txt +++ b/.licenses/semantic/cabal/cmark-gfm.txt @@ -1,7 +1,7 @@ --- type: cabal name: cmark-gfm -version: 0.1.6 +version: 0.1.8 summary: Fast, accurate GitHub Flavored Markdown parser and renderer homepage: https://github.com/kivikakk/cmark-gfm-hs license: bsd-3-clause diff --git a/proto/semantic/api/v1/code_analysis.proto b/proto/semantic/api/v1/code_analysis.proto index 55d6dc625..11ff46940 100644 --- a/proto/semantic/api/v1/code_analysis.proto +++ b/proto/semantic/api/v1/code_analysis.proto @@ -44,19 +44,19 @@ message ParseTreeGraphResponse { message ParseTreeFileGraph { string path = 1; - Language language = 2; + string language = 2; repeated TermVertex vertices = 3; repeated TermEdge edges = 4; repeated ParseError errors = 5; } message TermEdge { - int64 source = 1; - int64 target = 2; + int32 source = 1; + int32 target = 2; } message TermVertex { - int64 vertex_id = 1; + int32 vertex_id = 1; string term = 2; Span span = 3; } @@ -75,7 +75,7 @@ message DiffTreeTOCResponse { message TOCSummaryFile { string path = 1; - Language language = 2; + string language = 2; repeated TOCSummaryChange changes = 3; repeated TOCSummaryError errors = 4; } @@ -105,19 +105,19 @@ message DiffTreeGraphResponse { message DiffTreeFileGraph { string path = 1; - Language language = 2; + string language = 2; repeated DiffTreeVertex vertices = 3; repeated DiffTreeEdge edges = 4; repeated ParseError errors = 5; } message DiffTreeEdge { - int64 source = 1; - int64 target = 2; + int32 source = 1; + int32 target = 2; } message DiffTreeVertex { - int64 diff_vertex_id = 1; + int32 diff_vertex_id = 1; oneof diff_term { DeletedTerm deleted = 2; InsertedTerm inserted = 3; @@ -149,25 +149,10 @@ message MergedTerm { Span after_span = 3; } -enum Language { - UNKNOWN = 0; - GO = 1; - HASKELL = 2; - JAVA = 3; - JAVASCRIPT = 4; - JSON = 5; - JSX = 6; - MARKDOWN = 7; - PYTHON = 8; - RUBY = 9; - TYPESCRIPT = 10; - PHP = 11; -} - message Blob { string content = 1; string path = 2; - Language language = 3; + string language = 3; } message BlobPair { @@ -177,7 +162,7 @@ message BlobPair { message File { string path = 1; - Language language = 2; + string language = 2; repeated Symbol symbols = 3; repeated ParseError errors = 4; } @@ -195,8 +180,8 @@ message Docstring { } message Position { - int64 line = 1; - int64 column = 2; + int32 line = 1; + int32 column = 2; } message Span { diff --git a/src/Data/Abstract/Evaluatable.hs b/src/Data/Abstract/Evaluatable.hs index 5f3d5ee1e..f0ce97e3d 100644 --- a/src/Data/Abstract/Evaluatable.hs +++ b/src/Data/Abstract/Evaluatable.hs @@ -30,7 +30,7 @@ import Data.Abstract.Declarations as X import Data.Abstract.FreeVariables as X import Data.Abstract.Module import Data.Abstract.Name as X -import qualified Data.Abstract.ScopeGraph as ScopeGraph +import qualified Data.Abstract.ScopeGraph as ScopeGraph import Data.Abstract.ScopeGraph (Relation(..)) import Data.Abstract.AccessControls.Class as X import Data.Language diff --git a/src/Data/Syntax/Expression.hs b/src/Data/Syntax/Expression.hs index 888143b3f..bf4729752 100644 --- a/src/Data/Syntax/Expression.hs +++ b/src/Data/Syntax/Expression.hs @@ -5,8 +5,8 @@ module Data.Syntax.Expression where import Prelude hiding (null) import Prologue hiding (This, index, null) -import Control.Abstract hiding (Bitwise (..), Call, Member, Void) -import Data.Abstract.Evaluatable as Abstract hiding (Member, Void) +import Control.Abstract hiding (Bitwise (..), Call, Member) +import Data.Abstract.Evaluatable as Abstract hiding (Member) import Data.Abstract.Name as Name import Data.Abstract.Number (liftIntegralFrac, liftReal, liftedExponent, liftedFloorDiv) import Data.Fixed diff --git a/src/Data/Syntax/Type.hs b/src/Data/Syntax/Type.hs index 953cdd583..96d5603ea 100644 --- a/src/Data/Syntax/Type.hs +++ b/src/Data/Syntax/Type.hs @@ -2,7 +2,7 @@ {-# OPTIONS_GHC -Wno-missing-export-lists #-} module Data.Syntax.Type where -import Data.Abstract.Evaluatable hiding (Void) +import Data.Abstract.Evaluatable import Data.JSON.Fields import Diffing.Algorithm import Prelude hiding (Bool, Float, Int, Double) diff --git a/src/Rendering/Graph.hs b/src/Rendering/Graph.hs index 400ac8d99..69fc940ff 100644 --- a/src/Rendering/Graph.hs +++ b/src/Rendering/Graph.hs @@ -11,6 +11,7 @@ import Analysis.ConstructorName import Control.Effect import Control.Effect.Fresh import Control.Effect.Reader +import Control.Effect.State import Data.Diff import Data.Graph import Data.Location @@ -28,9 +29,13 @@ renderTreeGraph :: (Ord vertex, Recursive t, ToTreeGraph vertex (Base t)) => t - renderTreeGraph = simplify . runGraph . cata toTreeGraph runGraph :: ReaderC (Graph vertex) - (FreshC VoidC) (Graph vertex) + (FreshC PureC) (Graph vertex) -> Graph vertex -runGraph = run . runFresh . runReader mempty +runGraph = run . runFresh' . runReader mempty + where + -- NB: custom runFresh so that we count starting at 1 in order to avoid + -- default values for proto encoding. + runFresh' = evalState 1 . runFreshC -- | GraphViz styling for terms termStyle :: (IsString string, Monoid string) => String -> Style TermVertex string diff --git a/src/Reprinting/Translate.hs b/src/Reprinting/Translate.hs index c5081c126..eb5208475 100644 --- a/src/Reprinting/Translate.hs +++ b/src/Reprinting/Translate.hs @@ -20,7 +20,7 @@ import qualified Data.Source as Source type Translator = StateC [Scope] - ( ErrorC TranslationError VoidC) + ( ErrorC TranslationError PureC) contextualizing :: ProcessT Translator Token Fragment contextualizing = repeatedly $ await >>= \case diff --git a/src/Semantic/Api.hs b/src/Semantic/Api.hs index a284654af..54d1861ee 100644 --- a/src/Semantic/Api.hs +++ b/src/Semantic/Api.hs @@ -11,4 +11,4 @@ import Semantic.Api.Diffs as DiffsAPI import Semantic.Api.Symbols as SymbolsAPI import Semantic.Api.Terms as TermsAPI import Semantic.Api.TOCSummaries as TOCSummariesAPI -import Semantic.Api.V1.CodeAnalysisPB as Types hiding (Language(..)) +import Semantic.Api.V1.CodeAnalysisPB as Types diff --git a/src/Semantic/Api/Bridge.hs b/src/Semantic/Api/Bridge.hs index dc5876058..2197fe8b6 100644 --- a/src/Semantic/Api/Bridge.hs +++ b/src/Semantic/Api/Bridge.hs @@ -63,37 +63,37 @@ instance APIConvert Legacy.Span Data.Span where toAPI Data.Span{..} = Legacy.Span (bridging #? spanStart) (bridging #? spanEnd) fromAPI Legacy.Span {..} = Data.Span <$> (start >>= preview bridging) <*> (end >>= preview bridging) -instance APIBridge API.Language Data.Language where +instance APIBridge T.Text Data.Language where bridging = iso apiLanguageToLanguage languageToApiLanguage where - languageToApiLanguage :: Data.Language -> API.Language + languageToApiLanguage :: Data.Language -> T.Text languageToApiLanguage = \case - Data.Unknown -> API.Unknown - Data.Go -> API.Go - Data.Haskell -> API.Haskell - Data.Java -> API.Java - Data.JavaScript -> API.Javascript - Data.JSON -> API.Json - Data.JSX -> API.Jsx - Data.Markdown -> API.Markdown - Data.Python -> API.Python - Data.Ruby -> API.Ruby - Data.TypeScript -> API.Typescript - Data.PHP -> API.Php + Data.Unknown -> "Unknown" + Data.Go -> "Go" + Data.Haskell -> "Haskell" + Data.Java -> "Java" + Data.JavaScript -> "JavaScript" + Data.JSON -> "JSON" + Data.JSX -> "JSX" + Data.Markdown -> "Markdown" + Data.Python -> "Python" + Data.Ruby -> "Ruby" + Data.TypeScript -> "TypeScript" + Data.PHP -> "PHP" - apiLanguageToLanguage :: API.Language -> Data.Language + apiLanguageToLanguage :: T.Text -> Data.Language apiLanguageToLanguage = \case - API.Unknown -> Data.Unknown - API.Go -> Data.Go - API.Haskell -> Data.Haskell - API.Java -> Data.Java - API.Javascript -> Data.JavaScript - API.Json -> Data.JSON - API.Jsx -> Data.JSX - API.Markdown -> Data.Markdown - API.Python -> Data.Python - API.Ruby -> Data.Ruby - API.Typescript -> Data.TypeScript - API.Php -> Data.PHP + "Go" -> Data.Go + "Haskell" -> Data.Haskell + "Java" -> Data.Java + "JavaScript" -> Data.JavaScript + "JSON" -> Data.JSON + "JSX" -> Data.JSX + "Markdown" -> Data.Markdown + "Python" -> Data.Python + "Ruby" -> Data.Ruby + "TypeScript" -> Data.TypeScript + "PHP" -> Data.PHP + _ -> Data.Unknown instance APIBridge API.Blob Data.Blob where bridging = iso apiBlobToBlob blobToApiBlob where diff --git a/src/Semantic/Api/Diffs.hs b/src/Semantic/Api/Diffs.hs index 9b8d8dd29..ecec3bece 100644 --- a/src/Semantic/Api/Diffs.hs +++ b/src/Semantic/Api/Diffs.hs @@ -35,7 +35,7 @@ import Rendering.Graph import Rendering.JSON hiding (JSON) import qualified Rendering.JSON import Semantic.Api.Bridge -import Semantic.Api.V1.CodeAnalysisPB hiding (Blob, BlobPair, Language(..)) +import Semantic.Api.V1.CodeAnalysisPB hiding (Blob, BlobPair) import Semantic.Task as Task import Semantic.Telemetry as Stat import Serializing.Format hiding (JSON) diff --git a/src/Semantic/Api/Terms.hs b/src/Semantic/Api/Terms.hs index 1f38f7add..c95cd762b 100644 --- a/src/Semantic/Api/Terms.hs +++ b/src/Semantic/Api/Terms.hs @@ -38,7 +38,7 @@ import Rendering.Graph import Rendering.JSON hiding (JSON) import qualified Rendering.JSON import Semantic.Api.Bridge -import Semantic.Api.V1.CodeAnalysisPB hiding (Blob, Language (..)) +import Semantic.Api.V1.CodeAnalysisPB hiding (Blob) import Semantic.Task import Serializing.Format hiding (JSON) import qualified Serializing.Format as Format diff --git a/src/Semantic/Api/V1/CodeAnalysisPB.hs b/src/Semantic/Api/V1/CodeAnalysisPB.hs index 9ce828b72..d9675814d 100644 --- a/src/Semantic/Api/V1/CodeAnalysisPB.hs +++ b/src/Semantic/Api/V1/CodeAnalysisPB.hs @@ -3,25 +3,52 @@ {-# OPTIONS_GHC -Wno-unused-imports -Wno-missing-export-lists #-} module Semantic.Api.V1.CodeAnalysisPB where -import Control.DeepSeq -import Data.Aeson -import Data.ByteString (ByteString) -import Data.Int -import Data.Text (Text) -import Data.Vector (Vector) -import Data.Word -import GHC.Generics -import Proto3.Suite -import Proto3.Wire (at, oneof) +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 (Named, FromJSON, ToJSON, NFData) + deriving anyclass (Proto3.Named, NFData) -instance Message PingRequest where +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 + [ + encodeMessageField 1 service ] decodeMessage _ = PingRequest <$> at decodeMessageField 1 @@ -33,11 +60,42 @@ data PingResponse = PingResponse , timestamp :: Text , sha :: Text } deriving stock (Eq, Ord, Show, Generic) - deriving anyclass (Named, FromJSON, ToJSON, NFData) + deriving anyclass (Proto3.Named, NFData) -instance Message PingResponse where +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 1 status , encodeMessageField 2 hostname , encodeMessageField 3 timestamp , encodeMessageField 4 sha @@ -52,11 +110,33 @@ instance Message PingResponse where data ParseTreeRequest = ParseTreeRequest { blobs :: Vector Blob } deriving stock (Eq, Ord, Show, Generic) - deriving anyclass (Named, FromJSON, ToJSON, NFData) + deriving anyclass (Proto3.Named, NFData) -instance Message ParseTreeRequest where +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 (NestedVec blobs) + [ + encodeMessageField 1 (Proto3.NestedVec blobs) ] decodeMessage _ = ParseTreeRequest <$> (nestedvec <$> at decodeMessageField 1) @@ -65,11 +145,33 @@ instance Message ParseTreeRequest where data ParseTreeSymbolResponse = ParseTreeSymbolResponse { files :: Vector File } deriving stock (Eq, Ord, Show, Generic) - deriving anyclass (Named, FromJSON, ToJSON, NFData) + deriving anyclass (Proto3.Named, NFData) -instance Message ParseTreeSymbolResponse where +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 (NestedVec files) + [ + encodeMessageField 1 (Proto3.NestedVec files) ] decodeMessage _ = ParseTreeSymbolResponse <$> (nestedvec <$> at decodeMessageField 1) @@ -78,11 +180,33 @@ instance Message ParseTreeSymbolResponse where data ParseTreeGraphResponse = ParseTreeGraphResponse { files :: Vector ParseTreeFileGraph } deriving stock (Eq, Ord, Show, Generic) - deriving anyclass (Named, FromJSON, ToJSON, NFData) + deriving anyclass (Proto3.Named, NFData) -instance Message ParseTreeGraphResponse where +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 (NestedVec files) + [ + encodeMessageField 1 (Proto3.NestedVec files) ] decodeMessage _ = ParseTreeGraphResponse <$> (nestedvec <$> at decodeMessageField 1) @@ -90,20 +214,54 @@ instance Message ParseTreeGraphResponse where data ParseTreeFileGraph = ParseTreeFileGraph { path :: Text - , language :: Language + , language :: Text , vertices :: Vector TermVertex , edges :: Vector TermEdge , errors :: Vector ParseError } deriving stock (Eq, Ord, Show, Generic) - deriving anyclass (Named, FromJSON, ToJSON, NFData) + deriving anyclass (Proto3.Named, NFData) -instance Message ParseTreeFileGraph where +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 1 path , encodeMessageField 2 language - , encodeMessageField 3 (NestedVec vertices) - , encodeMessageField 4 (NestedVec edges) - , encodeMessageField 5 (NestedVec errors) + , encodeMessageField 3 (Proto3.NestedVec vertices) + , encodeMessageField 4 (Proto3.NestedVec edges) + , encodeMessageField 5 (Proto3.NestedVec errors) ] decodeMessage _ = ParseTreeFileGraph <$> at decodeMessageField 1 @@ -114,14 +272,39 @@ instance Message ParseTreeFileGraph where dotProto = undefined data TermEdge = TermEdge - { source :: Int64 - , target :: Int64 + { source :: Int32 + , target :: Int32 } deriving stock (Eq, Ord, Show, Generic) - deriving anyclass (Named, FromJSON, ToJSON, NFData) + deriving anyclass (Proto3.Named, NFData) -instance Message TermEdge where +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 1 source , encodeMessageField 2 target ] decodeMessage _ = TermEdge @@ -130,17 +313,45 @@ instance Message TermEdge where dotProto = undefined data TermVertex = TermVertex - { vertexId :: Int64 + { vertexId :: Int32 , term :: Text , span :: Maybe Span } deriving stock (Eq, Ord, Show, Generic) - deriving anyclass (Named, FromJSON, ToJSON, NFData) + deriving anyclass (Proto3.Named, NFData) -instance Message TermVertex where +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 1 vertexId , encodeMessageField 2 term - , encodeMessageField 3 (Nested span) + , encodeMessageField 3 (Proto3.Nested span) ] decodeMessage _ = TermVertex <$> at decodeMessageField 1 @@ -151,11 +362,33 @@ instance Message TermVertex where data ParseError = ParseError { error :: Text } deriving stock (Eq, Ord, Show, Generic) - deriving anyclass (Named, FromJSON, ToJSON, NFData) + deriving anyclass (Proto3.Named, NFData) -instance Message ParseError where +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 + [ + encodeMessageField 1 error ] decodeMessage _ = ParseError <$> at decodeMessageField 1 @@ -164,11 +397,33 @@ instance Message ParseError where data DiffTreeRequest = DiffTreeRequest { blobs :: Vector BlobPair } deriving stock (Eq, Ord, Show, Generic) - deriving anyclass (Named, FromJSON, ToJSON, NFData) + deriving anyclass (Proto3.Named, NFData) -instance Message DiffTreeRequest where +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 (NestedVec blobs) + [ + encodeMessageField 1 (Proto3.NestedVec blobs) ] decodeMessage _ = DiffTreeRequest <$> (nestedvec <$> at decodeMessageField 1) @@ -177,11 +432,33 @@ instance Message DiffTreeRequest where data DiffTreeTOCResponse = DiffTreeTOCResponse { files :: Vector TOCSummaryFile } deriving stock (Eq, Ord, Show, Generic) - deriving anyclass (Named, FromJSON, ToJSON, NFData) + deriving anyclass (Proto3.Named, NFData) -instance Message DiffTreeTOCResponse where +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 (NestedVec files) + [ + encodeMessageField 1 (Proto3.NestedVec files) ] decodeMessage _ = DiffTreeTOCResponse <$> (nestedvec <$> at decodeMessageField 1) @@ -189,18 +466,49 @@ instance Message DiffTreeTOCResponse where data TOCSummaryFile = TOCSummaryFile { path :: Text - , language :: Language + , language :: Text , changes :: Vector TOCSummaryChange , errors :: Vector TOCSummaryError } deriving stock (Eq, Ord, Show, Generic) - deriving anyclass (Named, FromJSON, ToJSON, NFData) + deriving anyclass (Proto3.Named, NFData) -instance Message TOCSummaryFile where +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 1 path , encodeMessageField 2 language - , encodeMessageField 3 (NestedVec changes) - , encodeMessageField 4 (NestedVec errors) + , encodeMessageField 3 (Proto3.NestedVec changes) + , encodeMessageField 4 (Proto3.NestedVec errors) ] decodeMessage _ = TOCSummaryFile <$> at decodeMessageField 1 @@ -215,13 +523,44 @@ data TOCSummaryChange = TOCSummaryChange , span :: Maybe Span , changeType :: ChangeType } deriving stock (Eq, Ord, Show, Generic) - deriving anyclass (Named, FromJSON, ToJSON, NFData) + deriving anyclass (Proto3.Named, NFData) -instance Message TOCSummaryChange where +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 1 category , encodeMessageField 2 term - , encodeMessageField 3 (Nested span) + , encodeMessageField 3 (Proto3.Nested span) , encodeMessageField 4 changeType ] decodeMessage _ = TOCSummaryChange @@ -235,12 +574,37 @@ data TOCSummaryError = TOCSummaryError { error :: Text , span :: Maybe Span } deriving stock (Eq, Ord, Show, Generic) - deriving anyclass (Named, FromJSON, ToJSON, NFData) + deriving anyclass (Proto3.Named, NFData) -instance Message TOCSummaryError where +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 (Nested span) + [ + encodeMessageField 1 error + , encodeMessageField 2 (Proto3.Nested span) ] decodeMessage _ = TOCSummaryError <$> at decodeMessageField 1 @@ -250,11 +614,33 @@ instance Message TOCSummaryError where data DiffTreeGraphResponse = DiffTreeGraphResponse { files :: Vector DiffTreeFileGraph } deriving stock (Eq, Ord, Show, Generic) - deriving anyclass (Named, FromJSON, ToJSON, NFData) + deriving anyclass (Proto3.Named, NFData) -instance Message DiffTreeGraphResponse where +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 (NestedVec files) + [ + encodeMessageField 1 (Proto3.NestedVec files) ] decodeMessage _ = DiffTreeGraphResponse <$> (nestedvec <$> at decodeMessageField 1) @@ -262,20 +648,54 @@ instance Message DiffTreeGraphResponse where data DiffTreeFileGraph = DiffTreeFileGraph { path :: Text - , language :: Language + , language :: Text , vertices :: Vector DiffTreeVertex , edges :: Vector DiffTreeEdge , errors :: Vector ParseError } deriving stock (Eq, Ord, Show, Generic) - deriving anyclass (Named, FromJSON, ToJSON, NFData) + deriving anyclass (Proto3.Named, NFData) -instance Message DiffTreeFileGraph where +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 1 path , encodeMessageField 2 language - , encodeMessageField 3 (NestedVec vertices) - , encodeMessageField 4 (NestedVec edges) - , encodeMessageField 5 (NestedVec errors) + , encodeMessageField 3 (Proto3.NestedVec vertices) + , encodeMessageField 4 (Proto3.NestedVec edges) + , encodeMessageField 5 (Proto3.NestedVec errors) ] decodeMessage _ = DiffTreeFileGraph <$> at decodeMessageField 1 @@ -286,14 +706,39 @@ instance Message DiffTreeFileGraph where dotProto = undefined data DiffTreeEdge = DiffTreeEdge - { source :: Int64 - , target :: Int64 + { source :: Int32 + , target :: Int32 } deriving stock (Eq, Ord, Show, Generic) - deriving anyclass (Named, FromJSON, ToJSON, NFData) + deriving anyclass (Proto3.Named, NFData) -instance Message DiffTreeEdge where +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 1 source , encodeMessageField 2 target ] decodeMessage _ = DiffTreeEdge @@ -302,22 +747,73 @@ instance Message DiffTreeEdge where dotProto = undefined data DiffTreeVertexDiffTerm - = Deleted { deleted :: Maybe DeletedTerm } - | Inserted { inserted :: Maybe InsertedTerm } - | Replaced { replaced :: Maybe ReplacedTerm } - | Merged { merged :: Maybe MergedTerm } + = Deleted (Maybe DeletedTerm) + | Inserted (Maybe InsertedTerm) + | Replaced (Maybe ReplacedTerm) + | Merged (Maybe MergedTerm) deriving stock (Eq, Ord, Show, Generic) - deriving anyclass (Message, Named, FromJSON, ToJSON, NFData) + 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 :: Int64 + { diffVertexId :: Int32 , diffTerm :: Maybe DiffTreeVertexDiffTerm } deriving stock (Eq, Ord, Show, Generic) - deriving anyclass (Named, FromJSON, ToJSON, NFData) + deriving anyclass (Proto3.Named, NFData) -instance Message DiffTreeVertex where +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 + [ + encodeMessageField 1 diffVertexId , case diffTerm of Nothing -> mempty Just (Deleted deleted) -> encodeMessageField 2 deleted @@ -329,7 +825,8 @@ instance Message DiffTreeVertex where <$> at decodeMessageField 1 <*> oneof Nothing - [ (2, Just . Deleted <$> decodeMessageField) + [ + (2, Just . Deleted <$> decodeMessageField) , (3, Just . Inserted <$> decodeMessageField) , (4, Just . Replaced <$> decodeMessageField) , (5, Just . Merged <$> decodeMessageField) @@ -340,12 +837,37 @@ data DeletedTerm = DeletedTerm { term :: Text , span :: Maybe Span } deriving stock (Eq, Ord, Show, Generic) - deriving anyclass (Named, FromJSON, ToJSON, NFData) + deriving anyclass (Proto3.Named, NFData) -instance Message DeletedTerm where +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 (Nested span) + [ + encodeMessageField 1 term + , encodeMessageField 2 (Proto3.Nested span) ] decodeMessage _ = DeletedTerm <$> at decodeMessageField 1 @@ -356,12 +878,37 @@ data InsertedTerm = InsertedTerm { term :: Text , span :: Maybe Span } deriving stock (Eq, Ord, Show, Generic) - deriving anyclass (Named, FromJSON, ToJSON, NFData) + deriving anyclass (Proto3.Named, NFData) -instance Message InsertedTerm where +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 (Nested span) + [ + encodeMessageField 1 term + , encodeMessageField 2 (Proto3.Nested span) ] decodeMessage _ = InsertedTerm <$> at decodeMessageField 1 @@ -374,14 +921,45 @@ data ReplacedTerm = ReplacedTerm , afterTerm :: Text , afterSpan :: Maybe Span } deriving stock (Eq, Ord, Show, Generic) - deriving anyclass (Named, FromJSON, ToJSON, NFData) + deriving anyclass (Proto3.Named, NFData) -instance Message ReplacedTerm where +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 (Nested beforeSpan) + [ + encodeMessageField 1 beforeTerm + , encodeMessageField 2 (Proto3.Nested beforeSpan) , encodeMessageField 3 afterTerm - , encodeMessageField 4 (Nested afterSpan) + , encodeMessageField 4 (Proto3.Nested afterSpan) ] decodeMessage _ = ReplacedTerm <$> at decodeMessageField 1 @@ -395,13 +973,41 @@ data MergedTerm = MergedTerm , beforeSpan :: Maybe Span , afterSpan :: Maybe Span } deriving stock (Eq, Ord, Show, Generic) - deriving anyclass (Named, FromJSON, ToJSON, NFData) + deriving anyclass (Proto3.Named, NFData) -instance Message MergedTerm where +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 (Nested beforeSpan) - , encodeMessageField 3 (Nested afterSpan) + [ + encodeMessageField 1 term + , encodeMessageField 2 (Proto3.Nested beforeSpan) + , encodeMessageField 3 (Proto3.Nested afterSpan) ] decodeMessage _ = MergedTerm <$> at decodeMessageField 1 @@ -412,13 +1018,41 @@ instance Message MergedTerm where data Blob = Blob { content :: Text , path :: Text - , language :: Language + , language :: Text } deriving stock (Eq, Ord, Show, Generic) - deriving anyclass (Named, FromJSON, ToJSON, NFData) + deriving anyclass (Proto3.Named, NFData) -instance Message Blob where +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 1 content , encodeMessageField 2 path , encodeMessageField 3 language ] @@ -432,12 +1066,37 @@ data BlobPair = BlobPair { before :: Maybe Blob , after :: Maybe Blob } deriving stock (Eq, Ord, Show, Generic) - deriving anyclass (Named, FromJSON, ToJSON, NFData) + deriving anyclass (Proto3.Named, NFData) -instance Message BlobPair where +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 (Nested before) - , encodeMessageField 2 (Nested after) + [ + encodeMessageField 1 (Proto3.Nested before) + , encodeMessageField 2 (Proto3.Nested after) ] decodeMessage _ = BlobPair <$> at decodeMessageField 1 @@ -446,18 +1105,49 @@ instance Message BlobPair where data File = File { path :: Text - , language :: Language + , language :: Text , symbols :: Vector Symbol , errors :: Vector ParseError } deriving stock (Eq, Ord, Show, Generic) - deriving anyclass (Named, FromJSON, ToJSON, NFData) + deriving anyclass (Proto3.Named, NFData) -instance Message File where +instance FromJSONPB File where + parseJSONPB = A.withObject "File" $ \obj -> File + <$> obj .: "path" + <*> obj .: "language" + <*> obj .: "symbols" + <*> obj .: "errors" + +instance ToJSONPB File where + toJSONPB File{..} = object + [ + "path" .= path + , "language" .= language + , "symbols" .= symbols + , "errors" .= errors + ] + toEncodingPB File{..} = pairs + [ + "path" .= path + , "language" .= language + , "symbols" .= symbols + , "errors" .= errors + ] + +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 1 path , encodeMessageField 2 language - , encodeMessageField 3 (NestedVec symbols) - , encodeMessageField 4 (NestedVec errors) + , encodeMessageField 3 (Proto3.NestedVec symbols) + , encodeMessageField 4 (Proto3.NestedVec errors) ] decodeMessage _ = File <$> at decodeMessageField 1 @@ -473,15 +1163,49 @@ data Symbol = Symbol , span :: Maybe Span , docs :: Maybe Docstring } deriving stock (Eq, Ord, Show, Generic) - deriving anyclass (Named, FromJSON, ToJSON, NFData) + deriving anyclass (Proto3.Named, NFData) -instance Message Symbol where +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 1 symbol , encodeMessageField 2 kind , encodeMessageField 3 line - , encodeMessageField 4 (Nested span) - , encodeMessageField 5 (Nested docs) + , encodeMessageField 4 (Proto3.Nested span) + , encodeMessageField 5 (Proto3.Nested docs) ] decodeMessage _ = Symbol <$> at decodeMessageField 1 @@ -494,25 +1218,72 @@ instance Message Symbol where data Docstring = Docstring { docstring :: Text } deriving stock (Eq, Ord, Show, Generic) - deriving anyclass (Named, FromJSON, ToJSON, NFData) + deriving anyclass (Proto3.Named, NFData) -instance Message Docstring where +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 + [ + encodeMessageField 1 docstring ] decodeMessage _ = Docstring <$> at decodeMessageField 1 dotProto = undefined data Position = Position - { line :: Int64 - , column :: Int64 + { line :: Int32 + , column :: Int32 } deriving stock (Eq, Ord, Show, Generic) - deriving anyclass (Named, FromJSON, ToJSON, NFData) + deriving anyclass (Proto3.Named, NFData) -instance Message Position where +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 1 line , encodeMessageField 2 column ] decodeMessage _ = Position @@ -524,12 +1295,37 @@ data Span = Span { start :: Maybe Position , end :: Maybe Position } deriving stock (Eq, Ord, Show, Generic) - deriving anyclass (Named, FromJSON, ToJSON, NFData) + deriving anyclass (Proto3.Named, NFData) -instance Message Span where +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 (Nested start) - , encodeMessageField 2 (Nested end) + [ + encodeMessageField 1 (Proto3.Nested start) + , encodeMessageField 2 (Proto3.Nested end) ] decodeMessage _ = Span <$> at decodeMessageField 1 @@ -542,24 +1338,25 @@ data ChangeType | Removed | Modified deriving stock (Eq, Ord, Show, Enum, Bounded, Generic) - deriving anyclass (Named, MessageField, FromJSON, ToJSON, NFData) - deriving Primitive via PrimitiveEnum ChangeType -instance HasDefault ChangeType where def = None + deriving anyclass (Proto3.Named, Proto3.MessageField, NFData) + deriving Proto3.Primitive via Proto3.PrimitiveEnum ChangeType -data Language - = Unknown - | Go - | Haskell - | Java - | Javascript - | Json - | Jsx - | Markdown - | Python - | Ruby - | Typescript - | Php - deriving stock (Eq, Ord, Show, Enum, Bounded, Generic) - deriving anyclass (Named, MessageField, FromJSON, ToJSON, NFData) - deriving Primitive via PrimitiveEnum Language -instance HasDefault Language where def = Unknown +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/Semantic/Util.hs b/src/Semantic/Util.hs index cd80aeb82..819d34573 100644 --- a/src/Semantic/Util.hs +++ b/src/Semantic/Util.hs @@ -479,6 +479,9 @@ scopeGraphRubyProject = justEvaluatingCatchingErrors <=< evaluateProjectForScope scopeGraphPHPProject :: ProjectEvaluator Language.PHP.Assignment.Syntax scopeGraphPHPProject = justEvaluatingCatchingErrors <=< evaluateProjectForScopeGraph (Proxy @'Language.PHP) phpParser +scopeGraphPythonProject :: ProjectEvaluator Language.Python.Assignment.Syntax +scopeGraphPythonProject = justEvaluatingCatchingErrors <=< evaluateProjectForScopeGraph (Proxy @'Language.Python) pythonParser + scopeGraphGoProject :: ProjectEvaluator Language.Go.Assignment.Syntax scopeGraphGoProject = justEvaluatingCatchingErrors <=< evaluateProjectForScopeGraph (Proxy @'Language.Go) goParser diff --git a/src/Tags/Tagging.hs b/src/Tags/Tagging.hs index 0549a33a3..2cc205d4b 100644 --- a/src/Tags/Tagging.hs +++ b/src/Tags/Tagging.hs @@ -39,7 +39,7 @@ type ContextToken = (Text, Maybe Range) type Contextualizer = StateC [ContextToken] - ( ErrorC TranslationError VoidC) + ( ErrorC TranslationError PureC) contextualizing :: Blob -> Machine.ProcessT Contextualizer Token Tag contextualizing Blob{..} = repeatedly $ await >>= \case diff --git a/test/Rendering/TOC/Spec.hs b/test/Rendering/TOC/Spec.hs index 4f014f6d4..d054d24e7 100644 --- a/test/Rendering/TOC/Spec.hs +++ b/test/Rendering/TOC/Spec.hs @@ -149,22 +149,22 @@ spec = parallel $ do it "produces JSON output" $ do blobs <- blobsForPaths (Both "ruby/toc/methods.A.rb" "ruby/toc/methods.B.rb") 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\",\"changes\":[{\"span\":{\"start\":{\"line\":1,\"column\":1},\"end\":{\"line\":2,\"column\":4}},\"category\":\"Method\",\"term\":\"self.foo\",\"changeType\":\"Added\"},{\"span\":{\"start\":{\"line\":4,\"column\":1},\"end\":{\"line\":6,\"column\":4}},\"category\":\"Method\",\"term\":\"bar\",\"changeType\":\"Modified\"},{\"span\":{\"start\":{\"line\":4,\"column\":1},\"end\":{\"line\":5,\"column\":4}},\"category\":\"Method\",\"term\":\"baz\",\"changeType\":\"Removed\"}],\"language\":\"Ruby\",\"errors\":[]}]}\n" :: ByteString) + 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 "ruby/toc/methods.A.rb" "ruby/toc/methods.X.rb") 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\",\"changes\":[{\"span\":{\"start\":{\"line\":1,\"column\":1},\"end\":{\"line\":2,\"column\":4}},\"category\":\"Method\",\"term\":\"bar\",\"changeType\":\"Removed\"},{\"span\":{\"start\":{\"line\":4,\"column\":1},\"end\":{\"line\":5,\"column\":4}},\"category\":\"Method\",\"term\":\"baz\",\"changeType\":\"Removed\"}],\"language\":\"Ruby\",\"errors\":[{\"span\":{\"start\":{\"line\":1,\"column\":1},\"end\":{\"line\":2,\"column\":3}},\"error\":\"expected end of input nodes, but got ParseError\"}]}]}\n" :: ByteString) + 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 "ruby/toc/lambda.A.rb" "ruby/toc/lambda.B.rb") 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\",\"changes\":[],\"language\":\"Ruby\",\"errors\":[]}]}\n" :: ByteString) + 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 "markdown/toc/headings.A.md" "markdown/toc/headings.B.md") 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\",\"changes\":[{\"span\":{\"start\":{\"line\":1,\"column\":1},\"end\":{\"line\":3,\"column\":16}},\"category\":\"Heading 1\",\"term\":\"Introduction\",\"changeType\":\"Removed\"},{\"span\":{\"start\":{\"line\":5,\"column\":1},\"end\":{\"line\":7,\"column\":4}},\"category\":\"Heading 2\",\"term\":\"Two\",\"changeType\":\"Modified\"},{\"span\":{\"start\":{\"line\":9,\"column\":1},\"end\":{\"line\":11,\"column\":10}},\"category\":\"Heading 3\",\"term\":\"This heading is new\",\"changeType\":\"Added\"},{\"span\":{\"start\":{\"line\":13,\"column\":1},\"end\":{\"line\":14,\"column\":4}},\"category\":\"Heading 1\",\"term\":\"Final\",\"changeType\":\"Added\"}],\"language\":\"Markdown\",\"errors\":[]}]}\n" :: ByteString) + 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) type Diff' = Diff ListableSyntax (Maybe Declaration) (Maybe Declaration) diff --git a/test/fixtures/cli/diff-tree.toc.json b/test/fixtures/cli/diff-tree.toc.json index 8a25277e5..d23542239 100644 --- a/test/fixtures/cli/diff-tree.toc.json +++ b/test/fixtures/cli/diff-tree.toc.json @@ -2,8 +2,11 @@ "files": [ { "path": "test/fixtures/ruby/corpus/method-declaration.A.rb -> test/fixtures/ruby/corpus/method-declaration.B.rb", + "language": "Ruby", "changes": [ { + "category": "Method", + "term": "bar", "span": { "start": @@ -17,11 +20,7 @@ "column": 4 } }, - "category": "Method", - "term": "bar", - "changeType": "Modified" - }], - "language": "Ruby", - "errors": [] + "changeType": "MODIFIED" + }] }] } diff --git a/test/fixtures/cli/parse-tree.symbols.json b/test/fixtures/cli/parse-tree.symbols.json index 5f58f20f7..eb9282009 100644 --- a/test/fixtures/cli/parse-tree.symbols.json +++ b/test/fixtures/cli/parse-tree.symbols.json @@ -2,8 +2,12 @@ "files": [ { "path": "test/fixtures/ruby/corpus/method-declaration.A.rb", + "language": "Ruby", "symbols": [ { + "symbol": "foo", + "kind": "Method", + "line": "def foo", "span": { "start": @@ -16,13 +20,7 @@ "line": 2, "column": 4 } - }, - "kind": "Method", - "symbol": "foo", - "line": "def foo", - "docs": null - }], - "language": "Ruby", - "errors": [] + } + }] }] } diff --git a/vendor/fused-effects b/vendor/fused-effects index 17b0a846a..25e669599 160000 --- a/vendor/fused-effects +++ b/vendor/fused-effects @@ -1 +1 @@ -Subproject commit 17b0a846aa50fd0dea157624c031a550d8edd469 +Subproject commit 25e66959978147b9ee1510ec3d90cd0045cfba54