on master help sign in
Move Report.toCodeSnippet to Code.toSnippet
commite43ce3dd1486f1136ed53ddc825bc1be662f71b6 authorEvan Czaplicki <evancz@users.noreply.github.com> dateThu 9 May 2019, 10:49 (7 years ago) parentdf9c15a
9 files changed+101−105
compiler/src/Reporting/Error/Canonicalize.hs+33−33 compiler/src/Reporting/Error/Docs.hs+5−5 compiler/src/Reporting/Error/Import.hs+4−4 compiler/src/Reporting/Error/Main.hs+3−3 compiler/src/Reporting/Error/Pattern.hs+4−4 compiler/src/Reporting/Error/Type.hs+9−9 compiler/src/Reporting/Render/Code.hs+40−4 compiler/src/Reporting/Report.hs−40 compiler/src/Reporting/Warning.hs+3−3
compiler/src/Reporting/Error/Canonicalize.hs+33−33
@@ -151,7 +151,7 @@ toReport source err =
151151 numDefArgs = numTypeArgs + leftovers
152152 in
153153 Report.Report "BAD TYPE ANNOTATION" region [] $
154− Report.toCodeSnippet source region Nothing
154+ Code.toSnippet source region Nothing
155155 (
156156 D.reflow $
157157 "The type annotation for `" <> Name.toChars name <> "` says it can accept "
@@ -185,7 +185,7 @@ toReport source err =
185185 in
186186 if actual < expected then
187187 Report.Report "TOO FEW ARGS" region [] $
188− Report.toCodeSnippet source region Nothing
188+ Code.toSnippet source region Nothing
189189 (
190190 D.reflow $
191191 "The `" <> Name.toChars name <> "` " <> thing <> " needs "
@@ -197,7 +197,7 @@ toReport source err =
197197
198198 else
199199 Report.Report "TOO MANY ARGS" region [] $
200− Report.toCodeSnippet source region Nothing
200+ Code.toSnippet source region Nothing
201201 (
202202 D.reflow $
203203 "The `" <> Name.toChars name <> "` " <> thing <> " needs "
@@ -211,7 +211,7 @@ toReport source err =
211211
212212 Binop region op1 op2 ->
213213 Report.Report "INFIX PROBLEM" region [] $
214− Report.toCodeSnippet source region Nothing
214+ Code.toSnippet source region Nothing
215215 (
216216 D.reflow $
217217 "You cannot mix (" <> Name.toChars op1 <> ") and (" <> Name.toChars op2 <> ") without parentheses."
@@ -268,7 +268,7 @@ toReport source err =
268268
269269 EffectNotFound region name ->
270270 Report.Report "EFFECT PROBLEM" region [] $
271− Report.toCodeSnippet source region Nothing
271+ Code.toSnippet source region Nothing
272272 (
273273 D.reflow $
274274 "You have declared that `" ++ Name.toChars name ++ "` is an effect type:"
@@ -279,7 +279,7 @@ toReport source err =
279279
280280 EffectFunctionNotFound region name ->
281281 Report.Report "EFFECT PROBLEM" region [] $
282− Report.toCodeSnippet source region Nothing
282+ Code.toSnippet source region Nothing
283283 (
284284 D.reflow $
285285 "This kind of effect module must define a `" ++ Name.toChars name ++ "` function."
@@ -295,7 +295,7 @@ toReport source err =
295295 "You are trying to expose `" <> Name.toChars name <> "` multiple times!"
296296 in
297297 Report.Report "REDUNDANT EXPORT" r2 [] $
298− Report.toCodePair source r1 r2
298+ Code.toPair source r1 r2
299299 (
300300 D.reflow messageThatEndsWithPunctuation
301301 ,
@@ -339,7 +339,7 @@ toReport source err =
339339
340340 ExportOpenAlias region name ->
341341 Report.Report "BAD EXPORT" region [] $
342− Report.toCodeSnippet source region Nothing
342+ Code.toSnippet source region Nothing
343343 (
344344 D.reflow $
345345 "The (..) syntax is for exposing union type constructors. It cannot be used with a type alias like `"
@@ -351,7 +351,7 @@ toReport source err =
351351
352352 ImportCtorByName region ctor tipe ->
353353 Report.Report "BAD IMPORT" region [] $
354− Report.toCodeSnippet source region Nothing
354+ Code.toSnippet source region Nothing
355355 (
356356 D.reflow $
357357 "You are trying to import the `" <> Name.toChars ctor
@@ -371,7 +371,7 @@ toReport source err =
371371 -- So this error should never actually get printed out.
372372 --
373373 Report.Report "UNKNOWN IMPORT" region [] $
374− Report.toCodeSnippet source region Nothing
374+ Code.toSnippet source region Nothing
375375 (
376376 D.reflow $
377377 "I could not find a `" <> Name.toChars name <> "` module to import!"
@@ -381,7 +381,7 @@ toReport source err =
381381
382382 ImportOpenAlias region name ->
383383 Report.Report "BAD IMPORT" region [] $
384− Report.toCodeSnippet source region Nothing
384+ Code.toSnippet source region Nothing
385385 (
386386 D.reflow $
387387 "The `" <> Name.toChars name <> "` type alias cannot be followed by (..) like this:"
@@ -402,7 +402,7 @@ toReport source err =
402402 Suggest.sort (Name.toChars home) Name.toChars possibleNames
403403 in
404404 Report.Report "BAD IMPORT" region suggestions $
405− Report.toCodeSnippet source region Nothing
405+ Code.toSnippet source region Nothing
406406 (
407407 D.reflow $
408408 "The `" <> Name.toChars home
@@ -435,7 +435,7 @@ toReport source err =
435435 NotFoundBinop region op locals ->
436436 if op == "===" then
437437 Report.Report "UNKNOWN OPERATOR" region ["=="] $
438− Report.toCodeSnippet source region Nothing
438+ Code.toSnippet source region Nothing
439439 (
440440 "Elm does not have a (===) operator like JavaScript."
441441 ,
@@ -444,7 +444,7 @@ toReport source err =
444444
445445 else if op == "!=" || op == "!==" then
446446 Report.Report "UNKNOWN OPERATOR" region ["/="] $
447− Report.toCodeSnippet source region Nothing
447+ Code.toSnippet source region Nothing
448448 (
449449 D.reflow $
450450 "Elm uses a different name for the “not equal” operator:"
@@ -459,7 +459,7 @@ toReport source err =
459459
460460 else if op == "**" then
461461 Report.Report "UNKNOWN OPERATOR" region ["^","*"] $
462− Report.toCodeSnippet source region Nothing
462+ Code.toSnippet source region Nothing
463463 (
464464 D.reflow $
465465 "I do not recognize the (**) operator:"
@@ -470,7 +470,7 @@ toReport source err =
470470
471471 else if op == "%" then
472472 Report.Report "UNKNOWN OPERATOR" region [] $
473− Report.toCodeSnippet source region Nothing
473+ Code.toSnippet source region Nothing
474474 (
475475 D.reflow $
476476 "Elm does not use (%) as the remainder operator:"
@@ -497,7 +497,7 @@ toReport source err =
497497 D.green $ "(" <> altOp <> ")"
498498 in
499499 Report.Report "UNKNOWN OPERATOR" region suggestions $
500− Report.toCodeSnippet source region Nothing
500+ Code.toSnippet source region Nothing
501501 (
502502 D.reflow $
503503 "I do not recognize the (" ++ Name.toChars op ++ ") operator."
@@ -515,7 +515,7 @@ toReport source err =
515515
516516 PatternHasRecordCtor region name ->
517517 Report.Report "BAD PATTERN" region [] $
518− Report.toCodeSnippet source region Nothing
518+ Code.toSnippet source region Nothing
519519 (
520520 D.reflow $
521521 "You can construct records by using `" <> Name.toChars name
@@ -529,7 +529,7 @@ toReport source err =
529529 let
530530 formatDetails (aBadKindOfThing, elaboration) =
531531 Report.Report "PORT ERROR" region [] $
532− Report.toCodeSnippet source region Nothing
532+ Code.toSnippet source region Nothing
533533 (
534534 D.reflow $
535535 "The `" <> Name.toChars portName <> "` port is trying to transmit " <> aBadKindOfThing <> ":"
@@ -595,7 +595,7 @@ toReport source err =
595595 let
596596 formatDetails (before, after) =
597597 Report.Report "BAD PORT" region [] $
598− Report.toCodeSnippet source region Nothing $
598+ Code.toSnippet source region Nothing $
599599 (
600600 D.reflow before
601601 ,
@@ -674,7 +674,7 @@ toReport source err =
674674 D.fillSep $ map (D.dullyellow . D.fromChars) (words question) ++ map D.fromChars (words details)
675675 in
676676 Report.Report "CYCLIC DEFINITION" region [] $
677− Report.toCodeSnippet source region Nothing $
677+ Code.toSnippet source region Nothing $
678678 case names of
679679 [] ->
680680 (
@@ -716,7 +716,7 @@ toReport source err =
716716
717717 RecursiveLet (A.At region name) names ->
718718 Report.Report "CYCLIC VALUE" region [] $
719− Report.toCodeSnippet source region Nothing $
719+ Code.toSnippet source region Nothing $
720720 case names of
721721 [] ->
722722 let
@@ -762,7 +762,7 @@ toReport source err =
762762
763763 Shadowing name r1 r2 ->
764764 Report.Report "SHADOWING" r2 [] $
765− Report.toCodePair source r1 r2
765+ Code.toPair source r1 r2
766766 ( "These variables cannot have the same name:"
767767 , advice
768768 )
@@ -783,7 +783,7 @@ toReport source err =
783783
784784 TupleLargerThanThree region ->
785785 Report.Report "BAD TUPLE" region [] $
786− Report.toCodeSnippet source region Nothing
786+ Code.toSnippet source region Nothing
787787 (
788788 "I only accept tuples with two or three items. This has too many:"
789789 ,
@@ -832,7 +832,7 @@ toReport source err =
832832 )
833833 in
834834 Report.Report title aliasRegion [] $
835− Report.toCodeSnippet source aliasRegion subRegion
835+ Code.toSnippet source aliasRegion subRegion
836836 (
837837 D.fillSep overview
838838 ,
@@ -885,7 +885,7 @@ toReport source err =
885885
886886 in
887887 Report.Report "TYPE VARIABLE PROBLEMS" aliasRegion [] $
888− Report.toCodeSnippet source aliasRegion Nothing
888+ Code.toSnippet source aliasRegion Nothing
889889 (
890890 D.reflow $
891891 "Type alias `" <> Name.toChars typeName <> "` has some type variable problems."
@@ -932,7 +932,7 @@ unboundTypeVars source declRegion tipe typeName allVars (unboundVar, varRegion)
932932 )
933933 in
934934 Report.Report title declRegion [] $
935− Report.toCodeSnippet source declRegion subRegion
935+ Code.toSnippet source declRegion subRegion
936936 (
937937 D.fillSep overview
938938 ,
@@ -960,7 +960,7 @@ unboundTypeVars source declRegion tipe typeName allVars (unboundVar, varRegion)
960960nameClash :: Code.Source -> A.Region -> A.Region -> String -> Report.Report
961961nameClash source r1 r2 messageThatEndsWithPunctuation =
962962 Report.Report "NAME CLASH" r2 [] $
963− Report.toCodePair source r1 r2
963+ Code.toPair source r1 r2
964964 (
965965 D.reflow messageThatEndsWithPunctuation
966966 ,
@@ -982,7 +982,7 @@ nameClash source r1 r2 messageThatEndsWithPunctuation =
982982ambiguousName :: Code.Source -> A.Region -> Maybe Name.Name -> Name.Name -> [ModuleName.Canonical] -> String -> Report.Report
983983ambiguousName source region maybePrefix name possibleHomes thing =
984984 Report.Report "AMBIGUOUS NAME" region [] $
985− Report.toCodeSnippet source region Nothing $
985+ Code.toSnippet source region Nothing $
986986 case maybePrefix of
987987 Nothing ->
988988 let
@@ -1065,7 +1065,7 @@ notFound source region maybePrefix name thing (PossibleNames locals quals) =
10651065
10661066 in
10671067 Report.Report "NAMING ERROR" region nearbyNames $
1068− Report.toCodeSnippet source region Nothing
1068+ Code.toSnippet source region Nothing
10691069 (
10701070 D.reflow $
10711071 "I cannot find a `" ++ givenName ++ "` " ++ thing ++ ":"
@@ -1195,7 +1195,7 @@ _argMismatchReport source region kind name expected actual =
11951195 <> " arguments"
11961196 in
11971197 Report.Report (map Char.toUpper numArgs) region [] $
1198− Report.toCodeSnippet source region Nothing
1198+ Code.toSnippet source region Nothing
11991199 (
12001200 D.reflow $
12011201 kind <> " " <> Name.toChars name <> " has " <> numArgs <> "."
@@ -1214,7 +1214,7 @@ aliasRecursionReport source region name args tipe others =
12141214 case others of
12151215 [] ->
12161216 Report.Report "ALIAS PROBLEM" region [] $
1217− Report.toCodeSnippet source region Nothing
1217+ Code.toSnippet source region Nothing
12181218 (
12191219 "This type alias is recursive, forming an infinite type!"
12201220 ,
@@ -1233,7 +1233,7 @@ aliasRecursionReport source region name args tipe others =
12331233
12341234 _ ->
12351235 Report.Report "ALIAS PROBLEM" region [] $
1236− Report.toCodeSnippet source region Nothing
1236+ Code.toSnippet source region Nothing
12371237 (
12381238 "This type alias is part of a mutually recursive set of type aliases."
12391239 ,
compiler/src/Reporting/Error/Docs.hs+5−5
@@ -63,7 +63,7 @@ toReport source err =
6363
6464 Duplicate name r1 r2 ->
6565 Report.Report "DUPLICATE DOCS" r2 [] $
66− Report.toCodePair source r1 r2
66+ Code.toPair source r1 r2
6767 (
6868 D.reflow $
6969 "There can only be one `" <> Name.toChars name
@@ -83,7 +83,7 @@ toReport source err =
8383
8484 OnlyInDocs name region ->
8585 Report.Report "DOCS MISTAKE" region [] $
86− Report.toCodeSnippet source region Nothing
86+ Code.toSnippet source region Nothing
8787 (
8888 D.reflow $
8989 "I do not see `" <> Name.toChars name
@@ -96,7 +96,7 @@ toReport source err =
9696
9797 OnlyInExports name region ->
9898 Report.Report "DOCS MISTAKE" region [] $
99− Report.toCodeSnippet source region Nothing
99+ Code.toSnippet source region Nothing
100100 (
101101 D.reflow $
102102 "I do not see `" <> Name.toChars name
@@ -112,7 +112,7 @@ toReport source err =
112112
113113 NoComment name region ->
114114 Report.Report "NO DOCS" region [] $
115− Report.toCodeSnippet source region Nothing
115+ Code.toSnippet source region Nothing
116116 (
117117 D.reflow $
118118 "The `" <> Name.toChars name <> "` definition does not have a documentation comment."
@@ -126,7 +126,7 @@ toReport source err =
126126
127127 NoAnnotation name region ->
128128 Report.Report "NO TYPE ANNOTATION" region [] $
129− Report.toCodeSnippet source region Nothing
129+ Code.toSnippet source region Nothing
130130 (
131131 D.reflow $
132132 "The `" <> Name.toChars name <> "` definition does not have a type annotation."
compiler/src/Reporting/Error/Import.hs+4−4
@@ -48,7 +48,7 @@ toReport source (Error region name unimportedModules problem) =
4848 case problem of
4949 NotFound ->
5050 Report.Report "MODULE NOT FOUND" region [] $
51− Report.toCodeSnippet source region Nothing
51+ Code.toSnippet source region Nothing
5252 (
5353 D.reflow $
5454 "You are trying to import a `" ++ ModuleName.toChars name ++ "` module:"
@@ -83,7 +83,7 @@ toReport source (Error region name unimportedModules problem) =
8383
8484 Ambiguous path _ pkg _ ->
8585 Report.Report "AMBIGUOUS IMPORT" region [] $
86− Report.toCodeSnippet source region Nothing
86+ Code.toSnippet source region Nothing
8787 (
8888 D.reflow $
8989 "You are trying to import a `" ++ ModuleName.toChars name ++ "` module:"
@@ -105,7 +105,7 @@ toReport source (Error region name unimportedModules problem) =
105105
106106 AmbiguousLocal path1 path2 paths ->
107107 Report.Report "AMBIGUOUS IMPORT" region [] $
108− Report.toCodeSnippet source region Nothing
108+ Code.toSnippet source region Nothing
109109 (
110110 D.reflow $
111111 "You are trying to import a `" ++ ModuleName.toChars name ++ "` module:"
@@ -125,7 +125,7 @@ toReport source (Error region name unimportedModules problem) =
125125
126126 AmbiguousForeign pkg1 pkg2 pkgs ->
127127 Report.Report "AMBIGUOUS IMPORT" region [] $
128− Report.toCodeSnippet source region Nothing
128+ Code.toSnippet source region Nothing
129129 (
130130 D.reflow $
131131 "You are trying to import a `" ++ ModuleName.toChars name ++ "` module:"
compiler/src/Reporting/Error/Main.hs+3−3
@@ -38,7 +38,7 @@ toReport localizer source err =
3838 case err of
3939 BadType region tipe ->
4040 Report.Report "BAD MAIN TYPE" region [] $
41− Report.toCodeSnippet source region Nothing
41+ Code.toSnippet source region Nothing
4242 (
4343 "I cannot handle this type of `main` value:"
4444 ,
@@ -53,7 +53,7 @@ toReport localizer source err =
5353
5454 BadCycle region name names ->
5555 Report.Report "BAD MAIN" region [] $
56− Report.toCodeSnippet source region Nothing
56+ Code.toSnippet source region Nothing
5757 (
5858 "A `main` definition cannot be defined in terms of itself."
5959 ,
@@ -69,7 +69,7 @@ toReport localizer source err =
6969 let
7070 formatDetails (aBadKindOfThing, butThatIsNoGood) =
7171 Report.Report "BAD FLAGS" region [] $
72− Report.toCodeSnippet source region Nothing
72+ Code.toSnippet source region Nothing
7373 (
7474 D.reflow $
7575 "Your `main` program wants " ++ aBadKindOfThing ++ " from JavaScript."
compiler/src/Reporting/Error/Pattern.hs+4−4
@@ -24,7 +24,7 @@ toReport source err =
2424 case err of
2525 P.Redundant caseRegion patternRegion index ->
2626 Report.Report "REDUNDANT PATTERN" patternRegion [] $
27− Report.toCodeSnippet source caseRegion (Just patternRegion)
27+ Code.toSnippet source caseRegion (Just patternRegion)
2828 (
2929 D.reflow $
3030 "The " <> D.intToOrdinal index <> " pattern is redundant:"
@@ -38,7 +38,7 @@ toReport source err =
3838 case context of
3939 P.BadArg ->
4040 Report.Report "UNSAFE PATTERN" region [] $
41− Report.toCodeSnippet source region Nothing
41+ Code.toSnippet source region Nothing
4242 (
4343 "This pattern does not cover all possiblities:"
4444 ,
@@ -54,7 +54,7 @@ toReport source err =
5454
5555 P.BadDestruct ->
5656 Report.Report "UNSAFE PATTERN" region [] $
57− Report.toCodeSnippet source region Nothing
57+ Code.toSnippet source region Nothing
5858 (
5959 "This pattern does not cover all possible values:"
6060 ,
@@ -74,7 +74,7 @@ toReport source err =
7474
7575 P.BadCase ->
7676 Report.Report "MISSING PATTERNS" region [] $
77− Report.toCodeSnippet source region Nothing
77+ Code.toSnippet source region Nothing
7878 (
7979 "This `case` does not have branches for all possibilities:"
8080 ,
compiler/src/Reporting/Error/Type.hs+9−9
@@ -188,7 +188,7 @@ toPatternReport source localizer patternRegion category tipe expected =
188188 Report.Report "TYPE MISMATCH" patternRegion [] $
189189 case expected of
190190 PNoExpectation expectedType ->
191− Report.toCodeSnippet source patternRegion Nothing $
191+ Code.toSnippet source patternRegion Nothing $
192192 ( "This pattern is being used in an unexpected way:"
193193 , patternTypeComparison localizer tipe expectedType
194194 (addPatternCategory "It is" category)
@@ -197,7 +197,7 @@ toPatternReport source localizer patternRegion category tipe expected =
197197 )
198198
199199 PFromContext region context expectedType ->
200− Report.toCodeSnippet source region (Just patternRegion) $
200+ Code.toSnippet source region (Just patternRegion) $
201201 case context of
202202 PTypedArg name index ->
203203 ( D.reflow $
@@ -630,7 +630,7 @@ toExprReport source localizer exprRegion category tipe expected =
630630 case expected of
631631 NoExpectation expectedType ->
632632 Report.Report "TYPE MISMATCH" exprRegion [] $
633− Report.toCodeSnippet source exprRegion Nothing
633+ Code.toSnippet source exprRegion Nothing
634634 ( "This expression is being used in an unexpected way:"
635635 , typeComparison localizer tipe expectedType
636636 (addCategory "It is" category)
@@ -653,7 +653,7 @@ toExprReport source localizer exprRegion category tipe expected =
653653 TypedBody -> "The body is"
654654 in
655655 Report.Report "TYPE MISMATCH" exprRegion [] $
656− Report.toCodeSnippet source exprRegion Nothing $
656+ Code.toSnippet source exprRegion Nothing $
657657 ( D.reflow ("Something is off with the " <> thing)
658658 , typeComparison localizer tipe expectedType
659659 (addCategory itIs category)
@@ -665,21 +665,21 @@ toExprReport source localizer exprRegion category tipe expected =
665665 let
666666 mismatch (maybeHighlight, problem, thisIs, insteadOf, furtherDetails) =
667667 Report.Report "TYPE MISMATCH" exprRegion [] $
668− Report.toCodeSnippet source region maybeHighlight
668+ Code.toSnippet source region maybeHighlight
669669 ( D.reflow problem
670670 , typeComparison localizer tipe expectedType (addCategory thisIs category) insteadOf furtherDetails
671671 )
672672
673673 badType (maybeHighlight, problem, thisIs, furtherDetails) =
674674 Report.Report "TYPE MISMATCH" exprRegion [] $
675− Report.toCodeSnippet source region maybeHighlight
675+ Code.toSnippet source region maybeHighlight
676676 ( D.reflow problem
677677 , loneType localizer tipe expectedType (D.reflow (addCategory thisIs category)) furtherDetails
678678 )
679679
680680 custom maybeHighlight docPair =
681681 Report.Report "TYPE MISMATCH" exprRegion [] $
682− Report.toCodeSnippet source region maybeHighlight docPair
682+ Code.toSnippet source region maybeHighlight docPair
683683 in
684684 case context of
685685 ListEntry index ->
@@ -762,7 +762,7 @@ toExprReport source localizer exprRegion category tipe expected =
762762
763763 CallArity maybeFuncName numGivenArgs ->
764764 Report.Report "TOO MANY ARGS" exprRegion [] $
765− Report.toCodeSnippet source region (Just exprRegion) $
765+ Code.toSnippet source region (Just exprRegion) $
766766 case countArgs tipe of
767767 0 ->
768768 let
@@ -1574,7 +1574,7 @@ badEquality localizer op tipe expected =
15741574toInfiniteReport :: Code.Source -> L.Localizer -> A.Region -> Name.Name -> T.Type -> Report.Report
15751575toInfiniteReport source localizer region name overallType =
15761576 Report.Report "INFINITE TYPE" region [] $
1577− Report.toCodeSnippet source region Nothing
1577+ Code.toSnippet source region Nothing
15781578 (
15791579 D.reflow $
15801580 "I am inferring a weird self-referential type for " <> Name.toChars name <> ":"
compiler/src/Reporting/Render/Code.hs+40−4
@@ -3,9 +3,8 @@
33module Reporting.Render.Code
44 ( Source
55 , toSource
6− , render
7− , CodePair(..)
8− , renderPair
6+ , toSnippet
7+ , toPair
98 )
109 where
1110
@@ -35,7 +34,44 @@ toSource source =
3534
3635
3736
38−-- RENDER
37+-- CODE FORMATTING
38+
39+
40+toSnippet :: Source -> A.Region -> Maybe A.Region -> (D.Doc, D.Doc) -> D.Doc
41+toSnippet source region highlight (preHint, postHint) =
42+ D.vcat
43+ [ preHint
44+ , ""
45+ , render source region highlight
46+ , postHint
47+ ]
48+
49+
50+toPair :: Source -> A.Region -> A.Region -> (D.Doc, D.Doc) -> (D.Doc, D.Doc, D.Doc) -> D.Doc
51+toPair source r1 r2 (oneStart, oneEnd) (twoStart, twoMiddle, twoEnd) =
52+ case renderPair source r1 r2 of
53+ OneLine codeDocs ->
54+ D.vcat
55+ [ oneStart
56+ , ""
57+ , codeDocs
58+ , oneEnd
59+ ]
60+
61+ TwoChunks code1 code2 ->
62+ D.vcat
63+ [ twoStart
64+ , ""
65+ , code1
66+ , twoMiddle
67+ , ""
68+ , code2
69+ , twoEnd
70+ ]
71+
72+
73+
74+-- RENDER SNIPPET
3975
4076
4177(|>) :: a -> (a -> b) -> b
compiler/src/Reporting/Report.hs−40
@@ -1,15 +1,12 @@
11{-# LANGUAGE OverloadedStrings #-}
22module Reporting.Report
33 ( Report(..)
4− , toCodeSnippet
5− , toCodePair
64 )
75 where
86
97
108import qualified Reporting.Annotation as A
119import qualified Reporting.Doc as D
12−import qualified Reporting.Render.Code as Code
1310
1411
1512
@@ -23,40 +20,3 @@ data Report =
2320 , _sgstns :: [String]
2421 , _message :: D.Doc
2522 }
26−
27−
28−
29−-- CODE FORMATTING
30−
31−
32−toCodeSnippet :: Code.Source -> A.Region -> Maybe A.Region -> (D.Doc, D.Doc) -> D.Doc
33−toCodeSnippet source region highlight (preHint, postHint) =
34− D.vcat
35− [ preHint
36− , ""
37− , Code.render source region highlight
38− , postHint
39− ]
40−
41−
42−toCodePair :: Code.Source -> A.Region -> A.Region -> (D.Doc, D.Doc) -> (D.Doc, D.Doc, D.Doc) -> D.Doc
43−toCodePair source r1 r2 (oneStart, oneEnd) (twoStart, twoMiddle, twoEnd) =
44− case Code.renderPair source r1 r2 of
45− Code.OneLine codeDocs ->
46− D.vcat
47− [ oneStart
48− , ""
49− , codeDocs
50− , oneEnd
51− ]
52−
53− Code.TwoChunks code1 code2 ->
54− D.vcat
55− [ twoStart
56− , ""
57− , code1
58− , twoMiddle
59− , ""
60− , code2
61− , twoEnd
62− ]
compiler/src/Reporting/Warning.hs+3−3
@@ -43,7 +43,7 @@ toReport localizer source warning =
4343 case warning of
4444 UnusedImport region moduleName ->
4545 Report.Report "unused import" region [] $
46− Report.toCodeSnippet source region Nothing
46+ Code.toSnippet source region Nothing
4747 (
4848 D.reflow $
4949 "Nothing from the `" <> Name.toChars moduleName <> "` module is used in this file."
@@ -54,7 +54,7 @@ toReport localizer source warning =
5454 UnusedVariable region context name ->
5555 let title = defOrPat context "unused definition" "unused variable" in
5656 Report.Report title region [] $
57− Report.toCodeSnippet source region Nothing
57+ Code.toSnippet source region Nothing
5858 (
5959 D.reflow $
6060 "You are not using `" <> Name.toChars name <> "` anywhere."
@@ -76,7 +76,7 @@ toReport localizer source warning =
7676
7777 MissingTypeAnnotation region name inferredType ->
7878 Report.Report "missing type annotation" region [] $
79− Report.toCodeSnippet source region Nothing
79+ Code.toSnippet source region Nothing
8080 (
8181 D.reflow $
8282 case Type.deepDealias inferredType of