1module Docs.Check (check) where
3import Control.Applicative ((<$>),(<*>))
4import qualified Data.Map as Map
5import qualified Data.Set as Set
6import qualified Data.Traversable as T
7import Text.Parsec ((<|>), choice, many, string)
9import qualified AST.Variable as Var
10import qualified Docs.AST as Docs
11import qualified Elm.Compiler.Type as Type
12import Elm.Utils ((|>))
14 ( anyUntil, commaSep1, iParse, parens, simpleNewline, symOp, var
17import qualified Reporting.Annotation as A
18import qualified Reporting.Error.Docs as Error
19import qualified Reporting.Region as R
20import qualified Reporting.Result as R
25check :: [Var.Value] -> A.Located (Maybe Docs.Centralized) -> R.Result w Error.Error Docs.Checked
26check exports (A.A region maybeDocs) =
29 R.throw region Error.NoDocs
32 checkHelp region exports docs
35checkHelp :: R.Region -> [Var.Value] -> Docs.Centralized -> R.Result w Error.Error Docs.Checked
36checkHelp region exports (Docs.Docs comment aliases types values) =
39 Set.fromList (commentedNames comment)
41 checkCategory checkValue dict =
43 |> Map.filterWithKey (\key _ -> Set.member key docNames)
44 |> Map.mapWithKey checkValue
47 checkValue name value =
49 <$> hasType name value
50 <*> hasComment Docs.valueComment name value
52 (\() -> Docs.Docs comment)
53 <$> checkComment region exports docNames
54 <*> checkCategory (hasComment Docs.aliasComment) aliases
55 <*> checkCategory (hasComment Docs.unionComment) types
56 <*> checkCategory checkValue values
60 :: (a -> Maybe String)
63 -> R.Result w Error.Error (A.Located a)
64hasComment getComment name (A.A region value) =
65 case getComment value of
67 R.throw region (Error.NoComment name)
70 R.ok (A.A region value)
75 -> A.Located (Docs.Value (Maybe Type.Type))
76 -> R.Result w Error.Error (A.Located (Docs.Value Type.Type))
77hasType name (A.A region value) =
78 case Docs.valueType value of
80 R.ok (A.A region (value { Docs.valueType = tipe }))
83 R.throw region (Error.NoType name)
86-- CHECK MODULE COMMENT
88checkComment :: R.Region -> [Var.Value] -> Set.Set String -> R.Result w Error.Error ()
89checkComment region exports docNames =
92 Set.fromList (map valueName exports)
95 Set.toList (Set.difference docNames exportNames)
98 Set.toList (Set.difference exportNames docNames)
101 <$> T.traverse (R.throw region . Error.OnlyInDocs) onlyInDocs
102 <*> T.traverse (R.throw region . Error.OnlyInExports) onlyInExports
105commentedNames :: String -> [String]
106commentedNames comment =
112 commaSep1 (var <|> parens symOp)
113 , do anyUntil simpleNewline
117 case iParse (concat <$> many nameParser) comment of
125valueName :: Var.Value -> String
128 Var.Value name -> name
129 Var.Alias name -> name
130 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