1{-# OPTIONS_GHC -Wall #-}
2{-# LANGUAGE OverloadedStrings #-}
3module Reporting.Warning
11import Data.Monoid ((<>))
12import qualified Data.Name as Name
14import qualified AST.Canonical as Can
15import qualified AST.Utils.Type as Type
16import qualified Reporting.Annotation as A
17import qualified Reporting.Doc as D
18import qualified Reporting.Report as Report
19import qualified Reporting.Render.Code as Code
20import qualified Reporting.Render.Type as RT
21import qualified Reporting.Render.Type.Localizer as L
25-- ALL POSSIBLE WARNINGS
29 = UnusedImport A.Region Name.Name
30 | UnusedVariable A.Region Context Name.Name
31 | MissingTypeAnnotation A.Region Name.Name Can.Type
34data Context = Def | Pattern
41toReport :: L.Localizer -> Code.Source -> Warning -> Report.Report
42toReport localizer source warning =
44 UnusedImport region moduleName ->
45 Report.Report "unused import" region [] $
46 Code.toSnippet source region Nothing
49 "Nothing from the `" <> Name.toChars moduleName <> "` module is used in this file."
51 "I recommend removing unused imports."
54 UnusedVariable region context name ->
55 let title = defOrPat context "unused definition" "unused variable" in
56 Report.Report title region [] $
57 Code.toSnippet source region Nothing
60 "You are not using `" <> Name.toChars name <> "` anywhere."
64 "Is there a typo? Maybe you intended to use `" <> Name.toChars name
65 <> "` somewhere but typed another name instead?"
68 ( "If you are sure there is no typo, remove the definition.\
69 \ This way future readers will not have to wonder why it is there!"
71 ( "If you are sure there is no typo, replace `" <> Name.toChars name
72 <> "` with _ so future readers will not have to wonder why it is there!"
77 MissingTypeAnnotation region name inferredType ->
78 Report.Report "missing type annotation" region [] $
79 Code.toSnippet source region Nothing
82 case Type.deepDealias inferredType of
84 "The `" <> Name.toChars name <> "` function has no type annotation."
87 "The `" <> Name.toChars name <> "` definition has no type annotation."
90 [ "I inferred the type annotation myself though! You can copy it into your code:"
91 , D.green $ D.hang 4 $ D.sep $
92 [ D.fromName name <> " :"
93 , RT.canToDoc localizer RT.None inferredType
99defOrPat :: Context -> a -> a -> a
100defOrPat context def pat =
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