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.Docs overview unions aliases values) =
46 do docNames <- parseNames region overview
48 let docSet = Set.fromList (map A.drop docNames)
49 let restrict checker dict =
50 Map.traverseWithKey (checkEntry checker) (Map.restrictKeys dict docSet)
52 R.mapError Error.Docs $
54 <$> restrict (checkUnion exposing) unions
55 <*> restrict checkAlias aliases
56 <*> restrict checkValue values
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)
127checkEntry :: (R.Region -> Text -> a -> Result w b) -> Text -> Docs.Raw a -> Result w (Docs.Good b)
128checkEntry checkDetails name (A.A region (Docs.Entry comment details)) =
130 <$> checkComment region name comment
131 <*> checkDetails region name details
138checkUnion :: Exposing.Canonical -> R.Region -> Text -> Docs.Union -> Result w Docs.Union
139checkUnion (Exposing.Canonical _ _ unions) _region name (Docs.Union args ctors) =
142 maybe [] id (lookup name unions)
145 ctor `elem` publicCtors
147 pure $ Docs.Union args (filter isPublic ctors)
154checkAlias :: R.Region -> Text -> Docs.Alias -> Result w Docs.Alias
155checkAlias _ _ alias =
163checkValue :: R.Region -> Text -> Docs.RawValue -> Result w Docs.GoodValue
164checkValue region name value =
168 <$> checkValueType region name tipe
170 Docs.Infix tipe assoc prec ->
172 <$> checkValueType region name tipe
177checkValueType :: R.Region -> Text -> Maybe Type.Type -> Result w Type.Type
178checkValueType region name maybeType =
184 R.throw region (E.NoType name)
191parseNames :: R.Region -> Text -> R.Result () w Error.Error [A.Located Text]
192parseNames (R.Region (R.Position row col) _) comment =
193 case runAt row (col + 3) (namesParser []) comment of
194 Left (A.A region parseError) ->
195 R.throw region (Error.Syntax parseError)
201namesParser :: [A.Located Text] -> Parser [A.Located Text]
203 do isDocs <- chompUntilDocs
204 if isDocs then namesParserHelp names else return names
207namesParserHelp :: [A.Located Text] -> Parser [A.Located Text]
208namesParserHelp names =
209 do pos <- getPosition
210 (SPos spos) <- whitespace
212 then namesParser names
213 else namesParser =<< chompNames names
216chompNames :: [A.Located Text] -> Parser [A.Located Text]
218 do name <- addLocation (oneOf [ lowVar, capVar, operator ])
224 chompNames (name:names)
225 , return (name:names)
229operator :: 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