1
1
mirror of https://github.com/github/semantic.git synced 2024-12-26 00:12:29 +03:00

Auto derive ToJSON right in Language.hs

This commit is contained in:
Timothy Clem 2017-06-08 07:01:03 -07:00
parent feb54b14ad
commit 572c24d36d
2 changed files with 3 additions and 4 deletions

View File

@ -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

View File

@ -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 ]