1module Docs.Centralize (centralize) where
3import Control.Arrow (second)
4import qualified Data.Map as Map
5import qualified Data.Maybe as Maybe
8import qualified AST.Declaration as Decl
9import qualified AST.Expression.Canonical as Canonical
10import qualified AST.Helpers as Help
11import qualified AST.Pattern as Pattern
12import qualified AST.Type as Type
13import qualified Docs.AST as Docs
14import qualified Elm.Compiler.Type.Extract as Extract
15import qualified Reporting.Annotation as A
16import qualified Reporting.Region as R
23centralize :: Decl.Canonical -> Text -> Docs.Centralized
24centralize (Decl.Decls defs unions aliases infixes) overview =
27 Map.fromList (map toInfixPair infixes)
31 (Map.fromList (map unionToEntry unions))
32 (Map.fromList (map aliasToEntry aliases))
33 (Map.fromList (Maybe.mapMaybe (defToEntry infixDict) defs))
44makeEntry :: Text -> (R.Region, Maybe Text) -> details -> Entry details
45makeEntry name (region, maybeComment) details =
46 ( name, A.A region (Docs.Entry maybeComment details) )
53unionToEntry :: A.Commented (Decl.Union Type.Canonical) -> Entry Docs.Union
54unionToEntry (A.A ann (Decl.Type name args ctors)) =
55 makeEntry name ann $ Docs.Union args $
56 map (second (map Extract.extract)) ctors
63aliasToEntry :: A.Commented (Decl.Alias Type.Canonical) -> Entry Docs.Alias
64aliasToEntry (A.A ann (Decl.Type name args tipe)) =
65 makeEntry name ann $ Docs.Alias args $ Extract.extract tipe
72defToEntry :: Map.Map Text (Decl.Assoc, Int) -> A.Commented Canonical.Def -> Maybe (Entry Docs.RawValue)
73defToEntry infixDict (A.A (_, maybeComment) definition) =
75 (Canonical.Def _ (A.A region pattern) _ maybeType) =
79 fmap (Extract.extract . A.drop) maybeType
83 Just $ makeEntry name (region, maybeComment) $
84 case Map.lookup name infixDict of
86 Docs.Infix tipe assoc prec
89 if Help.isOp name then
90 Docs.Infix tipe Decl.defaultAssociativity Decl.defaultPrecedence
98toInfixPair :: Decl.Infix -> ( Text, (Decl.Assoc, Int) )
99toInfixPair (Decl.Infix name assoc precedence) =
100 ( name, (assoc, precedence) )
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list