1
1
-- Retrieve the list of errors from the HaskellErrorIndex via its API
2
- {-# LANGUAGE CPP #-}
2
+ {-# LANGUAGE CPP #-}
3
3
4
4
module Development.IDE.Core.HaskellErrorIndex where
5
5
6
6
import Control.Exception (tryJust )
7
- import Data.Aeson (FromJSON (.. ), (.:) , withObject )
7
+ import Data.Aeson (FromJSON (.. ), withObject ,
8
+ (.:) )
8
9
import qualified Data.Map as M
9
10
import qualified Data.Text as T
10
11
import Development.IDE.Types.Diagnostics
11
- import GHC.Driver.Errors.Types ( GhcMessage
12
+ import GHC.Driver.Errors.Types (GhcMessage )
12
13
#if MIN_VERSION_ghc(9,6,1)
13
- , DiagnosticCode , diagnosticCode
14
+ import GHC.Types.Error ( diagnosticCode )
14
15
#endif
15
- )
16
- import Ide.Logger (Recorder , Pretty (.. ), WithPriority , logWith , Priority (.. ), vcat )
17
- import Language.LSP.Protocol.Types (Uri (.. ), CodeDescription (.. ))
18
- import Network.HTTP.Simple (HttpException , JSONException , getResponseBody , httpJSON )
16
+ import Ide.Logger (Pretty (.. ), Priority (.. ),
17
+ Recorder , WithPriority ,
18
+ logWith , vcat )
19
+ import Language.LSP.Protocol.Types (CodeDescription (.. ),
20
+ Uri (.. ))
21
+ import Network.HTTP.Simple (HttpException ,
22
+ JSONException ,
23
+ getResponseBody , httpJSON )
19
24
20
25
data Log
21
26
= LogHaskellErrorIndexInitialized
@@ -41,7 +46,7 @@ newtype HaskellErrorIndex = HaskellErrorIndex (M.Map T.Text HEIError)
41
46
deriving (Show , Eq , Ord )
42
47
43
48
data HEIError = HEIError
44
- { code :: T. Text
49
+ { code :: T. Text
45
50
, route :: T. Text
46
51
}
47
52
deriving (Show , Eq , Ord )
@@ -60,8 +65,8 @@ instance FromJSON HaskellErrorIndex where
60
65
parseJSON = fmap errorsToIndex <$> parseJSON
61
66
62
67
initHaskellErrorIndex :: Recorder (WithPriority Log ) -> IO (Maybe HaskellErrorIndex )
63
- initHaskellErrorIndex recorder = do
64
68
#if MIN_VERSION_ghc(9,6,1)
69
+ initHaskellErrorIndex recorder = do
65
70
res <- tryJust handleJSONError $ tryJust handleHttpError $ httpJSON " https://errors.haskell.org/api/errors.json"
66
71
case res of
67
72
Left jsonErr -> do
@@ -77,13 +82,13 @@ initHaskellErrorIndex recorder = do
77
82
handleHttpError :: HttpException -> Maybe HttpException
78
83
handleHttpError = Just
79
84
#else
80
- pure Nothing
85
+ initHaskellErrorIndex recorder = pure Nothing
81
86
#endif
82
87
83
88
heiGetError :: HaskellErrorIndex -> GhcMessage -> Maybe HEIError
84
89
heiGetError (HaskellErrorIndex index) msg
85
90
#if MIN_VERSION_ghc(9,6,1)
86
- | Just code <- diagnosticCode (errMsgDiagnostic msg)
91
+ | Just code <- diagnosticCode msg
87
92
= showGhcCode code `M.lookup` index
88
93
| otherwise
89
94
= Nothing
0 commit comments