Skip to content

Commit

Permalink
Docs: get package names from purs graph (#1309)
Browse files Browse the repository at this point in the history
  • Loading branch information
f-f authored Jan 20, 2025
1 parent c723832 commit ad5a1e3
Show file tree
Hide file tree
Showing 30 changed files with 417 additions and 476 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
/.spago
/bin/bundle.js
/bin/docs-search-app.js
/bin/docs-search-app.js.map
.direnv
.envrc
.spec-results
Expand Down
7 changes: 0 additions & 7 deletions bin/docs-search-app.js.map

This file was deleted.

4 changes: 0 additions & 4 deletions bin/spago.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@ package:
- foldable-traversable
- lists
- maybe
- node-path
- node-process
- now
- optparse
- ordered-collections
Expand All @@ -26,9 +24,7 @@ package:
- registry-lib
- spago
- spago-core
- strings
- transformers
- unsafe-coerce
bundle:
module: Main
outfile: bundle.js
Expand Down
22 changes: 22 additions & 0 deletions core/src/Purs/Types.purs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
module Spago.Purs.Types where

import Spago.Core.Prelude

type ModuleGraphWithPackage = Map ModuleName ModuleGraphWithPackageNode

type ModuleGraphWithPackageNode =
{ path :: String
, depends :: Array ModuleName
, package :: PackageName
}

type ModuleName = String

newtype ModuleGraph = ModuleGraph (Map ModuleName ModuleGraphNode)

derive instance Newtype ModuleGraph _

type ModuleGraphNode =
{ path :: String
, depends :: Array ModuleName
}
1 change: 1 addition & 0 deletions docs-search/client-halogen/spago.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ package:
- ordered-collections
- prelude
- profunctor-lenses
- registry-lib
- search-trie
- strings
- tuples
Expand Down
24 changes: 10 additions & 14 deletions docs-search/client-halogen/src/Docs/Search/App.purs
Original file line number Diff line number Diff line change
@@ -1,23 +1,21 @@
-- | This is the main module of the client-side Halogen app.
module Docs.Search.App where

import Docs.Search.App.SearchField as SearchField
import Docs.Search.App.SearchResults as SearchResults
import Docs.Search.App.Sidebar as Sidebar
import Docs.Search.Config as Config
import Docs.Search.Extra (whenJust)
import Docs.Search.ModuleIndex as ModuleIndex
import Docs.Search.PackageIndex as PackageIndex
import Docs.Search.Meta as Meta

import Prelude

import Control.Alt (alt)
import Data.Map as Map
import Data.Maybe (Maybe(..))
import Data.Newtype (wrap)
import Data.Map as Map
import Data.Tuple (Tuple(..))
import Data.Tuple.Nested ((/\))
import Docs.Search.App.SearchField as SearchField
import Docs.Search.App.SearchResults as SearchResults
import Docs.Search.App.Sidebar as Sidebar
import Docs.Search.Config as Config
import Docs.Search.Extra (whenJust)
import Docs.Search.ModuleIndex as ModuleIndex
import Docs.Search.PackageIndex as PackageIndex
import Effect (Effect)
import Effect.Aff (launchAff_)
import Halogen as H
Expand All @@ -26,8 +24,8 @@ import Halogen.Subscription (subscribe)
import Halogen.VDom.Driver (runUI)
import MarkdownIt as MD
import Web.DOM.ChildNode as ChildNode
import Web.DOM.Document as Document
import Web.DOM.Document (Document)
import Web.DOM.Document as Document
import Web.DOM.Element as Element
import Web.DOM.Node as Node
import Web.DOM.ParentNode as ParentNode
Expand Down Expand Up @@ -66,7 +64,6 @@ main = do
HA.runHalogenAff do
packageIndex <- PackageIndex.loadPackageIndex
moduleIndex <- ModuleIndex.unpackModuleIndex <$> ModuleIndex.loadModuleIndex
meta <- Meta.load
let scores = PackageIndex.mkScoresFromPackageIndex packageIndex

let
Expand All @@ -82,7 +79,6 @@ main = do
initialSearchEngineState
pageContents
markdownIt
meta

sfio <- runUI SearchField.component unit searchField
srio <- runUI resultsComponent unit searchResults
Expand All @@ -106,7 +102,7 @@ main = do
addEventListener hashchange listener true (Window.toEventTarget window)

sbio <- do
component <- Sidebar.mkComponent moduleIndex isIndexHTML meta
component <- Sidebar.mkComponent moduleIndex isIndexHTML
runUI component unit sidebarContainer

-- Subscribe to window focus events
Expand Down
49 changes: 28 additions & 21 deletions docs-search/client-halogen/src/Docs/Search/App/SearchResults.purs
Original file line number Diff line number Diff line change
@@ -1,32 +1,31 @@
-- | This module contains a Halogen component for search results.
module Docs.Search.App.SearchResults where

import Prelude

import Data.Array as Array
import Data.List as List
import Data.Maybe (Maybe(..), isJust, fromMaybe)
import Data.Newtype (wrap, unwrap)
import Data.String.CodeUnits (stripPrefix, stripSuffix) as String
import Data.String.Common (null, trim) as String
import Data.String.Pattern (Pattern(..)) as String
import Data.Tuple (Tuple(..))
import Docs.Search.App.SearchField (SearchFieldMessage(..))
import Docs.Search.BrowserEngine (PartialIndex, browserSearchEngine)
import Docs.Search.Config as Config
import Docs.Search.Declarations (DeclLevel(..), declLevelToHashAnchor)
import Docs.Search.DocTypes (DataDeclType(..))
import Docs.Search.Engine (Result(..), packageInfoToString)
import Docs.Search.Engine as Engine
import Docs.Search.Extra (homePageFromRepository, (>#>))
import Docs.Search.Extra ((>#>))
import Docs.Search.ModuleIndex (ModuleResult)
import Docs.Search.PackageIndex (PackageResult)
import Docs.Search.SearchResult (ResultInfo(..), SearchResult(..))
import Docs.Search.TypeDecoder (Constraint(..), Constraint', Type', Qualified(..), QualifiedBy(..), ProperName(..), Type(..), TypeArgument, ClassName, FunDeps)
import Docs.Search.TypeQuery as TypeQuery
import Docs.Search.TypeIndex (TypeIndex)
import Docs.Search.Types (Identifier, ModuleName(..), PackageName)
import Docs.Search.Meta (Meta)

import Prelude
import Data.Array as Array
import Data.List as List
import Data.Maybe (Maybe(..), isJust, fromMaybe)
import Data.Newtype (wrap, unwrap)
import Data.String.CodeUnits (stripSuffix) as String
import Data.String.Common (null, trim) as String
import Data.String.Pattern (Pattern(..)) as String
import Data.Tuple (Tuple(..))
import Docs.Search.TypeQuery as TypeQuery
import Docs.Search.Types (Identifier, ModuleName(..))
import Effect.Aff (Aff)
import Halogen as H
import Halogen.HTML as HH
Expand All @@ -35,6 +34,8 @@ import Halogen.HTML.Properties as HP
import Language.PureScript.PSString as PSString
import MarkdownIt as MD
import MarkdownIt.Renderer.Halogen as MDH
import Registry.Location (Location(..))
import Registry.PackageName as PackageName
import Web.DOM.Element (Element)
import Web.DOM.Element as Element
import Web.HTML as HTML
Expand All @@ -56,7 +57,6 @@ type State =
, resultsCount :: Int
, mode :: Mode
, markdownIt :: MD.MarkdownIt
, localPackageName :: PackageName
}

data Query a = MessageFromSearchField SearchFieldMessage a
Expand All @@ -70,9 +70,8 @@ mkComponent
. EngineState
-> Element
-> MD.MarkdownIt
-> Meta
-> H.Component Query i o Aff
mkComponent initialEngineState contents markdownIt { localPackageName } =
mkComponent initialEngineState contents markdownIt =
H.mkComponent
{ initialState: const
{ engineState: initialEngineState
Expand All @@ -82,7 +81,6 @@ mkComponent initialEngineState contents markdownIt { localPackageName } =
, resultsCount: Config.resultsCount
, mode: Off
, markdownIt
, localPackageName
}
, render
, eval: H.mkEval $ H.defaultEval
Expand Down Expand Up @@ -257,16 +255,25 @@ renderPackageResult { name, description, repository } =

, HH.a
[ HP.class_ (wrap "result__link")
, HP.href $ fromMaybe "" repository # homePageFromRepository
, HP.href $ renderLocation repository
]
[ HH.text $ unwrap name ]
[ HH.text $ PackageName.print name ]
]
]
] <>
description >#> \descriptionText ->
[ HH.div [ HP.class_ (wrap "result__body") ]
[ HH.text descriptionText ]
]
where
-- TODO subdir
renderLocation :: Location -> String
renderLocation = case _ of
GitHub { owner, repo } -> "https://github.com/" <> owner <> "/" <> repo
Git { url } ->
fromMaybe url $ String.stripSuffix (wrap ".git")
$ fromMaybe url
$ String.stripPrefix (wrap "git:") url <#> ("https:" <> _)

renderModuleResult
:: forall a
Expand Down Expand Up @@ -331,7 +338,7 @@ renderSearchResult state (SearchResult result) =
, HP.title "Package"
]
[ HH.text "P" ]
, HH.text $ packageInfoToString state.localPackageName result.packageInfo
, HH.text $ packageInfoToString result.packageInfo
]

