on master help sign in
add code for syntax errors in module docs
commit1b49afedd535b2307fdc780aaa4c21a86d8cf0ed authorEvan Czaplicki <evancz@users.noreply.github.com> dateMon 24 Jun 2019, 19:05 (7 years ago) parente0717fc
1 file changed+68−3
compiler/src/Reporting/Error/Docs.hs+68−3
compiler/src/Reporting/Error/Docs.hs+68−3
@@ -35,7 +35,7 @@ data Error
3535data SyntaxProblem
3636 = Op Row Col
3737 | OpBad BadOperator Row Col
38− | Export Row Col
38+ | Name Row Col
3939 | Space E.Space Row Col
4040 | Comma Row Col
4141 | BadEnd Row Col
@@ -88,8 +88,9 @@ toReports source err =
8888 \ it will be easy to understand as people read the documentation!"
8989 )
9090
91− SyntaxProblem _ ->
92− error "TODO SyntaxProblem in docs"
91+ SyntaxProblem problem ->
92+ NE.singleton $
93+ toSyntaxProblemReport source problem
9394
9495 NameProblems problems ->
9596 fmap (toNameProblemReport source) problems
@@ -98,6 +99,66 @@ toReports source err =
9899 fmap (toDefProblemReport source) problems
99100
100101
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+
101162toNameProblemReport :: Code.Source -> NameProblem -> Report.Report
102163toNameProblemReport source problem =
103164 case problem of
@@ -151,6 +212,10 @@ toNameProblemReport source problem =
151212 )
152213
153214
215+
216+-- DEF PROBLEM
217+
218+
154219toDefProblemReport :: Code.Source -> DefProblem -> Report.Report
155220toDefProblemReport source problem =
156221 case problem of