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 ((|>))
15 ( addLocation, anyUntil, commaSep1, iParse, parens, simpleNewline, symOp
18import qualified Reporting.Annotation as A
19import qualified Reporting.Error.Docs as Error
20import qualified Reporting.Error.Helpers as Error (nearbyNames)
21import qualified Reporting.Region as R
22import qualified Reporting.Result as R
27 R.Result () w Error.Error a
32check :: [Var.Value] -> A.Located (Maybe Docs.Centralized) -> Result w Docs.Checked
33check exports (A.A region maybeDocs) =
36 R.throw region Error.NoDocs
39 checkHelp region exports docs
42checkHelp :: R.Region -> [Var.Value] -> Docs.Centralized -> Result w Docs.Checked
43checkHelp region exports (Docs.Docs comment aliases types values) =
46 commentedNames region comment
49 Set.fromList (map A.drop docNames)
51 checkCategory checkValue dict =
53 |> Map.filterWithKey (\key _ -> Set.member key docSet)
54 |> Map.mapWithKey checkValue
58 map (\(tipe, Var.Listing tags _) -> (tipe, tags)) (Var.getUnions exports)
60 (\() -> Docs.Docs comment)
61 <$> checkModuleComment region exports docNames
62 <*> checkCategory (checkComment Docs.aliasComment) aliases
63 <*> checkCategory (checkUnion exportedUnions) types
64 <*> checkCategory checkValue values
67checkComment :: (a -> Maybe String) -> String -> A.Located a -> Result w (A.Located a)
68checkComment getComment name (A.A region value) =
69 case getComment value of
71 R.throw region (Error.NoComment name)
74 R.ok (A.A region value)
77checkUnion :: [(String, [String])] -> String -> A.Located Docs.Union -> Result w (A.Located Docs.Union)
78checkUnion exportedUnions name value =
80 <$> filterUnionTags exportedUnions name value
81 <*> checkComment Docs.unionComment name value
84filterUnionTags :: [(String, [String])] -> String -> A.Located Docs.Union -> Result w (A.Located Docs.Union)
85filterUnionTags exportedUnions name (A.A region union@(Docs.Union _ _ ctors)) =
88 maybe [] id (List.lookup name exportedUnions)
90 R.ok $ A.A region $ union
92 filter (\(tag, _) -> elem tag exportedTags) ctors
97checkValue :: String -> A.Located (Docs.Value (Maybe Type.Type)) -> Result w (A.Located (Docs.Value Type.Type))
98checkValue name value =
100 <$> hasType name value
101 <*> checkComment Docs.valueComment name value
104hasType :: String -> A.Located (Docs.Value (Maybe Type.Type)) -> Result w (A.Located (Docs.Value Type.Type))
105hasType name (A.A region value) =
106 case Docs.valueType value of
108 R.ok (A.A region (value { Docs.valueType = tipe }))
111 R.throw region (Error.NoType name)
114-- CHECK MODULE COMMENT
116checkModuleComment :: R.Region -> [Var.Value] -> [A.Located String] -> Result w ()
117checkModuleComment docRegion exports locatedDocNames =
120 map valueName exports
123 Map.fromList (map (\name -> (name, ())) exportNames)
126 Map.fromList (map (\(A.A region name) -> (name, region)) locatedDocNames)
128 extraNameError (name, region) =
129 R.throw region (Error.OnlyInDocs name (Error.nearbyNames id name exportNames))
132 Map.difference docDict exportDict
134 |> T.traverse extraNameError
137 Map.difference exportDict docDict
142 if null namesOnlyInExports then
145 R.throw docRegion (Error.OnlyInExports namesOnlyInExports)
152commentedNames :: R.Region -> String -> [A.Located String]
153commentedNames (R.Region start _) comment =
159 commaSep1 (addLocation (var <|> parens symOp))
160 , do anyUntil simpleNewline
165 do setPosition (newPos "docs" (R.line start) (R.column start + 3))
166 concat <$> many nameParser
168 case iParse docCommentParser comment of
176valueName :: Var.Value -> String
179 Var.Value name -> name
180 Var.Alias name -> name
181 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