, HH.span [ HP.class_ (wrap "result__actions__item") ]
Expand Down
32 changes: 14 additions & 18 deletions docs-search/client-halogen/src/Docs/Search/App/Sidebar.purs
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
module Docs.Search.App.Sidebar where

import Docs.Search.Config as Config
import Docs.Search.Meta (Meta)
import Docs.Search.ModuleIndex (ModuleIndex)
import Docs.Search.Types (ModuleName(..), PackageInfo(..), PackageName)

import Prelude

import Data.Array as Array
Expand All @@ -17,23 +12,27 @@ import Data.Maybe (Maybe(..), isJust, fromMaybe)
import Data.Newtype (wrap, unwrap)
import Data.Set (Set)
import Data.Set as Set
import Data.Traversable (traverse)
import Data.Tuple.Nested (type (/\), (/\))
import Docs.Search.Config as Config
import Docs.Search.ModuleIndex (ModuleIndex)
import Docs.Search.Types (ModuleName(..), PackageInfo(..))
import Effect (Effect)
import Effect.Aff (Aff)
import Halogen as H
import Halogen.HTML as HH
import Halogen.HTML.Events as HE
import Halogen.HTML.Properties as HP
import Registry.PackageName as PackageName
import Type.Proxy (Proxy(..))
import Web.HTML as HTML
import Web.HTML.Window as Window
import Web.Storage.Storage as Storage
import Web.DOM.Document as Document
import Web.DOM.Element as Element
import Web.HTML.HTMLDocument as HTMLDocument
import Web.DOM.ParentNode as ParentNode
import Data.Traversable (traverse)
import Web.DOM.Node as Node
import Web.DOM.ParentNode as ParentNode
import Web.HTML as HTML
import Web.HTML.HTMLDocument as HTMLDocument
import Web.HTML.Window as Window
import Web.Storage.Storage as Storage

