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
@@ -125,22 +123,9 @@ data ShowDiagnostic
125
123
instance NFData ShowDiagnostic where
126
124
rnf = rwhnf
127
125
128
- -- | Human readable diagnostics for a specific file.
129
- --
130
- -- This type packages a pretty printed, human readable error message
131
- -- along with the related source location so that we can display the error
132
- -- on either the console or in the IDE at the right source location.
133
- --
134
- data FileDiagnostic = FileDiagnostic
135
- { fdFilePath :: NormalizedFilePath
136
- , fdShouldShowDiagnostic :: ShowDiagnostic
137
- , fdLspDiagnostic :: Diagnostic
138
- , fdStructuredMessage :: StructuredMessage
139
- }
140
- deriving (Eq , Ord , Show , Generic )
141
-
142
- instance NFData FileDiagnostic
143
-
126
+ -- | A Maybe-like wrapper for a GhcMessage that doesn't try to compare, show, or
127
+ -- force the GhcMessage inside, so that we can derive Show, Eq, Ord, NFData on
128
+ -- FileDiagnostic
144
129
data StructuredMessage
145
130
= NoStructuredMessage
146
131
| SomeStructuredMessage (MsgEnvelope GhcMessage )
@@ -165,9 +150,25 @@ instance NFData StructuredMessage where
165
150
rnf NoStructuredMessage = ()
166
151
rnf SomeStructuredMessage {} = ()
167
152
168
- modifyFdLspDiagnostic :: (Diagnostic -> Diagnostic ) -> FileDiagnostic -> FileDiagnostic
169
- modifyFdLspDiagnostic f diag =
170
- diag { fdLspDiagnostic = f (fdLspDiagnostic diag) }
153
+ -- | Human readable diagnostics for a specific file.
154
+ --
155
+ -- This type packages a pretty printed, human readable error message
156
+ -- along with the related source location so that we can display the error
157
+ -- on either the console or in the IDE at the right source location.
158
+ --
159
+ data FileDiagnostic = FileDiagnostic
160
+ { fdFilePath :: NormalizedFilePath
161
+ , fdShouldShowDiagnostic :: ShowDiagnostic
162
+ , fdLspDiagnostic :: Diagnostic
163
+ , fdStructuredMessage :: StructuredMessage
164
+ }
165
+ deriving (Eq , Ord , Show , Generic )
166
+
167
+ instance NFData FileDiagnostic
168
+
169
+ makeLensesWith
170
+ (lensRules & lensField .~ mappingNamer (pure . (++ " L" )))
171
+ ''FileDiagnostic
171
172
172
173
prettyRange :: Range -> Doc Terminal. AnsiStyle
173
174
prettyRange Range {.. } = f _start <> " -" <> f _end
0 commit comments