on master help sign in
add code for syntax errors in module docs
1b49afeEvan Czaplicki
compiler/src/Reporting/Error/Docs.hs+68−3
@@ -35,7 +35,7 @@ data Error
35data SyntaxProblem
35data SyntaxProblem
36 = Op Row Col
36 = Op Row Col
37 | OpBad BadOperator Row Col
37 | OpBad BadOperator Row Col
38− | Export Row Col
38+ | Name Row Col
39 | Space E.Space Row Col
39 | Space E.Space Row Col
40 | Comma Row Col
40 | Comma Row Col
41 | BadEnd Row Col
41 | BadEnd Row Col
@@ -88,8 +88,9 @@ toReports source err =
88 \ it will be easy to understand as people read the documentation!"
88 \ it will be easy to understand as people read the documentation!"
89 )
89 )
90
90
91− SyntaxProblem _ ->
91+ SyntaxProblem problem ->
92− error "TODO SyntaxProblem in docs"
92+ NE.singleton $
93+ toSyntaxProblemReport source problem
93
94
94 NameProblems problems ->
95 NameProblems problems ->
95 fmap (toNameProblemReport source) problems
96 fmap (toNameProblemReport source) problems
@@ -98,6 +99,66 @@ toReports source err =
98 fmap (toDefProblemReport source) problems
99 fmap (toDefProblemReport source) problems
99
100
100
101
102+
103+-- SYNTAX PROBLEM
104+
105+
106+toSyntaxProblemReport :: Code.Source -> SyntaxProblem -> Report.Report
107+toSyntaxProblemReport source problem =
108+ let
109+ toSyntaxReport row col details =
110+ let
111+ region = toRegion row col
112+ in
113+ Report.Report "PROBLEM IN DOCS" region [] $
114+ Code.toSnippet source region Nothing
115+ ( D.reflow "I was partway through parsing your module documentation, but I got stuck here:"
116+ , D.stack $
117+ [ D.reflow details
118+ , D.toSimpleHint $
119+ "Read through https://package.elm-lang.org/help/documentation-format for\
120+ \ tips on how to write module documentation!"
121+ ]
122+ )
123+ in
124+ case problem of
125+ Op row col ->
126+ toSyntaxReport row col $
127+ "I am trying to parse an operator like (+) or (*) but something is going wrong."
128+
129+ OpBad _ row col ->
130+ toSyntaxReport row col $
131+ "I am trying to parse an operator like (+) or (*) but it looks like you are using\
132+ \ a reserved symbol in this case."
133+
134+ Name row col ->
135+ toSyntaxReport row col $
136+ "I was expecting to see the name of another exposed value from this module."
137+
138+ Space space row col ->
139+ E.toSpaceReport source space row col
140+
141+ Comma row col ->
142+ toSyntaxReport row col $
143+ "I was expecting to see a comma next."
144+
145+ BadEnd row col ->
146+ toSyntaxReport row col $
147+ "I am not really sure what I am getting stuck on though."
148+
149+
150+toRegion :: Row -> Col -> A.Region
151+toRegion row col =
152+ let
153+ pos = A.Position row col
154+ in
155+ A.Region pos pos
156+
157+
158+
159+-- NAME PROBLEM
160+
161+
101toNameProblemReport :: Code.Source -> NameProblem -> Report.Report
162toNameProblemReport :: Code.Source -> NameProblem -> Report.Report
102toNameProblemReport source problem =
163toNameProblemReport source problem =
103 case problem of
164 case problem of
@@ -151,6 +212,10 @@ toNameProblemReport source problem =
151 )
212 )
152
213
153
214
215+
216+-- DEF PROBLEM
217+
218+
154toDefProblemReport :: Code.Source -> DefProblem -> Report.Report
219toDefProblemReport :: Code.Source -> DefProblem -> Report.Report
155toDefProblemReport source problem =
220toDefProblemReport source problem =
156 case problem of
221 case problem of