data Action = ToggleGrouping GroupingMode

Expand All @@ -54,17 +53,15 @@ type State =
, groupingMode :: GroupingMode
, moduleNames :: Array ModuleName
, isIndexHTML :: IsIndexHTML
, localPackageName :: PackageName
, currentPackage :: PackageInfo
}

mkComponent
:: forall i
. ModuleIndex
-> IsIndexHTML
-> Meta
-> Aff (H.Component Query i Action Aff)
mkComponent moduleIndex@{ packageModules } isIndexHTML { localPackageName } = do
mkComponent moduleIndex@{ packageModules } isIndexHTML = do
groupingMode <- H.liftEffect loadGroupingModeFromLocalStorage
mbModuleName <- H.liftEffect getCurrentModuleName
let currentPackage = getCurrentPackage moduleIndex mbModuleName
Expand All @@ -75,7 +72,6 @@ mkComponent moduleIndex@{ packageModules } isIndexHTML { localPackageName } = do
, groupingMode
, moduleNames
, isIndexHTML
, localPackageName
, currentPackage
}
, render
Expand Down Expand Up @@ -118,7 +114,7 @@ render
:: forall m
. State
-> H.ComponentHTML Action () m
render state@{ groupingMode, moduleNames, localPackageName } =
render state@{ groupingMode, moduleNames } =
HH.div
[ HP.classes
[ wrap "col"
Expand Down Expand Up @@ -156,8 +152,8 @@ render state@{ groupingMode, moduleNames, localPackageName } =
[ HH.summary_
[ HH.text $
case package of
Package packageName -> unwrap packageName
LocalPackage -> unwrap localPackageName
Package packageName -> PackageName.print packageName
LocalPackage packageName -> PackageName.print packageName
Builtin -> "<builtins>"
UnknownPackage -> "<unknown>"
]
Expand Down
2 changes: 2 additions & 0 deletions docs-search/common/spago.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,10 @@ package:
- prelude
- profunctor
- profunctor-lenses
- registry-lib
- safe-coerce
- search-trie
- spago-core
- string-parsers
- strings
- transformers
Expand Down
13 changes: 4 additions & 9 deletions docs-search/common/src/Docs/Search/Config.purs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ import Prelude
import Data.Char as Char
import Data.List (List, (:))
import Data.Newtype (wrap)
import Docs.Search.Types (GlobalIdentifier, PackageName, PartId(..), URL, FilePath)
import Docs.Search.Types (GlobalIdentifier, PartId(..), URL, FilePath)

-- TODO use the spago-generated one
version :: String
version = "0.0.12"

Expand Down Expand Up @@ -90,14 +91,8 @@ getPartId (a : _) =
PartId $ Char.toCharCode a `mod` numberOfIndexParts
getPartId _ = PartId 0

defaultPackageName :: PackageName
defaultPackageName = wrap "<local package>"

defaultDocsFiles :: Array String
defaultDocsFiles = [ "output/**/docs.json" ]

defaultBowerFiles :: Array String
defaultBowerFiles = [ ".spago/*/*/bower.json", "bower_components/purescript-*/bower.json" ]

defaultSourceFiles :: Array String
defaultSourceFiles = [ "src/**/*.purs" ]
defaultPursFiles :: Array String
defaultPursFiles = [ ".spago/*/*/purs.json" ]
Loading

0 comments on commit ad5a1e3

Please sign in to comment.