git.iko.soy/rowtype-yoga/purescript-docs-search
on master help sign in
Updates for v0.14 (#46)

Co-authored-by: Fabrizio Ferrai <fabrizio.ferrai@gmail.com>

commitc22dc0b2a6013bf6c49ae8bc555699734456dfe6 authorVladimir Kalnitsky <klntsky@gmail.com> dateThu 15 Apr 2021, 22:15 (5 years ago) parent58ce738
26 files changed+227−487
package.json+8−9 packages.dhall+51−10 spago.dhall+54−42 src/Docs/Search/App.purs+10−9 src/Docs/Search/App/SearchField.purs+10−9 src/Docs/Search/App/SearchResults.purs+10−20 src/Docs/Search/App/Sidebar.purs+2−2 src/Docs/Search/BrowserEngine.purs−3 src/Docs/Search/Declarations.purs+3−3 src/Docs/Search/DocsJson.purs+4−4 src/Docs/Search/IndexBuilder.purs+1−1 src/Docs/Search/Interactive.purs+5−5 src/Docs/Search/Main.purs+1−1 src/Docs/Search/ModuleIndex.purs+4−4 src/Docs/Search/PackageIndex.purs+3−2 src/Docs/Search/Score.purs+1−1 src/Docs/Search/SearchResult.purs+5−5 src/Docs/Search/TypeDecoder.purs+8−49 src/Docs/Search/TypeIndex.purs+4−5 src/Docs/Search/TypePrinter.purs+5−14 src/Docs/Search/TypeQuery.purs+3−3 src/Docs/Search/TypeShape.purs+2−2 src/Docs/Search/Types.purs+3−3 src/Docs/Search/URIHash.purs+1−1 test/Main.purs+28−279 test/Test/TypeQuery.purs+1−1
package.json+8−9
@@ -17,15 +17,14 @@
1717 "scripts": {
1818 "test": "spago docs --no-search && ./dist/purescript-docs-search build-index && spago test && npm run check-version",
1919 "bundle-app": "spago bundle-app --no-build --no-install -m Docs.Search.App --to dist/docs-search-app.js",
20− "parcel-app": "parcel build --no-source-maps --target browser --out-file dist/docs-search-app.js dist/docs-search-app.js",
21− "build-app": "npm run bundle-app && npm run parcel-app",
20+ "esbuild-app": "esbuild dist/docs-search-app.js --target=es2016 --bundle --minify --outfile=dist/docs-search-app.min.js && mv dist/docs-search-app.min.js dist/docs-search-app.js",
21+ "build-app": "npm run bundle-app && npm run esbuild-app",
2222 "bundle-main": "spago bundle-app --no-build --no-install -m Docs.Search.Main --to dist/main.js",
23− "parcel-main": "parcel build --no-source-maps --target node --bundle-node-modules --out-file dist/main.js dist/main.js",
23+ "esbuild-main": "esbuild dist/main.js --platform=node --bundle --minify --outfile=dist/main.min.js && mv dist/main.min.js dist/main.js",
2424 "add-shebang": "echo \"#!/usr/bin/env node\" > dist/purescript-docs-search && cat dist/main.js >> dist/purescript-docs-search",
2525 "chmod-main": "chmod +x dist/purescript-docs-search",
26− "build-main": "npm run bundle-main && npm run parcel-main && npm run add-shebang && rm dist/main.js && npm run chmod-main",
26+ "build-main": "npm run bundle-main && npm run esbuild-main && npm run add-shebang && rm dist/main.js && npm run chmod-main",
2727 "build": "spago build && npm run build-app && npm run build-main",
28− "build-dev": "spago build && npm run build-app && npm run bundle-main && npm run add-shebang && rm dist/main.js && npm run chmod-main",
2928 "clean": "rm -rf dist",
3029 "check-version": "[ \"$(./dist/purescript-docs-search version)\" = \"$npm_package_version\" ]"
3130 },
@@ -44,10 +43,10 @@
4443 "homepage": "https://github.com/spacchetti/purescript-docs-search#readme",
4544 "dependencies": {},
4645 "devDependencies": {
46+ "esbuild": "^0.11.10",
4747 "glob": "^7.1.6",
48− "markdown-it": "^11.0.0",
49− "parcel": "^1.12.4",
50− "puppeteer": "^5.2.1",
51− "spago": "^0.15.3"
48+ "markdown-it": "^12.0.4",
49+ "puppeteer": "^8.0.0",
50+ "spago": "^0.20.0"
5251 }
5352}
packages.dhall+51−10
@@ -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-20200724/packages.dhall sha256:bb941d30820a49345a0e88937094d2b9983d939c9fd3a46969b85ce44953d7d9
5+ https://github.com/purescript/package-sets/releases/download/psc-0.14.0-20210409/packages.dhall sha256:e81c2f2ce790c0e0d79869d22f7a37d16caeb5bd81cfda71d46c58f6199fd33f
66
77let overrides = {=}
88
@@ -13,12 +13,13 @@ let additions =
1313 , "avar"
1414 , "console"
1515 , "const"
16− , "coroutines"
1716 , "dom-indexed"
17+ , "effect"
1818 , "foreign"
1919 , "fork"
2020 , "free"
2121 , "freeap"
22+ , "halogen-subscriptions"
2223 , "halogen-vdom"
2324 , "media-types"
2425 , "nullable"
@@ -28,15 +29,29 @@ let additions =
2829 , "transformers"
2930 , "unsafe-coerce"
3031 , "unsafe-reference"
32+ , "web-file"
3133 , "web-uievents"
3234 ]
33− "https://github.com/slamdata/purescript-halogen.git"
34− "v5.0.0-rc.6"
35+ "https://github.com/purescript-halogen/purescript-halogen.git"
36+ "v6.1.0"
3537 , halogen-css =
3638 mkPackage
37− [ "css", "halogen" ]
39+ [ "halogen" ]
3840 "https://github.com/slamdata/purescript-halogen-css.git"
3941 "v8.0.0"
42+ , memoize =
43+ mkPackage
44+ [ "prelude"
45+ , "lazy"
46+ , "either"
47+ , "maybe"
48+ , "tuples"
49+ , "integers"
50+ , "lists"
51+ , "strings"
52+ ]
53+ "https://github.com/paf31/purescript-memoize.git"
54+ "9960694e82adc212fd89f8ed8778cf55fcb72aeb"
4055 , optparse =
4156 mkPackage
4257 [ "prelude"
@@ -46,14 +61,14 @@ let additions =
4661 , "ordered-collections"
4762 , "arrays"
4863 , "console"
49− , "memoize"
5064 , "transformers"
5165 , "exists"
5266 , "node-process"
5367 , "free"
68+ , "memoize"
5469 ]
55− "https://github.com/f-o-a-m/purescript-optparse.git"
56− "v3.0.1"
70+ "https://github.com/srghma/purescript-optparse.git"
71+ "d49b03fcd35f5be167e9c5c44ab1c17ca0956fb1"
5772 , exitcodes =
5873 mkPackage
5974 [ "enums" ]
@@ -66,9 +81,9 @@ let additions =
6681 "v0.4.0"
6782 , html-parser-halogen =
6883 mkPackage
69− [ "string-parsers", "generics-rep", "halogen" ]
84+ [ "string-parsers", "halogen" ]
7085 "https://github.com/rnons/purescript-html-parser-halogen.git"
71− "890da763cdd2a1049ab8837e477c5ba1fcf6d4ce"
86+ "458e492e441fcf69a66911b7b64beea5849e0dad"
7287 , markdown-it-halogen =
7388 mkPackage
7489 [ "markdown-it", "html-parser-halogen" ]
@@ -86,6 +101,32 @@ let additions =
86101 ]
87102 "https://github.com/justinwoo/purescript-toppokki.git"
88103 "v2.4.0"
104+ , search-trie =
105+ mkPackage
106+ [ "prelude"
107+ , "arrays"
108+ , "ordered-collections"
109+ , "lists"
110+ , "foldable-traversable"
111+ , "bifunctors"
112+ ]
113+ "https://github.com/klntsky/purescript-search-trie.git"
114+ "e7f7f22486a1dba22171ec885dbc2149dc815119"
115+ , css =
116+ mkPackage
117+ [ "colors"
118+ , "console"
119+ , "effect"
120+ , "exceptions"
121+ , "nonempty"
122+ , "profunctor"
123+ , "psci-support"
124+ , "strings"
125+ , "these"
126+ , "transformers"
127+ ]
128+ "https://github.com/purescript-contrib/purescript-css.git"
129+ "5c1a44ee95c259352a2b4570b060de14130540bc"
89130 }
90131
91132in upstream // overrides // additions
spago.dhall+54−42
@@ -1,44 +1,56 @@
1−{ sources =
2− [ "src/**/*.purs", "test/**/*.purs" ]
3−, name =
4− "docs-search"
1+{ sources = [ "src/**/*.purs", "test/**/*.purs" ]
2+, name = "docs-search"
53, dependencies =
6− [ "aff-promise"
7− , "argonaut-codecs"
8− , "argonaut-core"
9− , "argonaut-generic"
10− , "arrays"
11− , "bower-json"
12− , "console"
13− , "control"
14− , "coroutines"
15− , "effect"
16− , "foldable-traversable"
17− , "generics-rep"
18− , "halogen"
19− , "halogen-css"
20− , "lists"
21− , "markdown-it"
22− , "markdown-it-halogen"
23− , "maybe"
24− , "newtype"
25− , "node-buffer"
26− , "node-fs"
27− , "node-fs-aff"
28− , "node-process"
29− , "node-readline"
30− , "optparse"
31− , "profunctor"
32− , "profunctor-lenses"
33− , "search-trie"
34− , "string-parsers"
35− , "strings"
36− , "test-unit"
37− , "web-dom"
38− , "web-html"
39− , "toppokki"
40− , "web-storage"
41− ]
42−, packages =
43− ./packages.dhall
4+ [ "aff"
5+ , "aff-promise"
6+ , "argonaut-codecs"
7+ , "argonaut-core"
8+ , "argonaut-generic"
9+ , "arrays"
10+ , "bower-json"
11+ , "console"
12+ , "control"
13+ , "css"
14+ , "effect"
15+ , "either"
16+ , "exceptions"
17+ , "foldable-traversable"
18+ , "foreign"
19+ , "foreign-object"
20+ , "halogen"
21+ , "halogen-css"
22+ , "halogen-subscriptions"
23+ , "identity"
24+ , "js-uri"
25+ , "lists"
26+ , "markdown-it"
27+ , "markdown-it-halogen"
28+ , "maybe"
29+ , "newtype"
30+ , "node-buffer"
31+ , "node-fs"
32+ , "node-fs-aff"
33+ , "node-process"
34+ , "node-readline"
35+ , "optparse"
36+ , "ordered-collections"
37+ , "partial"
38+ , "prelude"
39+ , "profunctor"
40+ , "profunctor-lenses"
41+ , "search-trie"
42+ , "string-parsers"
43+ , "strings"
44+ , "test-unit"
45+ , "toppokki"
46+ , "transformers"
47+ , "tuples"
48+ , "unfoldable"
49+ , "web-dom"
50+ , "web-events"
51+ , "web-html"
52+ , "web-storage"
53+ , "web-uievents"
54+ ]
55+, packages = ./packages.dhall
4456}
src/Docs/Search/App.purs+10−9
@@ -13,15 +13,16 @@ import Docs.Search.Meta as Meta
1313import Prelude
1414
1515import Control.Alt (alt)
16−import Control.Coroutine as Coroutine
1716import Data.Maybe (Maybe(..))
1817import Data.Newtype (wrap)
18+import Data.Map as Map
1919import Data.Tuple (Tuple(..))
2020import Data.Tuple.Nested ((/\))
2121import Effect (Effect)
2222import Effect.Aff (launchAff_)
2323import Halogen as H
2424import Halogen.Aff as HA
25+import Halogen.Subscription (subscribe)
2526import Halogen.VDom.Driver (runUI)
2627import MarkdownIt as MD
2728import Web.DOM.ChildNode as ChildNode
@@ -70,11 +71,10 @@ main = do
7071
7172 let initialSearchEngineState = { packageIndex
7273 , moduleIndex
73− , index: mempty
74− , typeIndex: mempty
74+ , index: wrap Map.empty
75+ , typeIndex: wrap Map.empty
7576 , scores
7677 }
77−
7878 resultsComponent =
7979 SearchResults.mkComponent
8080 initialSearchEngineState
@@ -85,12 +85,13 @@ main = do
8585 sfio <- runUI SearchField.component unit searchField
8686 srio <- runUI resultsComponent unit searchResults
8787
88− sfio.subscribe $
89− Coroutine.consumer (srio.query <<< H.tell <<< SearchResults.MessageFromSearchField)
88+ void $ H.liftEffect $ subscribe sfio.messages $ \sfm -> do
89+ launchAff_ do
90+ srio.query (SearchResults.MessageFromSearchField sfm unit)
9091
9192 -- We need to read the URI hash only when both components are initialized and
9293 -- the search field is subscribed to the main component.
93− void $ sfio.query $ H.tell SearchField.ReadURIHash
94+ void $ sfio.query $ SearchField.ReadURIHash unit
9495
9596 -- Subscribe to URI hash updates
9697 H.liftEffect do
@@ -98,7 +99,7 @@ main = do
9899 listener <-
99100 eventListener \event ->
100101 launchAff_ do
101− sfio.query $ H.tell SearchField.ReadURIHash
102+ sfio.query $ SearchField.ReadURIHash unit
102103
103104 addEventListener hashchange listener true (Window.toEventTarget window)
104105
@@ -112,7 +113,7 @@ main = do
112113 listener <-
113114 eventListener \event ->
114115 launchAff_ do
115− sbio.query $ H.tell Sidebar.UpdateModuleGrouping
116+ sbio.query $ Sidebar.UpdateModuleGrouping unit
116117
117118 addEventListener focus listener true (Window.toEventTarget window)
118119
src/Docs/Search/App/SearchField.purs+10−9
@@ -15,7 +15,7 @@ import Halogen.HTML as HH
1515import Halogen.HTML.CSS as HS
1616import Halogen.HTML.Events as HE
1717import Halogen.HTML.Properties as HP
18−import Halogen.Query.EventSource as ES
18+import Halogen.Query.Event as ES
1919import Web.DOM.Document as Document
2020import Web.DOM.ParentNode as ParentNode
2121import Web.HTML as HTML
@@ -36,6 +36,7 @@ data Action
3636 | FocusChanged Boolean
3737 | InitKeyboardListener
3838 | HandleKey H.SubscriptionId KeyboardEvent
39+ | NoOp
3940
4041data Query a
4142 = ReadURIHash a
@@ -46,7 +47,7 @@ data SearchFieldMessage
4647 | Focused
4748 | LostFocus
4849
49−component :: forall i. H.Component HH.HTML Query i SearchFieldMessage Aff
50+component :: forall i. H.Component Query i SearchFieldMessage Aff
5051component =
5152 H.mkComponent
5253 { initialState
@@ -73,12 +74,12 @@ initialState _ = { input: "", focused: false }
7374
7475handleAction :: Action -> H.HalogenM State Action () SearchFieldMessage Aff Unit
7576handleAction = case _ of
76−
77+ NoOp -> pure unit
7778 InitKeyboardListener -> do
7879
7980 document <- H.liftEffect $ Window.document =<< HTML.window
8081 H.subscribe' \sid ->
81− ES.eventListenerEventSource
82+ ES.eventListener
8283 KET.keyup
8384 (HTMLDocument.toEventTarget document)
8485 (map (HandleKey sid) <<< KE.fromEvent)
@@ -159,11 +160,11 @@ render state =
159160 , HP.type_ HP.InputText
160161 , HE.onKeyUp (\event ->
161162 case KeyboardEvent.code event of
162− "Enter" -> Just EnterPressed
163− _ -> Nothing)
164− , HE.onValueInput (Just <<< InputAction)
165− , HE.onFocusIn $ const $ Just $ FocusChanged true
166− , HE.onFocusOut $ const $ Just $ FocusChanged false
163+ "Enter" -> EnterPressed
164+ _ -> NoOp)
165+ , HE.onValueInput InputAction
166+ , HE.onFocusIn $ const $ FocusChanged true
167+ , HE.onFocusOut $ const $ FocusChanged false
167168 , HS.style do
168169
169170 let pursuitColor = rgb 0x1d 0x22 0x2d
src/Docs/Search/App/SearchResults.purs+10−20
@@ -12,13 +12,13 @@ import Docs.Search.Extra (homePageFromRepository, (>#>))
1212import Docs.Search.ModuleIndex (ModuleResult)
1313import Docs.Search.PackageIndex (PackageResult)
1414import Docs.Search.SearchResult (ResultInfo(..), SearchResult(..))
15−import Docs.Search.TypeDecoder (Constraint(..), FunDep(..), FunDeps(..), Kind(..), QualifiedName(..), Type(..), TypeArgument(..), joinForAlls, joinRows)
15+import Docs.Search.TypeDecoder (Constraint(..), FunDep(..), FunDeps(..), QualifiedName(..), Type(..), TypeArgument(..), joinForAlls, joinRows)
1616import Docs.Search.TypeIndex (TypeIndex)
1717import Docs.Search.Types (Identifier(..), ModuleName(..), PackageName)
1818import Docs.Search.Meta (Meta)
1919
2020import Prelude
21−
21+import Prim hiding (Type, Constraint)
2222import Data.Array ((!!))
2323import Data.Array as Array
2424import Data.List as List
@@ -76,7 +76,7 @@ mkComponent
7676 -> Element
7777 -> MD.MarkdownIt
7878 -> Meta
79− -> H.Component HH.HTML Query i o Aff
79+ -> H.Component Query i o Aff
8080mkComponent initialEngineState contents markdownIt { localPackageName } =
8181 H.mkComponent
8282 { initialState: const { engineState: initialEngineState
@@ -205,7 +205,7 @@ render state@{ mode: Active } =
205205 , HH.div [ HP.class_ (wrap "load_more"), HP.id_ "load-more" ]
206206 [ if Array.length shownResults < Array.length state.results
207207 then HH.a [ HP.id_ "load-more-link"
208− , HE.onClick $ const $ Just MoreResultsRequested ]
208+ , HE.onClick $ const MoreResultsRequested ]
209209 [ HH.text "Show more results" ]
210210 else HH.p_
211211 [ HH.text "No further results." ]
@@ -305,7 +305,7 @@ renderSearchResult state (SearchResult result) =
305305 [ HH.div [ HP.class_ (wrap "result") ]
306306 [ HH.h3 [ HP.class_ (wrap "result__title") ]
307307 [ HH.a [ HP.class_ (wrap "result__link")
308− , HE.onClick $ const $ Just $ SearchResultClicked result.moduleName
308+ , HE.onClick $ const $ SearchResultClicked result.moduleName
309309 , HP.href $
310310 unwrap result.moduleName <> ".html#" <>
311311 result.hashAnchor <> ":" <> unwrap result.name
@@ -386,7 +386,7 @@ renderValueSignature
386386 -> Array (HH.HTML a Action)
387387renderValueSignature result ty =
388388 [ HH.a [ makeHref ValueLevel false result.moduleName result.name
389− , HE.onClick $ const $ Just $ SearchResultClicked result.moduleName ]
389+ , HE.onClick $ const $ SearchResultClicked result.moduleName ]
390390 [ HH.text $ unwrap result.name ]
391391 , HH.text " :: "
392392 , renderType ty ]
@@ -417,7 +417,7 @@ renderTypeClassSignature { fundeps, arguments, superclasses } { name, moduleName
417417 ]
418418 , space
419419 , HH.a [ makeHref TypeLevel false moduleName name
420− , HE.onClick $ const $ Just $
420+ , HE.onClick $ const $
421421 SearchResultClicked moduleName
422422 ]
423423 [ HH.text $ unwrap name ]
@@ -510,7 +510,7 @@ renderTypeArgument (TypeArgument { name, mbKind }) =
510510 [ HH.text "("
511511 , HH.text $ name
512512 , HH.text " :: "
513− , renderKind kind
513+ , renderType kind
514514 , HH.text ")"
515515 ]
516516
@@ -592,7 +592,7 @@ renderForAll ty =
592592 HH.span_ [ HH.text $ " (" <> name <> " "
593593 , syntax "::"
594594 , space
595− , renderKind kind
595+ , renderType kind
596596 , HH.text ")" ]
597597 ) <>
598598
@@ -666,7 +666,7 @@ renderQualifiedName isInfix level (QualifiedName { moduleNameParts, name })
666666 = if isBuiltIn then
667667 HH.text $ unwrap name
668668 else
669− HH.a [ HE.onClick $ const $ Just $
669+ HH.a [ HE.onClick $ const $
670670 SearchResultClicked $ moduleName
671671 , makeHref level isInfix moduleName name
672672 ]
@@ -676,16 +676,6 @@ renderQualifiedName isInfix level (QualifiedName { moduleNameParts, name })
676676 isBuiltIn = moduleNameParts !! 0 == Just "Prim"
677677
678678
679−renderKind
680− :: forall a
681− . Kind
682− -> HH.HTML a Action
683−renderKind = case _ of
684− Row k1 -> HH.span_ [ HH.text "# ", renderKind k1 ]
685− FunKind k1 k2 -> HH.span_ [ renderKind k1, syntax " -> ", renderKind k2 ]
686− NamedKind qname -> renderQualifiedName false KindLevel qname
687−
688−
689679-- | Construct a `href` property value w.r.t. `DeclLevel`.
690680makeHref
691681 :: forall t rest
src/Docs/Search/App/Sidebar.purs+2−2
@@ -64,7 +64,7 @@ mkComponent
6464 . ModuleIndex
6565 -> IsIndexHTML
6666 -> Meta
67− -> Aff (H.Component HH.HTML Query i Action Aff)
67+ -> Aff (H.Component Query i Action Aff)
6868mkComponent moduleIndex@{ packageModules } isIndexHTML { localPackageName } = do
6969 groupingMode <- H.liftEffect loadGroupingModeFromLocalStorage
7070 mbModuleName <- H.liftEffect getCurrentModuleName
@@ -134,7 +134,7 @@ render state@{ groupingMode, moduleNames, localPackageName } =
134134 , HH.input [ HP.id_ "group-modules__input"
135135 , HP.type_ HP.InputCheckbox
136136 , HP.checked (groupingMode == GroupByPackage)
137− , HE.onChecked $ Just <<< ToggleGrouping <<< isCheckedToGroupingMode
137+ , HE.onChecked $ ToggleGrouping <<< isCheckedToGroupingMode
138138 ]
139139
140140 , HH.text " "
src/Docs/Search/BrowserEngine.purs−3
@@ -36,9 +36,6 @@ newtype PartialIndex
3636 = PartialIndex (Map PartId Index)
3737
3838derive instance newtypePartialIndex :: Newtype PartialIndex _
39−derive newtype instance semigroupPartialIndex :: Semigroup PartialIndex
40−derive newtype instance monoidPartialIndex :: Monoid PartialIndex
41−
4239
4340type BrowserEngineState = EngineState PartialIndex TypeIndex
4441
src/Docs/Search/Declarations.purs+3−3
@@ -3,11 +3,11 @@ module Docs.Search.Declarations where
33import Docs.Search.DocsJson (ChildDeclType(..), ChildDeclaration(..), DeclType(..), Declaration(..), DocsJson(..), SourceSpan)
44import Docs.Search.Score (Scores, getPackageScore, getPackageScoreForPackageName)
55import Docs.Search.SearchResult (ResultInfo(..), SearchResult(..))
6−import Docs.Search.TypeDecoder (Constraint(..), QualifiedName(..), Type(..), Kind, joinForAlls)
6+import Docs.Search.TypeDecoder (Constraint(..), QualifiedName(..), Type(..), joinForAlls)
77import Docs.Search.Types (ModuleName(..), PackageName(..), PackageInfo(..), Identifier(..))
88
99import Prelude
10−
10+import Prim hiding (Type)
1111import Control.Alt ((<|>))
1212import Data.Array ((!!))
1313import Data.Array as Array
@@ -271,7 +271,7 @@ mkChildInfo
271271 -- We concatenate two lists:
272272 -- * a list of type parameters of the type class, and
273273 -- * a list of quantified variables of the unconstrained type
274− allArguments :: Array { name :: String, mbKind :: Maybe Kind }
274+ allArguments :: Array { name :: String, mbKind :: Maybe Type }
275275 allArguments =
276276 (arguments <#> unwrap) <> List.toUnfoldable binders
277277
src/Docs/Search/DocsJson.purs+4−4
@@ -2,8 +2,8 @@
22module Docs.Search.DocsJson where
33
44import Prelude
5−
6−import Docs.Search.TypeDecoder (Constraint, FunDeps, Kind, Type, TypeArgument)
5+import Prim hiding (Type, Constraint)
6+import Docs.Search.TypeDecoder (Constraint, FunDeps, Type, TypeArgument)
77
88import Data.Argonaut.Core (fromString, stringify, toString)
99import Data.Argonaut.Decode (class DecodeJson, decodeJson, (.:), (.:?))
@@ -11,7 +11,7 @@ import Data.Argonaut.Decode.Error (JsonDecodeError(..))
1111import Data.Argonaut.Encode (class EncodeJson, encodeJson)
1212import Data.Either (Either(..))
1313import Data.Generic.Rep (class Generic)
14−import Data.Generic.Rep.Show (genericShow)
14+import Data.Show.Generic (genericShow)
1515import Data.Maybe (Maybe(..))
1616import Data.Newtype (class Newtype, unwrap)
1717
@@ -44,7 +44,7 @@ newtype Declaration
4444 , comments :: Maybe String
4545 , info :: { declType :: DeclType
4646 , dataDeclType :: Maybe DataDeclType
47− , kind :: Maybe Kind
47+ , kind :: Maybe Type
4848 , typeArguments :: Maybe (Array TypeArgument)
4949 , type :: Maybe Type
5050 , superclasses :: Maybe (Array Constraint)
src/Docs/Search/IndexBuilder.purs+1−1
@@ -249,7 +249,7 @@ writeMeta meta = do
249249-- | Get a mapping from index parts to index contents.
250250getIndex :: Declarations -> Map PartId (Array (Tuple String (Array SearchResult)))
251251getIndex (Declarations trie) =
252− Array.foldr insert mempty parts
252+ Array.foldr insert Map.empty parts
253253 where
254254 insert part = Map.insertWith append (getPartId part.prefix) part.results
255255
src/Docs/Search/Interactive.purs+5−5
@@ -13,13 +13,13 @@ import Docs.Search.PackageIndex (PackageResult, mkPackageIndex, mkPackageInfo)
1313import Docs.Search.Score (mkScores)
1414import Docs.Search.SearchResult (ResultInfo(..), SearchResult(..))
1515import Docs.Search.Terminal (bold, cyan, green, yellow)
16−import Docs.Search.TypeDecoder (Constraint, FunDeps, Kind, QualifiedName, Type, TypeArgument)
16+import Docs.Search.TypeDecoder (Constraint, FunDeps, QualifiedName, Type, TypeArgument)
1717import Docs.Search.TypeIndex (resultsWithTypes)
18−import Docs.Search.TypePrinter (keyword, showConstraint, showFunDeps, showKind, showType, showTypeArgument, space, syntax)
18+import Docs.Search.TypePrinter (keyword, showConstraint, showFunDeps, showType, showTypeArgument, space, syntax)
1919import Docs.Search.Types (ModuleName, PackageName, PackageInfo, Identifier)
2020
2121import Prelude
22−
22+import Prim hiding (Type, Constraint)
2323import Data.Array as Array
2424import Data.Identity (Identity(..))
2525import Data.List as List
@@ -279,7 +279,7 @@ showTypeSynonymSignature { type: ty, arguments } { name } =
279279
280280showExternDataSignature
281281 :: forall rest
282− . { kind :: Kind }
282+ . { kind :: Type }
283283 -> { name :: Identifier | rest }
284284 -> String
285285showExternDataSignature { kind } { name } =
@@ -288,7 +288,7 @@ showExternDataSignature { kind } { name } =
288288 yellow (unwrap name) <>
289289 space <>
290290 syntax " :: " <>
291− showKind kind
291+ showType kind
292292
293293
294294leftShift :: Int -> String -> String
src/Docs/Search/Main.purs+1−1
@@ -9,7 +9,7 @@ import Docs.Search.Config as Config
99import Docs.Search.Types (PackageName(..))
1010
1111import Data.Generic.Rep (class Generic)
12−import Data.Generic.Rep.Show (genericShow)
12+import Data.Show.Generic (genericShow)
1313import Data.List as List
1414import Data.List.NonEmpty as NonEmpty
1515import Data.Maybe (Maybe, fromMaybe, optional)
src/Docs/Search/ModuleIndex.purs+4−4
@@ -56,7 +56,7 @@ type ModuleResult
5656
5757unpackModuleIndex :: PackedModuleIndex -> ModuleIndex
5858unpackModuleIndex packageModules =
59− flip execState { packageModules, modulePackages: mempty, index: mempty } do
59+ flip execState { packageModules, modulePackages: Map.empty, index: mempty } do
6060 for_ (Map.toUnfoldableUnordered packageModules :: Array _)
6161 \(package /\ moduleNames) -> do
6262 for_ moduleNames \moduleName -> do
@@ -94,12 +94,12 @@ queryModuleIndex scores { index, modulePackages } query =
9494-- | Constructs a mapping from packages to modules
9595mkPackedModuleIndex :: Declarations -> PackedModuleIndex
9696mkPackedModuleIndex (Declarations trie) =
97− foldr (Map.unionWith Set.union) mempty $ extract <$> Trie.values trie
97+ foldr (Map.unionWith Set.union) Map.empty $ extract <$> Trie.values trie
9898 where
9999 extract
100100 :: List SearchResult
101101 -> Map PackageInfo (Set ModuleName)
102− extract = foldr (Map.unionWith Set.union) mempty <<< map mkEntry
102+ extract = foldr (Map.unionWith Set.union) Map.empty <<< map mkEntry
103103 where
104104 mkEntry (SearchResult { packageInfo, moduleName }) =
105105 Map.singleton packageInfo (Set.singleton moduleName)
@@ -107,7 +107,7 @@ mkPackedModuleIndex (Declarations trie) =
107107loadModuleIndex :: Aff PackedModuleIndex
108108loadModuleIndex = do
109109 json <- toAffE $ load Config.moduleIndexLoadPath
110− pure $ fromMaybe mempty $ hush $ decodeJson json
110+ pure $ fromMaybe Map.empty $ hush $ decodeJson json
111111
112112
113113foreign import load
src/Docs/Search/PackageIndex.purs+3−2
@@ -36,7 +36,7 @@ mkPackageInfo :: Scores -> Array PackageMeta -> PackageInfo
3636mkPackageInfo packageScores pms =
3737 Array.fromFoldable $
3838 Map.values $
39− Array.foldr insert mempty pms
39+ Array.foldr insert Map.empty pms
4040
4141 where
4242 insert
@@ -64,7 +64,8 @@ mkPackageInfo packageScores pms =
6464
6565mkScoresFromPackageIndex :: PackageIndex -> Scores
6666mkScoresFromPackageIndex =
67− Trie.values >>> Array.foldr (\ { name, score } -> Map.insert name score) mempty
67+ Trie.values >>> Array.fromFoldable >>>
68+ Array.foldr (\ { name, score } -> Map.insert name score) Map.empty
6869
6970
7071loadPackageIndex :: Aff PackageIndex
src/Docs/Search/Score.purs+1−1
@@ -29,7 +29,7 @@ mkScores =
2929 updateScoresFor (unwrap pm).dependencies >>>
3030 updateScoresFor (unwrap pm).devDependencies
3131 )
32− mempty
32+ Map.empty
3333
3434 where
3535 updateScoresFor :: Dependencies -> Scores -> Scores
src/Docs/Search/SearchResult.purs+5−5
@@ -1,15 +1,15 @@
11module Docs.Search.SearchResult where
22
33import Docs.Search.DocsJson (DataDeclType)
4−import Docs.Search.TypeDecoder (Constraint, FunDeps, Kind, QualifiedName, Type, TypeArgument)
4+import Docs.Search.TypeDecoder (Constraint, FunDeps, QualifiedName, Type, TypeArgument)
55import Docs.Search.Types (ModuleName, PackageInfo, Identifier, PackageScore)
66
77import Prelude
8−
8+import Prim hiding (Type, Constraint)
99import Data.Argonaut.Decode (class DecodeJson)
10−import Data.Argonaut.Decode.Generic.Rep (genericDecodeJson)
10+import Data.Argonaut.Decode.Generic (genericDecodeJson)
1111import Data.Argonaut.Encode (class EncodeJson)
12−import Data.Argonaut.Encode.Generic.Rep (genericEncodeJson)
12+import Data.Argonaut.Encode.Generic (genericEncodeJson)
1313import Data.Generic.Rep (class Generic)
1414import Data.Maybe (Maybe(..))
1515import Data.Newtype (class Newtype, un)
@@ -19,7 +19,7 @@ import Data.Newtype (class Newtype, un)
1919data ResultInfo
2020 = DataResult { typeArguments :: Array TypeArgument
2121 , dataDeclType :: DataDeclType }
22− | ExternDataResult { kind :: Kind }
22+ | ExternDataResult { kind :: Type }
2323 | TypeSynonymResult { arguments :: Array TypeArgument
2424 , type :: Type }
2525 | DataConstructorResult { arguments :: Array Type }
src/Docs/Search/TypeDecoder.purs+8−49
@@ -1,9 +1,10 @@
1+-- | A decoder for types located in 'Language.PureScript.Types'.
12module Docs.Search.TypeDecoder where
23
34import Docs.Search.Types (Identifier)
45
56import Prelude
6−
7+import Prim hiding (Type, Constraint)
78import Control.Alt ((<|>))
89import Data.Argonaut.Core (Json, caseJsonObject, fromArray, fromObject, jsonEmptyObject, stringify, toArray)
910import Data.Argonaut.Decode (class DecodeJson, decodeJson, (.:))
@@ -11,7 +12,7 @@ import Data.Argonaut.Encode (class EncodeJson, encodeJson)
1112import Data.Argonaut.Decode.Error (JsonDecodeError(..))
1213import Data.Either (Either(..))
1314import Data.Generic.Rep (class Generic)
14−import Data.Generic.Rep.Show (genericShow)
15+import Data.Show.Generic (genericShow)
1516import Data.List (List(..), (:))
1617import Data.List as List
1718import Data.Maybe (Maybe(..))
@@ -49,49 +50,6 @@ mkJsonError name json _ =
4950mkJsonError' :: String -> Json -> JsonDecodeError
5051mkJsonError' name json = mkJsonError name json unit
5152
52−-- | The data type of kinds
53−data Kind
54− -- | Kinds for labelled, unordered rows without duplicates
55− = Row Kind
56− -- | Function kinds
57− | FunKind Kind Kind
58− -- | A named kind
59− | NamedKind QualifiedName
60−
61−derive instance eqKind :: Eq Kind
62−derive instance genericKind :: Generic Kind _
63−
64−instance showKind :: Show Kind where
65− show x = genericShow x
66−
67−instance decodeJsonKind :: DecodeJson Kind where
68− decodeJson json = do
69− handle <- decodeJson json
70− tag <- handle .: "tag"
71− case tag of
72− "NamedKind" -> do
73− contents <- handle .: "contents"
74− pure $ NamedKind contents
75− "Row" -> do
76− contents <- handle .: "contents"
77− pure $ Row contents
78− "FunKind" -> do
79− contents <- handle .: "contents"
80− case contents of
81− [k1, k2] ->
82− Right $ FunKind k1 k2
83− _ -> Left $ mkJsonError' "FunKind" json
84− _ -> Left $ mkJsonError' "Kind" json
85−
86−instance encodeJsonKind :: EncodeJson Kind where
87− encodeJson = case _ of
88− Row k ->
89− tagged "Row" (encodeJson k)
90− FunKind k1 k2 ->
91− tagged "FunKind" (encodeTuple k1 k2)
92− NamedKind qname ->
93− tagged "NamedKind" (encodeJson qname)
94−
9553-- | A typeclass constraint
9654newtype Constraint = Constraint
9755 { constraintClass :: QualifiedName
@@ -141,7 +99,7 @@ data Type
14199 -- | A type application
142100 | TypeApp Type Type
143101 -- | Forall quantifier
144− | ForAll String (Maybe Kind) Type
102+ | ForAll String (Maybe Type) Type
145103 -- | A type withset of type class constraints
146104 | ConstrainedType Constraint Type
147105 {-
@@ -189,9 +147,10 @@ instance decodeJsonType :: DecodeJson Type where
189147 (Left $ err unit)
190148 json
191149 <|>
150+ -- Ignore SkolemScope
192151 decodeContents
193152 (decodeQuadriple
194− (\f (k :: Kind) a (_ :: Maybe Int) ->
153+ (\f (k :: Type) a (_ :: Maybe Int) ->
195154 ForAll f (Just k) a)
196155 err)
197156 (Left $ err unit)
@@ -270,7 +229,7 @@ instance encodeJsonFunDeps :: EncodeJson FunDeps where
270229newtype TypeArgument
271230 = TypeArgument
272231 { name :: String
273− , mbKind :: Maybe Kind
232+ , mbKind :: Maybe Type
274233 }
275234
276235derive newtype instance eqTypeArgument :: Eq TypeArgument
@@ -404,7 +363,7 @@ tagged tag contents =
404363joinForAlls
405364 :: Type
406365 -> { binders :: List { name :: String
407− , mbKind :: Maybe Kind }
366+ , mbKind :: Maybe Type }
408367 , ty :: Type
409368 }
410369joinForAlls ty = go Nil ty
src/Docs/Search/TypeIndex.purs+4−5
@@ -12,12 +12,13 @@ import Docs.Search.Types (ModuleName(..))
1212import Docs.Search.TypeShape (shapeOfType, shapeOfTypeQuery, stringifyShape)
1313
1414import Prelude
15−
15+import Prim hiding (Type)
1616import Control.Promise (Promise, toAffE)
1717import Data.Argonaut.Core (Json)
1818import Data.Argonaut.Decode (decodeJson)
1919import Data.Array as Array
2020import Data.Either (hush)
21+import Data.Foldable (fold, foldr)
2122import Data.Map (Map)
2223import Data.Map as Map
2324import Data.Maybe (Maybe(..), fromMaybe', isJust)
@@ -28,14 +29,12 @@ import Effect.Aff (Aff, try)
2829
2930newtype TypeIndex = TypeIndex (Map String (Maybe (Array SearchResult)))
3031
31−derive newtype instance semigroupTypeIndex :: Semigroup TypeIndex
32−derive newtype instance monoidTypeIndex :: Monoid TypeIndex
3332derive instance newtypeTypeIndex :: Newtype TypeIndex _
3433
3534
3635mkTypeIndex :: Scores -> Array DocsJson -> TypeIndex
3736mkTypeIndex scores docsJsons =
38− TypeIndex $ map Just $ Array.foldr insert mempty docsJsons
37+ TypeIndex $ map Just $ foldr insert Map.empty docsJsons
3938 where
4039 insert :: DocsJson -> Map String (Array SearchResult) -> Map String (Array SearchResult)
4140 insert docsJson mp =
@@ -78,7 +77,7 @@ lookup
7877 -> Aff { index :: TypeIndex, results :: Array SearchResult }
7978lookup key index@(TypeIndex map) =
8079 case Map.lookup key map of
81− Just results -> pure { index, results: Array.fold results }
80+ Just results -> pure { index, results: fold results }
8281 Nothing -> do
8382 eiJson <- try (toAffE (lookup_ key $ Config.mkShapeScriptPath key))
8483 pure $ fromMaybe'
src/Docs/Search/TypePrinter.purs+5−14
@@ -1,10 +1,10 @@
11module Docs.Search.TypePrinter where
22
33import Prelude
4−
4+import Prim hiding (Type, Constraint)
55import Docs.Search.Extra ((>#>))
66import Docs.Search.Terminal (cyan)
7−import Docs.Search.TypeDecoder (Constraint(..), FunDep(..), FunDeps(..), Kind(..), QualifiedName(..), Type(..), TypeArgument(..), joinForAlls, joinRows)
7+import Docs.Search.TypeDecoder (Constraint(..), FunDep(..), FunDeps(..), QualifiedName(..), Type(..), TypeArgument(..), joinForAlls, joinRows)
88import Docs.Search.Types (Identifier(..))
99
1010import Data.Array as Array
@@ -70,7 +70,7 @@ showTypeArgument (TypeArgument { name, mbKind }) =
7070 "(" <>
7171 name <>
7272 " :: " <>
73− showKind kind <>
73+ showType kind <>
7474 ")"
7575
7676
@@ -127,7 +127,7 @@ showForAll
127127showForAll ty =
128128 keyword "forall" <>
129129
130− ( Array.fold $ foralls.binders <#>
130+ ( Array.fold $ Array.fromFoldable $ foralls.binders <#>
131131 \ { name, mbKind } ->
132132 case mbKind of
133133 Nothing -> " " <> name
@@ -135,7 +135,7 @@ showForAll ty =
135135 " (" <> name <> " "
136136 <> syntax "::"
137137 <> space
138− <> showKind kind
138+ <> showType kind
139139 <> ")"
140140 ) <>
141141
@@ -146,15 +146,6 @@ showForAll ty =
146146 foralls = joinForAlls ty
147147
148148
149−showKind
150− :: Kind
151− -> String
152−showKind = case _ of
153− Row k1 -> "# " <> showKind k1
154− FunKind k1 k2 -> showKind k1 <> syntax " -> " <> showKind k2
155− NamedKind qname -> showQualifiedName qname
156−
157−
158149showConstraint
159150 :: Constraint
160151 -> String
src/Docs/Search/TypeQuery.purs+3−3
@@ -16,12 +16,12 @@ import Docs.Search.TypeDecoder (QualifiedName(..), Type(..), joinConstraints, jo
1616import Docs.Search.Types (Identifier(..))
1717
1818import Prelude
19−
19+import Prim hiding (Type)
2020import Control.Alt ((<|>))
2121import Data.Array as Array
2222import Data.Either (Either)
2323import Data.Generic.Rep (class Generic)
24−import Data.Generic.Rep.Show (genericShow)
24+import Data.Show.Generic (genericShow)
2525import Data.List (List(..), many, some, (:))
2626import Data.List as List
2727import Data.List.NonEmpty (NonEmptyList)
@@ -331,7 +331,7 @@ typeVarPenalty substs =
331331 Substitute v1 v2 ->
332332 f v1 v2
333333 _ -> identity
334− ) mempty substs
334+ ) Map.empty substs
335335
336336
337337-- | Penalty for name mismatches.
src/Docs/Search/TypeShape.purs+2−2
@@ -8,9 +8,9 @@ import Docs.Search.TypeQuery (TypeQuery(..), getFreeVariables)
88import Docs.Search.Types (Identifier(..))
99
1010import Prelude
11−
11+import Prim hiding (Type)
1212import Data.Generic.Rep (class Generic)
13−import Data.Generic.Rep.Show (genericShow)
13+import Data.Show.Generic (genericShow)
1414import Data.List (List(..), (:))
1515import Data.List as List
1616import Data.List.NonEmpty as NonEmptyList
src/Docs/Search/Types.purs+3−3
@@ -3,11 +3,11 @@ module Docs.Search.Types where
33import Prelude
44
55import Data.Argonaut.Decode (class DecodeJson)
6−import Data.Argonaut.Decode.Generic.Rep (genericDecodeJson)
6+import Data.Argonaut.Decode.Generic (genericDecodeJson)
77import Data.Argonaut.Encode (class EncodeJson)
8−import Data.Argonaut.Encode.Generic.Rep (genericEncodeJson)
8+import Data.Argonaut.Encode.Generic (genericEncodeJson)
99import Data.Generic.Rep (class Generic)
10−import Data.Generic.Rep.Show (genericShow)
10+import Data.Show.Generic (genericShow)
1111import Data.Newtype (class Newtype)
1212
1313
src/Docs/Search/URIHash.purs+1−1
@@ -10,7 +10,7 @@ import Prelude
1010import Data.Maybe (Maybe(Just), fromMaybe)
1111import Data.String.CodeUnits as String
1212import Effect (Effect)
13−import Global (decodeURIComponent, encodeURIComponent)
13+import JSURI (decodeURIComponent, encodeURIComponent)
1414import Web.HTML as HTML
1515import Web.HTML.Location as Location
1616import Web.HTML.Window as Window
test/Main.purs+28−279
@@ -2,23 +2,21 @@ module Test.Main where
22
33import Prelude
44
5−import Docs.Search.TypeDecoder (Constraint(..), FunDep(..), FunDeps(..), Kind(..), QualifiedName(..), Type(..))
6−import Docs.Search.Types (Identifier(..))
7−import Test.TypeQuery as TypeQuery
8−import Test.IndexBuilder as IndexBuilder
9−import Test.Declarations as Declarations
10−import Test.ModuleIndex as ModuleIndex
11−import Test.UI as UI
12−
13−import Test.Extra (assertRight)
14−
5+import Data.Argonaut.Core (Json)
156import Data.Argonaut.Decode (decodeJson)
16−import Data.Argonaut.Encode (encodeJson)
177import Data.Argonaut.Parser (jsonParser)
18−import Data.Either (fromRight)
8+import Data.Either (Either(..))
199import Data.Maybe (Maybe(..))
10+import Docs.Search.TypeDecoder (Constraint(..), FunDep(..), FunDeps(..), QualifiedName(..), Type(..))
11+import Docs.Search.Types (Identifier(..))
2012import Effect (Effect)
2113import Partial.Unsafe (unsafePartial)
14+import Test.Declarations as Declarations
15+import Test.Extra (assertRight)
16+import Test.IndexBuilder as IndexBuilder
17+import Test.ModuleIndex as ModuleIndex
18+import Test.TypeQuery as TypeQuery
19+import Test.UI as UI
2220import Test.Unit (TestSuite, suite, test)
2321import Test.Unit.Main (runTest)
2422
@@ -27,131 +25,39 @@ main = do
2725 runTest mainTest
2826 UI.main
2927
28+mkJson :: String -> Json
29+mkJson str =
30+ unsafePartial $ case jsonParser str of
31+ Right r -> r
32+
3033mainTest :: TestSuite
3134mainTest = do
3235 TypeQuery.tests
3336 IndexBuilder.tests
3437 Declarations.tests
3538 ModuleIndex.tests
36−
37− let mkJson x = unsafePartial $ fromRight $ jsonParser x
3839 suite "FunDeps decoder" do
3940 test "FunDeps" do
40− let funDeps = mkJson """
41− [
41+ let
42+ funDeps = mkJson """
4243 [
43− [
44− "lhs",
45− "rhs"
46− ],
47− [
48− "output"
49− ]
50− ]
51− ]
52− """
44+ [
45+ [
46+ "lhs",
47+ "rhs"
48+ ],
49+ [
50+ "output"
51+ ]
52+ ]
53+ ]
54+ """
5355 assertRight (decodeJson funDeps)
5456 (FunDeps [ FunDep { lhs: [ "lhs", "rhs" ]
5557 , rhs: [ "output"]
5658 }
5759 ])
5860
59− suite "Kind decoder" do
60−
61− test "QualifiedName" do
62−
63− let qualifiedName = mkJson """
64− [
65− [
66− "Prim"
67− ],
68− "Type"
69− ]
70− """
71−
72− assertRight (decodeJson qualifiedName)
73− (qualified ["Prim"] "Type")
74−
75− test "NamedKind" do
76− let namedKind = mkJson """
77− {
78− "annotation": [],
79− "tag": "NamedKind",
80− "contents": [
81− [
82− "Prim"
83− ],
84− "Type"
85− ]
86− }
87− """
88−
89− assertRight (decodeJson namedKind)
90− (NamedKind $ qualified ["Prim"] "Type")
91−
92− test "Row" do
93− let row = mkJson """
94− {
95− "annotation": [],
96− "tag": "Row",
97− "contents": {
98− "annotation": [],
99− "tag": "NamedKind",
100− "contents": [
101− [
102− "Prim"
103− ],
104− "Type"
105− ]
106− }
107− }
108− """
109−
110− assertRight (decodeJson row) (Row $ NamedKind $ qualified ["Prim"] "Type")
111−
112− test "FunKind" do
113− let funKind = mkJson """
114− {
115− "annotation": [],
116− "tag": "FunKind",
117− "contents": [
118− {
119− "annotation": [],
120− "tag": "Row",
121− "contents": {
122− "annotation": [],
123− "tag": "NamedKind",
124− "contents": [
125− [
126− "Prim"
127− ],
128− "Type"
129− ]
130− }
131− },
132− {
133− "annotation": [],
134− "tag": "Row",
135− "contents": {
136− "annotation": [],
137− "tag": "NamedKind",
138− "contents": [
139− [
140− "Prim"
141− ],
142− "Type"
143− ]
144− }
145− }
146− ]
147− }
148− """
149− assertRight (decodeJson funKind)
150− (FunKind (Row $ NamedKind $ qualified ["Prim"] "Type")
151− (Row $ NamedKind $ qualified ["Prim"] "Type")
152− )
153−
154−
15561 suite "Constraint decoder" do
15662 test "Constraint" do
15763 let constraint = mkJson """
@@ -372,155 +278,6 @@ mainTest = do
372278 (TypeConstructor $ qualified ["Prim"] "String"))
373279 (TypeVar "a"))
374280
375− test "ForAll #2" do
376− let forallJson = mkJson """
377−{
378− "annotation": [],
379− "tag": "ForAll",
380− "contents": [
381− "f",
382− {
383− "annotation": [],
384− "tag": "FunKind",
385− "contents": [
386− {
387− "annotation": [],
388− "tag": "NamedKind",
389− "contents": [
390− [
391− "Prim",
392− "RowList"
393− ],
394− "RowList"
395− ]
396− },
397− {
398− "annotation": [],
399− "tag": "NamedKind",
400− "contents": [
401− [
402− "Prim"
403− ],
404− "Type"
405− ]
406− }
407− ]
408− },
409− {
410− "annotation": [],
411− "tag": "TypeApp",
412− "contents": [
413− {
414− "annotation": [],
415− "tag": "TypeApp",
416− "contents": [
417− {
418− "annotation": [],
419− "tag": "TypeConstructor",
420− "contents": [
421− [
422− "Prim"
423− ],
424− "Function"
425− ]
426− },
427− {
428− "annotation": [],
429− "tag": "TypeApp",
430− "contents": [
431− {
432− "annotation": [],
433− "tag": "TypeVar",
434− "contents": "f"
435− },
436− {
437− "annotation": [],
438− "tag": "TypeVar",
439− "contents": "l"
440− }
441− ]
442− }
443− ]
444− },
445− {
446− "annotation": [],
447− "tag": "TypeApp",
448− "contents": [
449− {
450− "annotation": [],
451− "tag": "TypeConstructor",
452− "contents": [
453− [
454− "Data",
455− "List",
456− "Types"
457− ],
458− "List"
459− ]
460− },
461− {
462− "annotation": [],
463− "tag": "ParensInType",
464− "contents": {
465− "annotation": [],
466− "tag": "TypeApp",
467− "contents": [
468− {
469− "annotation": [],
470− "tag": "TypeApp",
471− "contents": [
472− {
473− "annotation": [],
474− "tag": "TypeConstructor",
475− "contents": [
476− [
477− "Data",
478− "Tuple"
479− ],
480− "Tuple"
481− ]
482− },
483− {
484− "annotation": [],
485− "tag": "TypeConstructor",
486− "contents": [
487− [
488− "Prim"
489− ],
490− "String"
491− ]
492− }
493− ]
494− },
495− {
496− "annotation": [],
497− "tag": "TypeConstructor",
498− "contents": [
499− [
500− "Prim"
501− ],
502− "String"
503− ]
504− }
505− ]
506− }
507− }
508− ]
509− }
510− ]
511− },
512− null
513− ]
514−}
515− """
516− assertRight (decodeJson forallJson) $
517− ForAll "f"
518− (Just (FunKind (NamedKind (QualifiedName { moduleNameParts: ["Prim","RowList"], name: Identifier "RowList" })) (NamedKind (QualifiedName { moduleNameParts: ["Prim"], name: Identifier "Type" }))))
519− (TypeApp (TypeApp (TypeConstructor (QualifiedName { moduleNameParts: ["Prim"], name: Identifier "Function" })) (TypeApp (TypeVar "f") (TypeVar "l"))) (TypeApp (TypeConstructor (QualifiedName { moduleNameParts: ["Data","List","Types"], name: Identifier "List" })) (ParensInType (TypeApp (TypeApp (TypeConstructor (QualifiedName { moduleNameParts: ["Data","Tuple"], name: Identifier "Tuple" })) (TypeConstructor (QualifiedName { moduleNameParts: ["Prim"], name: Identifier "String" }))) (TypeConstructor (QualifiedName { moduleNameParts: ["Prim"], name: Identifier "String" }))))))
520−
521−
522−
523−
524281 suite "jsons" do
525282
526283 test "jsons #1" do
@@ -530,14 +287,6 @@ mainTest = do
530287
531288 assertRight (decodeJson json) $ (ForAll "o" Nothing (ForAll "r" Nothing (ForAll "l" Nothing (ConstrainedType (Constraint { constraintArgs: [(TypeVar "l"),(TypeVar "r"),(TypeVar "o")], constraintClass: (QualifiedName { moduleNameParts: ["Type","Data","Boolean"], name: Identifier "And" }) }) (TypeApp (TypeApp (TypeConstructor (QualifiedName { moduleNameParts: ["Prim"], name: Identifier "Function" })) (TypeApp (TypeConstructor (QualifiedName { moduleNameParts: ["Type","Data","Boolean"], name: Identifier "BProxy" })) (TypeVar "l"))) (TypeApp (TypeApp (TypeConstructor (QualifiedName { moduleNameParts: ["Prim"], name: Identifier "Function" })) (TypeApp (TypeConstructor (QualifiedName { moduleNameParts: ["Type","Data","Boolean"], name: Identifier "BProxy" })) (TypeVar "r"))) (TypeApp (TypeConstructor (QualifiedName { moduleNameParts: ["Type","Data","Boolean"], name: Identifier "BProxy" })) (TypeVar "o"))))))))
532289
533− suite "Kind encoder" do
534− test "FunKind" do
535− let k1 =
536− FunKind (Row (NamedKind $ qualified [] "a"))
537− (FunKind (NamedKind $ qualified [] "b")
538− (NamedKind $ qualified [] "b"))
539− assertRight (decodeJson $ encodeJson $ k1) k1
540−
541290
542291qualified :: Array String -> String -> QualifiedName
543292qualified moduleNameParts name = QualifiedName { moduleNameParts, name: Identifier name }
test/Test/TypeQuery.purs+1−1
@@ -6,7 +6,7 @@ import Docs.Search.TypeShape (ShapeChunk(..), shapeOfType, shapeOfTypeQuery)
66import Docs.Search.Types (Identifier(..))
77
88import Prelude
9−
9+import Prim hiding (Constraint, Type)
1010import Data.Foldable (class Foldable)
1111import Data.List (List(..), (:))
1212import Data.List as List