Skip to content

Commit f559576

Browse files
authored
Merge pull request #5254 from unisonweb/cp/defn-search-sync
Add FromJSON for Display Object for definition search
2 parents b12baa4 + a49146f commit f559576

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

unison-share-api/src/Unison/Server/Orphans.hs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,15 @@ instance (ToJSON b, ToJSON a) => ToJSON (DisplayObject b a) where
155155
MissingObject sh -> object ["tag" Aeson..= String "MissingObject", "contents" Aeson..= sh]
156156
UserObject a -> object ["tag" Aeson..= String "UserObject", "contents" Aeson..= a]
157157

158+
instance (FromJSON a, FromJSON b) => FromJSON (DisplayObject b a) where
159+
parseJSON = withObject "DisplayObject" \o -> do
160+
tag <- o .: "tag"
161+
case tag of
162+
"BuiltinObject" -> BuiltinObject <$> o .: "contents"
163+
"MissingObject" -> MissingObject <$> o .: "contents"
164+
"UserObject" -> UserObject <$> o .: "contents"
165+
_ -> fail $ "Invalid tag: " <> Text.unpack tag
166+
158167
deriving instance (ToSchema b, ToSchema a) => ToSchema (DisplayObject b a)
159168

160169
-- [21/10/07] Hello, this is Mitchell. Name refactor in progress. Changing internal representation from a flat text to a

0 commit comments

Comments
 (0)