git.iko.soy/rowtype-yoga/purescript-docs-search
on master help sign in
Upgrade package-set, use newer bower-json.
commit14ff0105d29a58aee4e58e55f70208905ef15624 authorklntsky <klntsky@gmail.com> dateFri 7 Aug 2020, 17:01 (6 years ago) parentabbc2b3
5 files changed+36−43
packages.dhall+1−16 src/Docs/Search/DocsJson.purs+11−6 src/Docs/Search/IndexBuilder.purs+5−2 src/Docs/Search/Loader.purs+2−1 src/Docs/Search/TypeDecoder.purs+17−18
packages.dhall+1−16
@@ -2,7 +2,7 @@ let mkPackage =
22 https://raw.githubusercontent.com/purescript/package-sets/psc-0.13.2-20190725/src/mkPackage.dhall sha256:0b197efa1d397ace6eb46b243ff2d73a3da5638d8d0ac8473e8e4a8fc528cf57
33
44let upstream =
5− https://github.com/purescript/package-sets/releases/download/psc-0.13.8/packages.dhall sha256:0e95ec11604dc8afc1b129c4d405dcc17290ce56d7d0665a0ff15617e32bbf03
5+ https://github.com/purescript/package-sets/releases/download/psc-0.13.8-20200724/packages.dhall sha256:bb941d30820a49345a0e88937094d2b9983d939c9fd3a46969b85ce44953d7d9
66
77let overrides = {=}
88
@@ -74,21 +74,6 @@ let additions =
7474 [ "markdown-it", "html-parser-halogen" ]
7575 "https://github.com/nonbili/purescript-markdown-it-halogen.git"
7676 "08c9625015bf04214be14e45230e8ce12f3fa2bf"
77− , bower-json =
78− mkPackage
79− [ "prelude"
80− , "generics-rep"
81− , "maybe"
82− , "arrays"
83− , "either"
84− , "newtype"
85− , "tuples"
86− , "foldable-traversable"
87− , "argonaut-codecs"
88− , "foreign-object"
89− ]
90− "https://github.com/klntsky/purescript-bower-json.git"
91− "v1.0.0"
9277 , toppokki =
9378 mkPackage
9479 [ "prelude"
src/Docs/Search/DocsJson.purs+11−6
@@ -7,6 +7,7 @@ import Docs.Search.TypeDecoder (Constraint, FunDeps, Kind, Type, TypeArgument)
77
88import Data.Argonaut.Core (fromString, stringify, toString)
99import Data.Argonaut.Decode (class DecodeJson, decodeJson, (.:), (.:?))
10+import Data.Argonaut.Decode.Error (JsonDecodeError(..))
1011import Data.Argonaut.Encode (class EncodeJson, encodeJson)
1112import Data.Either (Either(..))
1213import Data.Generic.Rep (class Generic)
@@ -151,7 +152,7 @@ instance encodeJsonDeclType :: EncodeJson DeclType where
151152instance decodeJsonDeclType :: DecodeJson DeclType where
152153 decodeJson json =
153154 case toString json of
154− Nothing -> Left $ "Couldn't decode DeclType: " <> stringify json
155+ Nothing -> errorWith $ "Couldn't decode DeclType: " <> stringify json
155156 Just string ->
156157 case string of
157158 "value" -> Right DeclValue
@@ -161,7 +162,7 @@ instance decodeJsonDeclType :: DecodeJson DeclType where
161162 "typeClass" -> Right DeclTypeClass
162163 "alias" -> Right DeclAlias
163164 "kind" -> Right DeclExternKind
164− _ -> Left $ "Couldn't decode DeclType: " <> string
165+ _ -> errorWith $ "Couldn't decode DeclType: " <> string
165166
166167
167168data ChildDeclType
@@ -184,13 +185,13 @@ instance encodeJsonChildDeclType :: EncodeJson ChildDeclType where
184185instance decodeJsonChildDeclType :: DecodeJson ChildDeclType where
185186 decodeJson json =
186187 case toString json of
187− Nothing -> Left $ "Couldn't decode ChildDeclType: " <> stringify json
188+ Nothing -> errorWith $ "Couldn't decode ChildDeclType: " <> stringify json
188189 Just tag ->
189190 case tag of
190191 "instance" -> Right ChildDeclInstance
191192 "dataConstructor" -> Right ChildDeclDataConstructor
192193 "typeClassMember" -> Right ChildDeclTypeClassMember
193− _ -> Left $ "Couldn't decode ChildDeclType: " <> tag
194+ _ -> errorWith $ "Couldn't decode ChildDeclType: " <> tag
194195
195196
196197data DataDeclType
@@ -215,5 +216,9 @@ instance decodeJsonDataDeclType :: DecodeJson DataDeclType where
215216 case tag of
216217 "newtype" -> Right NewtypeDataDecl
217218 "data" -> Right DataDataDecl
218− _ -> Left $ "Couldn't decode DataDeclType: " <> tag
219− Nothing -> Left $ "Couldn't decode DataDeclType: " <> stringify json
219+ _ -> errorWith $ "Couldn't decode DataDeclType: " <> tag
220+ Nothing -> errorWith $ "Couldn't decode DataDeclType: " <> stringify json
221+
222+
223+errorWith :: forall a. String -> Either JsonDecodeError a
224+errorWith = Left <<< TypeMismatch
src/Docs/Search/IndexBuilder.purs+5−2
@@ -14,8 +14,10 @@ import Docs.Search.Types (PackageName, PartId)
1414import Docs.Search.Meta (Meta)
1515
1616import Prelude
17+
1718import Data.Argonaut.Core (stringify)
1819import Data.Argonaut.Decode (decodeJson)
20+import Data.Argonaut.Decode.Error (printJsonDecodeError)
1921import Data.Argonaut.Encode (encodeJson)
2022import Data.Argonaut.Parser (jsonParser)
2123import Data.Array as Array
@@ -27,6 +29,7 @@ import Data.Map (Map)
2729import Data.Map as Map
2830import Data.Maybe (Maybe(..), fromMaybe)
2931import Data.Newtype (unwrap)
32+import Data.Profunctor.Choice (left)
3033import Data.Search.Trie as Trie
3134import Data.Set as Set
3235import Data.String.CodePoints (contains) as String
@@ -151,7 +154,7 @@ decodeDocsJsons cfg@{ docsFiles } = do
151154 if doesExist then do
152155
153156 contents <- readTextFile UTF8 jsonFile
154− let eiResult = jsonParser contents >>= decodeJson
157+ let eiResult = jsonParser contents >>= left printJsonDecodeError <<< decodeJson
155158
156159 case eiResult of
157160 Left error -> do
@@ -192,7 +195,7 @@ decodeBowerJsons { bowerFiles } = do
192195 join <$> withExisting jsonFileName
193196 \contents ->
194197 either (logError jsonFileName) pure
195− (jsonParser contents >>= decodeJson)
198+ (jsonParser contents >>= left printJsonDecodeError <<< decodeJson)
196199
197200 where
198201 compareNames
src/Docs/Search/Loader.purs+2−1
@@ -7,6 +7,7 @@ import Prelude
77import Control.Monad.Error.Class (throwError)
88import Control.Promise (Promise, toAffE)
99import Data.Argonaut.Core (Json)
10+import Data.Argonaut.Decode.Error (printJsonDecodeError)
1011import Data.Argonaut.Decode.Class (class DecodeJson, decodeJson)
1112import Data.Either (either)
1213import Data.Newtype (unwrap)
@@ -28,7 +29,7 @@ load globalIdentifier url = do
2829 where
2930 throw err = throwError $ error $
3031 "Couldn't load content from window." <>
31− unwrap globalIdentifier <> ": " <> err
32+ unwrap globalIdentifier <> ": " <> printJsonDecodeError err
3233
3334
3435foreign import loadFromScript
src/Docs/Search/TypeDecoder.purs+17−18
@@ -8,13 +8,13 @@ import Control.Alt ((<|>))
88import Data.Argonaut.Core (Json, caseJsonObject, fromArray, fromObject, jsonEmptyObject, stringify, toArray)
99import Data.Argonaut.Decode (class DecodeJson, decodeJson, (.:))
1010import Data.Argonaut.Encode (class EncodeJson, encodeJson)
11−import Data.Array ((!!))
11+import Data.Argonaut.Decode.Error (JsonDecodeError(..))
1212import Data.Either (Either(..))
1313import Data.Generic.Rep (class Generic)
1414import Data.Generic.Rep.Show (genericShow)
1515import Data.List (List(..), (:))
1616import Data.List as List
17−import Data.Maybe (Maybe(..), fromMaybe)
17+import Data.Maybe (Maybe(..))
1818import Data.Newtype (class Newtype)
1919import Data.Tuple (Tuple(..))
2020import Foreign.Object as Object
@@ -42,11 +42,11 @@ instance encodeJsonQualifiedName :: EncodeJson QualifiedName where
4242 encodeJson (QualifiedName { moduleNameParts, name }) =
4343 encodeTuple moduleNameParts name
4444
45−mkJsonError :: String -> Json -> (forall i. i -> String)
45+mkJsonError :: String -> Json -> (forall i. i -> JsonDecodeError)
4646mkJsonError name json _ =
47− "Couldn't parse " <> name <> " from " <> stringify json
47+ TypeMismatch $ "Couldn't parse " <> name <> " from " <> stringify json
4848
49−mkJsonError' :: String -> Json -> String
49+mkJsonError' :: String -> Json -> JsonDecodeError
5050mkJsonError' name json = mkJsonError name json unit
5151
5252-- | The data type of kinds
@@ -294,17 +294,16 @@ decodeTuple
294294 . DecodeJson fst
295295 => DecodeJson sec
296296 => (fst -> sec -> res)
297− -> (forall a. a -> String)
297+ -> (forall a. a -> JsonDecodeError)
298298 -> Json
299− -> Either String res
299+ -> Either JsonDecodeError res
300300decodeTuple cont err json =
301− fromMaybe (Left $ err unit) $
302− toArray json >>= \jsons ->
303− jsons !! 0 >>= \json1 ->
304− jsons !! 1 >>= \json2 -> pure $ do
305− fst <- decodeJson json1
306− sec <- decodeJson json2
307− pure $ cont fst sec
301+ case toArray json of
302+ Just [ json1, json2 ] -> do
303+ fst <- decodeJson json1
304+ sec <- decodeJson json2
305+ pure $ cont fst sec
306+ _ -> Left $ err unit
308307
309308-- | Decode a heterogeneous triple.
310309decodeTriple
@@ -313,9 +312,9 @@ decodeTriple
313312 => DecodeJson sec
314313 => DecodeJson trd
315314 => (fst -> sec -> trd -> res)
316− -> (forall a. a -> String)
315+ -> (forall a. a -> JsonDecodeError)
317316 -> Json
318− -> Either String res
317+ -> Either JsonDecodeError res
319318decodeTriple cont err json =
320319 case toArray json of
321320 Just [ json1, json2, json3 ] -> do
@@ -333,9 +332,9 @@ decodeQuadriple
333332 => DecodeJson trd
334333 => DecodeJson frt
335334 => (fst -> sec -> trd -> frt -> res)
336− -> (forall a. a -> String)
335+ -> (forall a. a -> JsonDecodeError)
337336 -> Json
338− -> Either String res
337+ -> Either JsonDecodeError res
339338decodeQuadriple cont err json =
340339 case toArray json of
341340 Just [ json1, json2, json3, json4 ] -> do