1module Docs.Check (check) where
3import Control.Applicative ((<$>),(<*>))
4import qualified Data.List as List
5import qualified Data.Map as Map
6import qualified Data.Set as Set
7import qualified Data.Traversable as T
8import Text.Parsec ((<|>), choice, many, setPosition, string)
9import Text.Parsec.Pos (newPos)
11import qualified AST.Variable as Var
12import qualified Docs.AST as Docs
13import qualified Elm.Compiler.Type as Type
14import Elm.Utils ((|>))
16 ( addLocation, anyUntil, commaSep1, iParse, parens, simpleNewline, symOp
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
26type Result w a = R.Result w Error.Error a
31check :: [Var.Value] -> A.Located (Maybe Docs.Centralized) -> Result w Docs.Checked
32check exports (A.A region maybeDocs) =
35 R.throw region Error.NoDocs
38 checkHelp region exports docs
41checkHelp :: R.Region -> [Var.Value] -> Docs.Centralized -> Result w Docs.Checked
42checkHelp region exports (Docs.Docs comment aliases types values) =
45 commentedNames region comment
48 Set.fromList (map A.drop docNames)
50 checkCategory checkValue dict =
52 |> Map.filterWithKey (\key _ -> Set.member key docSet)
53 |> Map.mapWithKey checkValue
57 map (\(tipe, Var.Listing tags _) -> (tipe, tags)) (Var.getUnions exports)
59 (\() -> Docs.Docs comment)
60 <$> checkModuleComment region exports docNames
61 <*> checkCategory (checkComment Docs.aliasComment) aliases
62 <*> checkCategory (checkUnion exportedUnions) types
63 <*> checkCategory checkValue values
66checkComment :: (a -> Maybe String) -> String -> A.Located a -> Result w (A.Located a)
67checkComment getComment name (A.A region value) =
68 case getComment value of
70 R.throw region (Error.NoComment name)
73 R.ok (A.A region value)
76checkUnion :: [(String, [String])] -> String -> A.Located Docs.Union -> Result w (A.Located Docs.Union)
77checkUnion exportedUnions name value =
79 <$> filterUnionTags exportedUnions name value
80 <*> checkComment Docs.unionComment name value
83filterUnionTags :: [(String, [String])] -> String -> A.Located Docs.Union -> Result w (A.Located Docs.Union)
84filterUnionTags exportedUnions name (A.A region union@(Docs.Union _ _ ctors)) =
87 maybe [] id (List.lookup name exportedUnions)
89 R.ok $ A.A region $ union
91 filter (\(tag, _) -> elem tag exportedTags) ctors
96checkValue :: String -> A.Located (Docs.Value (Maybe Type.Type)) -> Result w (A.Located (Docs.Value Type.Type))
97checkValue name value =
99 <$> hasType name value
100 <*> checkComment Docs.valueComment name value
103hasType :: String -> A.Located (Docs.Value (Maybe Type.Type)) -> Result w (A.Located (Docs.Value Type.Type))
104hasType name (A.A region value) =
105 case Docs.valueType value of
107 R.ok (A.A region (value { Docs.valueType = tipe }))
110 R.throw region (Error.NoType name)
113-- CHECK MODULE COMMENT
115checkModuleComment :: R.Region -> [Var.Value] -> [A.Located String] -> Result w ()
116checkModuleComment docRegion exports locatedDocNames =
119 map valueName exports
122 Map.fromList (map (\name -> (name, ())) exportNames)
125 Map.fromList (map (\(A.A region name) -> (name, region)) locatedDocNames)
127 extraNameError (name, region) =
128 R.throw region (Error.OnlyInDocs name (Error.nearbyNames id name exportNames))
131 Map.difference docDict exportDict
133 |> T.traverse extraNameError
136 Map.difference exportDict docDict
141 if null namesOnlyInExports then
144 R.throw docRegion (Error.OnlyInExports namesOnlyInExports)
151commentedNames :: R.Region -> String -> [A.Located String]
152commentedNames (R.Region start _) comment =
158 commaSep1 (addLocation (var <|> parens symOp))
159 , do anyUntil simpleNewline
164 do setPosition (newPos "docs" (R.line start) (R.column start + 3))
165 concat <$> many nameParser
167 case iParse docCommentParser comment of
175valueName :: Var.Value -> String
178 Var.Value name -> name
179 Var.Alias name -> name
180 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