2
2
-- SPDX-License-Identifier: Apache-2.0
3
3
4
4
{-# LANGUAGE DeriveGeneric #-}
5
+ {-# LANGUAGE TemplateHaskell #-}
5
6
{-# LANGUAGE CPP #-}
6
7
7
8
module Development.IDE.Types.Diagnostics (
8
9
LSP. Diagnostic (.. ),
9
10
ShowDiagnostic (.. ),
10
11
FileDiagnostic (.. ),
11
- fdFilePath ,
12
- fdShouldShowDiagnostic ,
13
- fdLspDiagnostic ,
14
- fdStructuredMessage ,
15
- modifyFdLspDiagnostic ,
12
+ fdLspDiagnosticL ,
16
13
StructuredMessage (.. ),
17
14
IdeResult ,
18
15
LSP. DiagnosticSeverity (.. ),
@@ -25,6 +22,7 @@ module Development.IDE.Types.Diagnostics (
25
22
IdeResultNoDiagnosticsEarlyCutoff ) where
26
23
27
24
import Control.DeepSeq
25
+ import Control.Lens
28
26
import Data.ByteString (ByteString )
29
27
import Data.Maybe as Maybe
30
28
import qualified Data.Text as T
@@ -119,22 +117,9 @@ data ShowDiagnostic
119
117
instance NFData ShowDiagnostic where
120
118
rnf = rwhnf
121
119
122
- -- | Human readable diagnostics for a specific file.
123
- --
124
- -- This type packages a pretty printed, human readable error message
125
- -- along with the related source location so that we can display the error
126
- -- on either the console or in the IDE at the right source location.
127
- --
128
- data FileDiagnostic = FileDiagnostic
129
- { fdFilePath :: NormalizedFilePath
130
- , fdShouldShowDiagnostic :: ShowDiagnostic
131
- , fdLspDiagnostic :: Diagnostic
132
- , fdStructuredMessage :: StructuredMessage
133
- }
134
- deriving (Eq , Ord , Show , Generic )
135
-
136
- instance NFData FileDiagnostic
137
-
120
+ -- | A Maybe-like wrapper for a GhcMessage that doesn't try to compare, show, or
121
+ -- force the GhcMessage inside, so that we can derive Show, Eq, Ord, NFData on
122
+ -- FileDiagnostic
138
123
data StructuredMessage
139
124
= NoStructuredMessage
140
125
| SomeStructuredMessage (MsgEnvelope GhcMessage )
@@ -159,9 +144,25 @@ instance NFData StructuredMessage where
159
144
rnf NoStructuredMessage = ()
160
145
rnf SomeStructuredMessage {} = ()
161
146
162
- modifyFdLspDiagnostic :: (Diagnostic -> Diagnostic ) -> FileDiagnostic -> FileDiagnostic
163
- modifyFdLspDiagnostic f diag =
164
- diag { fdLspDiagnostic = f (fdLspDiagnostic diag) }
147
+ -- | Human readable diagnostics for a specific file.
148
+ --
149
+ -- This type packages a pretty printed, human readable error message
150
+ -- along with the related source location so that we can display the error
151
+ -- on either the console or in the IDE at the right source location.
152
+ --
153
+ data FileDiagnostic = FileDiagnostic
154
+ { fdFilePath :: NormalizedFilePath
155
+ , fdShouldShowDiagnostic :: ShowDiagnostic
156
+ , fdLspDiagnostic :: Diagnostic
157
+ , fdStructuredMessage :: StructuredMessage
158
+ }
159
+ deriving (Eq , Ord , Show , Generic )
160
+
161
+ instance NFData FileDiagnostic
162
+
163
+ makeLensesWith
164
+ (lensRules & lensField .~ mappingNamer (pure . (++ " L" )))
165
+ ''FileDiagnostic
165
166
166
167
prettyRange :: Range -> Doc Terminal. AnsiStyle
167
168
prettyRange Range {.. } = f _start <> " -" <> f _end
0 commit comments