1module Docs.Check (Result, check) where
3import qualified Data.List as List
4import qualified Data.Map as Map
5import qualified Data.Set as Set
6import qualified Data.Traversable as T
7import Text.Parsec ((<|>), choice, many, setPosition, string)
8import Text.Parsec.Pos (newPos)
10import qualified AST.Variable as Var
11import qualified Docs.AST as Docs
12import qualified Elm.Compiler.Type as Type
13import Elm.Utils ((|>))
14import Parse.Binop (infixOp)
16 ( addLocation, anyUntil, commaSep1, parens, parse, simpleNewline
19import qualified Reporting.Annotation as A
20import qualified Reporting.Error.Docs as Error
21import qualified Reporting.Error.Helpers as Error (nearbyNames)
22import qualified Reporting.Region as R
23import qualified Reporting.Result as R
28 R.Result () w Error.Error a
33check :: [Var.Value] -> A.Located (Maybe Docs.Centralized) -> Result w Docs.Checked
34check exports (A.A region maybeDocs) =
37 R.throw region Error.NoDocs
40 checkHelp region exports docs
43checkHelp :: R.Region -> [Var.Value] -> Docs.Centralized -> Result w Docs.Checked
44checkHelp region exports (Docs.Docs comment aliases types values) =
47 commentedNames region comment
50 Set.fromList (map A.drop docNames)
52 checkCategory checkValue dict =
54 |> Map.filterWithKey (\key _ -> Set.member key docSet)
55 |> Map.mapWithKey checkValue
59 map (\(tipe, Var.Listing tags _) -> (tipe, tags)) (Var.getUnions exports)
61 (\() -> Docs.Docs comment)
62 <$> checkModuleComment region exports docNames
63 <*> checkCategory (checkComment Docs.aliasComment) aliases
64 <*> checkCategory (checkUnion exportedUnions) types
65 <*> checkCategory checkValue values
68checkComment :: (a -> Maybe String) -> String -> A.Located a -> Result w (A.Located a)
69checkComment getComment name (A.A region value) =
70 case getComment value of
72 R.throw region (Error.NoComment name)
75 R.ok (A.A region value)
78checkUnion :: [(String, [String])] -> String -> A.Located Docs.Union -> Result w (A.Located Docs.Union)
79checkUnion exportedUnions name value =
81 <$> filterUnionTags exportedUnions name value
82 <*> checkComment Docs.unionComment name value
85filterUnionTags :: [(String, [String])] -> String -> A.Located Docs.Union -> Result w (A.Located Docs.Union)
86filterUnionTags exportedUnions name (A.A region union@(Docs.Union _ _ ctors)) =
89 maybe [] id (List.lookup name exportedUnions)
91 R.ok $ A.A region $ union
93 filter (\(tag, _) -> elem tag exportedTags) ctors
98checkValue :: String -> A.Located (Docs.Value (Maybe Type.Type)) -> Result w (A.Located (Docs.Value Type.Type))
99checkValue name value =
101 <$> hasType name value
102 <*> checkComment Docs.valueComment name value
105hasType :: String -> A.Located (Docs.Value (Maybe Type.Type)) -> Result w (A.Located (Docs.Value Type.Type))
106hasType name (A.A region value) =
107 case Docs.valueType value of
109 R.ok (A.A region (value { Docs.valueType = tipe }))
112 R.throw region (Error.NoType name)
115-- CHECK MODULE COMMENT
117checkModuleComment :: R.Region -> [Var.Value] -> [A.Located String] -> Result w ()
118checkModuleComment docRegion exports locatedDocNames =
121 map valueName exports
124 Map.fromList (map (\name -> (name, ())) exportNames)
127 Map.fromList (map (\(A.A region name) -> (name, region)) locatedDocNames)
129 extraNameError (name, region) =
130 R.throw region (Error.OnlyInDocs name (Error.nearbyNames id name exportNames))
133 Map.difference docDict exportDict
135 |> T.traverse extraNameError
138 Map.difference exportDict docDict
143 if null namesOnlyInExports then
146 R.throw docRegion (Error.OnlyInExports namesOnlyInExports)
153commentedNames :: R.Region -> String -> [A.Located String]
154commentedNames (R.Region (R.Position line column) _) comment =
160 commaSep1 (addLocation (var <|> parens infixOp))
161 , do anyUntil simpleNewline
166 do setPosition (newPos "docs" line (column + 3))
167 concat <$> many nameParser
169 case parse docCommentParser comment of
177valueName :: Var.Value -> String
180 Var.Value name -> name
181 Var.Alias name -> name
182 Var.Union name _ -> name
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