From 572c24d36d6aebf5e478ee527a4f3eb875bbec72 Mon Sep 17 00:00:00 2001 From: Timothy Clem Date: Thu, 8 Jun 2017 07:01:03 -0700 Subject: [PATCH] Auto derive ToJSON right in Language.hs --- src/Language.hs | 5 +++-- src/Renderer/JSON.hs | 2 -- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/src/Language.hs b/src/Language.hs index f1ee8ecfc..3ac854757 100644 --- a/src/Language.hs +++ b/src/Language.hs @@ -1,6 +1,7 @@ -{-# LANGUAGE DataKinds, DeriveGeneric #-} +{-# LANGUAGE DataKinds, DeriveGeneric, DeriveAnyClass #-} module Language where +import Data.Aeson import Data.Record import Data.String import Info @@ -16,7 +17,7 @@ data Language = | Ruby | TypeScript -- ^ Also JavaScript. | Python - deriving (Show, Eq, Read, Generic) + deriving (Show, Eq, Read, Generic, ToJSON) -- | Returns a Language based on the file extension (including the "."). languageForType :: String -> Maybe Language diff --git a/src/Renderer/JSON.hs b/src/Renderer/JSON.hs index 6b0676fd0..58ad2bac7 100644 --- a/src/Renderer/JSON.hs +++ b/src/Renderer/JSON.hs @@ -113,8 +113,6 @@ instance ToJSONFields (Union '[] a) where data File a = File { filePath :: FilePath, fileLanguage :: Maybe Language, fileContent :: a } deriving (Generic, Show) -instance ToJSON Language - instance ToJSON a => ToJSON (File a) where toJSON File{..} = object [ "filePath" .= filePath, "language" .= fileLanguage, "programNode" .= fileContent ]