1
1
mirror of https://github.com/github/semantic.git synced 2024-12-21 22:01:46 +03:00

Remove HasDefault and Primitive instances for Language.

Those instances are handled by the bridged data types in `Semantic.Api`.
Keeping this around is both unnecessary and is making #139 go all
wobbly for reasons that are still unclear to me.
This commit is contained in:
Patrick Thomson 2019-06-13 14:14:57 -04:00
parent e4fdb7f492
commit 838f09e31c

View File

@ -17,7 +17,6 @@ import Data.Char (toUpper)
import Data.String
import qualified Data.Text as T
import Prologue
import Proto3.Suite
import System.FilePath.Posix
-- | The various languages we support.
@ -107,18 +106,6 @@ parseLanguage l = case T.toLower l of
knownLanguage :: Language -> Bool
knownLanguage = (/= Unknown)
-- | Defaults to 'Unknown'.
instance HasDefault Language where def = Unknown
-- | Piggybacks on top of the 'Enumerated' instance, as the generated code would.
-- This instance will get easier when we have DerivingVia.
instance Primitive Language where
primType _ = primType (Proxy @(Enumerated Language))
encodePrimitive f = encodePrimitive f . Enumerated . Right
decodePrimitive = decodePrimitive >>= \case
(Enumerated (Right r)) -> pure r
other -> Prelude.fail ("Language decodeMessageField: unexpected value" <> show other)
-- | Returns a Language based on the file extension (including the ".").
languageForType :: String -> Language
languageForType mediaType = case mediaType of