1{-# OPTIONS_GHC -Wall #-}
8import Data.List.NonEmpty (NonEmpty((:|)))
9import qualified Data.Map as Map
10import qualified Data.Set as Set
11import Data.Text (Text)
13import qualified AST.Exposing as Exposing
14import qualified Docs.AST as Docs
15import qualified Elm.Compiler.Type as Type
16import qualified Reporting.Annotation as A
17import qualified Reporting.Error as Error
18import qualified Reporting.Error.Docs as E
19import qualified Reporting.Helpers as Help (nearbyNames)
20import qualified Reporting.Region as R
21import qualified Reporting.Result as R
23 ( Parser, addLocation, getPosition
24 , spaces, checkSpace, whitespace, SPos(..)
25 , capVar, lowVar, leftParen, rightParen, infixOp, runAt
26 , chompUntilDocs, comma, oneOf
34check :: Exposing.Canonical -> A.Located (Maybe Docs.Centralized) -> R.Result () w Error.Error Docs.Checked
35check exports (A.A region maybeDocs) =
38 R.throw region (Error.Docs E.NoDocs)
41 checkHelp region exports docs
44checkHelp :: R.Region -> Exposing.Canonical -> Docs.Centralized -> R.Result () w Error.Error Docs.Checked
45checkHelp region exposing (Docs.Centralized comment values aliases unions) =
46 do docNames <- parseNames region comment
48 let docSet = Set.fromList (map A.drop docNames)
49 let restrict checker dict =
50 Map.traverseWithKey checker (Map.restrictKeys dict docSet)
52 R.mapError Error.Docs $
54 <$> restrict checkValue values
55 <*> restrict checkAlias aliases
56 <*> restrict (checkUnion exposing) unions
57 <* checkCommentNames region exposing docNames
64type Result w a = R.Result () w E.Error a
67checkCommentNames :: R.Region -> Exposing.Canonical -> [A.Located Text] -> Result w ()
68checkCommentNames region (Exposing.Canonical values aliases unions) docNames =
74 Map.fromList $ map addUnit $
75 values ++ aliases ++ map fst unions
78 A.listToDict id docNames
80 checkOnlyInExports region (Map.difference exposed docDict)
81 <* Map.traverseMaybeWithKey (checkDocName exposed) docDict
84checkOnlyInExports :: R.Region -> Map.Map Text () -> Result w ()
85checkOnlyInExports region onlyInExports =
86 case Map.keys onlyInExports of
91 R.throw region (E.OnlyInExports names)
94checkDocName :: Map.Map Text () -> Text -> NonEmpty R.Region -> Result w (Maybe a)
95checkDocName exposed name (region :| duplicates) =
98 if Map.member name exposed then
102 R.throw region $ E.OnlyInDocs name $
103 Help.nearbyNames id name (Map.keys exposed)
106 R.throw region (E.Duplicates name)
113checkComment :: R.Region -> Text -> Maybe Text -> Result w Text
114checkComment region name maybeComment =
120 R.throw region (E.NoComment name)
127checkValue :: Text -> A.Located Docs.RawValue -> Result w Docs.GoodValue
128checkValue name (A.A region (Docs.Value comment tipe assocPrec)) =
130 <$> checkComment region name comment
131 <*> checkValueType region name tipe
135checkValueType :: R.Region -> Text -> Maybe Type.Type -> Result w Type.Type
136checkValueType region name maybeType =
142 R.throw region (E.NoType name)
149checkAlias :: Text -> A.Located Docs.RawAlias -> Result w Docs.GoodAlias
150checkAlias name (A.A region (Docs.Alias comment args tipe)) =
152 <$> checkComment region name comment
161checkUnion :: Exposing.Canonical -> Text -> A.Located Docs.RawUnion -> Result w Docs.GoodUnion
162checkUnion (Exposing.Canonical _ _ unions) name (A.A region (Docs.Union comment args ctors)) =
164 <$> checkComment region name comment
166 <*> checkUnionCtors (Map.fromList unions) name ctors
169checkUnionCtors :: Map.Map Text [Text] -> Text -> [(Text, [Type.Type])] -> Result w [(Text, [Type.Type])]
170checkUnionCtors unions name ctors =
173 maybe [] id (Map.lookup name unions)
176 ctor `elem` publicCtors
178 R.ok $ filter isPublic ctors
185parseNames :: R.Region -> Text -> R.Result () w Error.Error [A.Located Text]
186parseNames (R.Region (R.Position row col) _) comment =
187 case runAt row (col + 3) (namesParser []) comment of
188 Left (A.A region parseError) ->
189 R.throw region (Error.Syntax parseError)
195namesParser :: [A.Located Text] -> Parser [A.Located Text]
197 do isDocs <- chompUntilDocs
198 if isDocs then namesParserHelp names else return names
201namesParserHelp :: [A.Located Text] -> Parser [A.Located Text]
202namesParserHelp names =
203 do pos <- getPosition
204 (SPos spos) <- whitespace
206 then namesParser names
207 else namesParser =<< chompNames names
210chompNames :: [A.Located Text] -> Parser [A.Located Text]
212 do name <- addLocation (oneOf [ lowVar, capVar, operator ])
218 chompNames (name:names)
219 , return (name:names)
223operator :: Parser Text
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