on master help sign in
split Reporting.Error.Docs type into a couple different parts
b8f1676Evan Czaplicki
compiler/src/Reporting/Error/Docs.hs+61−17
@@ -2,17 +2,24 @@
2{-# LANGUAGE OverloadedStrings #-}
2{-# LANGUAGE OverloadedStrings #-}
3module Reporting.Error.Docs
3module Reporting.Error.Docs
4 ( Error(..)
4 ( Error(..)
5− , toReport
5+ , SyntaxProblem(..)
6+ , NameProblem(..)
7+ , DefProblem(..)
8+ , toReports
6 )
9 )
7 where
10 where
8
11
9
12
10import qualified Data.Name as Name
13import qualified Data.Name as Name
14+import qualified Data.NonEmptyList as NE
11
15
16+import Parse.Primitives (Row, Col)
17+import Parse.Symbol (BadOperator(..))
12import qualified Reporting.Annotation as A
18import qualified Reporting.Annotation as A
13import Reporting.Doc ((<>))
19import Reporting.Doc ((<>))
14import qualified Reporting.Doc as D
20import qualified Reporting.Doc as D
15import qualified Reporting.Render.Code as Code
21import qualified Reporting.Render.Code as Code
22+import qualified Reporting.Error.Syntax as E
16import qualified Reporting.Report as Report
23import qualified Reporting.Report as Report
17
24
18
25
@@ -20,36 +27,56 @@ import qualified Reporting.Report as Report
20data Error
27data Error
21 = NoDocs A.Region
28 = NoDocs A.Region
22 | ImplicitExposing A.Region
29 | ImplicitExposing A.Region
30+ | SyntaxProblem SyntaxProblem
31+ | NameProblems (NE.List NameProblem)
32+ | DefProblems (NE.List DefProblem)
33+
34+
35+data SyntaxProblem
36+ = Op Row Col
37+ | OpBad BadOperator Row Col
38+ | Export Row Col
39+ | Space E.Space Row Col
40+ | Comma Row Col
41+ | BadEnd Row Col
42+
43+
44+data NameProblem
23− | Duplicate Name.Name A.Region A.Region
45+ = NameDuplicate Name.Name A.Region A.Region
24− | OnlyInDocs Name.Name A.Region
46+ | NameOnlyInDocs Name.Name A.Region
25− | OnlyInExports Name.Name A.Region
47+ | NameOnlyInExports Name.Name A.Region
48+
49+
50+data DefProblem
26− | NoComment Name.Name A.Region
51+ = NoComment Name.Name A.Region
27 | NoAnnotation Name.Name A.Region
52 | NoAnnotation Name.Name A.Region
28
53
29
54
30
55
31−-- TO REPORT
56+-- TO REPORTS
32
57
33
58
34−toReport :: Code.Source -> Error -> Report.Report
59+toReports :: Code.Source -> Error -> NE.List Report.Report
35−toReport source err =
60+toReports source err =
36 case err of
61 case err of
37 NoDocs region ->
62 NoDocs region ->
63+ NE.singleton $
38 Report.Report "NO DOCS" region [] $
64 Report.Report "NO DOCS" region [] $
39− D.stack
65+ Code.toSnippet source region Nothing
40− [
66+ (
41 D.reflow $
67 D.reflow $
42 "You must have a documentation comment between the module\
68 "You must have a documentation comment between the module\
43 \ declaration and the imports."
69 \ declaration and the imports."
44 ,
70 ,
45 D.reflow
71 D.reflow
46 "Learn more at <http://package.elm-lang.org/help/documentation-format>"
72 "Learn more at <http://package.elm-lang.org/help/documentation-format>"
47− ]
73+ )
48
74
49 ImplicitExposing region ->
75 ImplicitExposing region ->
76+ NE.singleton $
50 Report.Report "IMPLICIT EXPOSING" region [] $
77 Report.Report "IMPLICIT EXPOSING" region [] $
51− D.stack
78+ Code.toSnippet source region Nothing
52− [
79+ (
53 D.reflow $
80 D.reflow $
54 "I need you to be explicit about what this module exposes:"
81 "I need you to be explicit about what this module exposes:"
55 ,
82 ,
@@ -59,9 +86,22 @@ toReport source err =
59 \ to be explicit about this is a way of adding another quality check before\
86 \ to be explicit about this is a way of adding another quality check before\
60 \ code gets published. So as you write out the public API, ask yourself if\
87 \ code gets published. So as you write out the public API, ask yourself if\
61 \ it will be easy to understand as people read the documentation!"
88 \ it will be easy to understand as people read the documentation!"
62− ]
89+ )
90+
91+ SyntaxProblem _ ->
92+ error "TODO SyntaxProblem in docs"
63
93
94+ NameProblems problems ->
95+ fmap (toNameProblemReport source) problems
96+
97+ DefProblems problems ->
98+ fmap (toDefProblemReport source) problems
99+
100+
101+toNameProblemReport :: Code.Source -> NameProblem -> Report.Report
102+toNameProblemReport source problem =
103+ case problem of
64− Duplicate name r1 r2 ->
104+ NameDuplicate name r1 r2 ->
65 Report.Report "DUPLICATE DOCS" r2 [] $
105 Report.Report "DUPLICATE DOCS" r2 [] $
66 Code.toPair source r1 r2
106 Code.toPair source r1 r2
67 (
107 (
@@ -81,7 +121,7 @@ toReport source err =
81 "Remove one of them!"
121 "Remove one of them!"
82 )
122 )
83
123
84− OnlyInDocs name region ->
124+ NameOnlyInDocs name region ->
85 Report.Report "DOCS MISTAKE" region [] $
125 Report.Report "DOCS MISTAKE" region [] $
86 Code.toSnippet source region Nothing
126 Code.toSnippet source region Nothing
87 (
127 (
@@ -94,7 +134,7 @@ toReport source err =
94 <> Name.toChars name <> "` and forgot to delete it here?"
134 <> Name.toChars name <> "` and forgot to delete it here?"
95 )
135 )
96
136
97− OnlyInExports name region ->
137+ NameOnlyInExports name region ->
98 Report.Report "DOCS MISTAKE" region [] $
138 Report.Report "DOCS MISTAKE" region [] $
99 Code.toSnippet source region Nothing
139 Code.toSnippet source region Nothing
100 (
140 (
@@ -110,6 +150,10 @@ toReport source err =
110 ]
150 ]
111 )
151 )
112
152
153+
154+toDefProblemReport :: Code.Source -> DefProblem -> Report.Report
155+toDefProblemReport source problem =
156+ case problem of
113 NoComment name region ->
157 NoComment name region ->
114 Report.Report "NO DOCS" region [] $
158 Report.Report "NO DOCS" region [] $
115 Code.toSnippet source region Nothing
159 Code.toSnippet source region Nothing