mirror of
https://github.com/github/semantic.git
synced 2024-12-25 16:02:43 +03:00
Auto derive ToJSON right in Language.hs
This commit is contained in:
parent
feb54b14ad
commit
572c24d36d
@ -1,6 +1,7 @@
|
|||||||
{-# LANGUAGE DataKinds, DeriveGeneric #-}
|
{-# LANGUAGE DataKinds, DeriveGeneric, DeriveAnyClass #-}
|
||||||
module Language where
|
module Language where
|
||||||
|
|
||||||
|
import Data.Aeson
|
||||||
import Data.Record
|
import Data.Record
|
||||||
import Data.String
|
import Data.String
|
||||||
import Info
|
import Info
|
||||||
@ -16,7 +17,7 @@ data Language =
|
|||||||
| Ruby
|
| Ruby
|
||||||
| TypeScript -- ^ Also JavaScript.
|
| TypeScript -- ^ Also JavaScript.
|
||||||
| Python
|
| Python
|
||||||
deriving (Show, Eq, Read, Generic)
|
deriving (Show, Eq, Read, Generic, ToJSON)
|
||||||
|
|
||||||
-- | Returns a Language based on the file extension (including the ".").
|
-- | Returns a Language based on the file extension (including the ".").
|
||||||
languageForType :: String -> Maybe Language
|
languageForType :: String -> Maybe Language
|
||||||
|
@ -113,8 +113,6 @@ instance ToJSONFields (Union '[] a) where
|
|||||||
data File a = File { filePath :: FilePath, fileLanguage :: Maybe Language, fileContent :: a }
|
data File a = File { filePath :: FilePath, fileLanguage :: Maybe Language, fileContent :: a }
|
||||||
deriving (Generic, Show)
|
deriving (Generic, Show)
|
||||||
|
|
||||||
instance ToJSON Language
|
|
||||||
|
|
||||||
instance ToJSON a => ToJSON (File a) where
|
instance ToJSON a => ToJSON (File a) where
|
||||||
toJSON File{..} = object [ "filePath" .= filePath, "language" .= fileLanguage, "programNode" .= fileContent ]
|
toJSON File{..} = object [ "filePath" .= filePath, "language" .= fileLanguage, "programNode" .= fileContent ]
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user