@@ -49,6 +49,16 @@ import GHC.Serialized (Serialized)
49
49
import Language.LSP.Types (NormalizedFilePath )
50
50
import TcRnMonad (TcGblEnv )
51
51
52
+ -- | A class to signal when a rule will never produce diagnostics and thus
53
+ -- can be excluded from the diagnostic loop
54
+ class HasNoDiagnostics k where
55
+ hasDiagnostics :: k -> Bool
56
+ hasDiagnostics _ = False
57
+
58
+ -- | The default instance always returns "I have diagnostics"
59
+ instance {-# OVERLAPPABLE #-} HasNoDiagnostics a where
60
+ hasDiagnostics = const True
61
+
52
62
data LinkableType = ObjectLinkable | BCOLinkable
53
63
deriving (Eq ,Ord ,Show , Generic )
54
64
instance Hashable LinkableType
@@ -69,19 +79,23 @@ type instance RuleResult GetParsedModuleWithComments = ParsedModule
69
79
-- This rule will succeed even if there is an error, e.g., a module could not be located,
70
80
-- a module could not be parsed or an import cycle.
71
81
type instance RuleResult GetDependencyInformation = DependencyInformation
82
+ instance HasNoDiagnostics GetDependencyInformation
72
83
73
84
-- | Transitive module and pkg dependencies based on the information produced by GetDependencyInformation.
74
85
-- This rule is also responsible for calling ReportImportCycles for each file in the transitive closure.
75
86
type instance RuleResult GetDependencies = TransitiveDependencies
87
+ instance HasNoDiagnostics GetDependencies
76
88
77
89
type instance RuleResult GetModuleGraph = DependencyInformation
90
+ instance HasNoDiagnostics GetModuleGraph -- 'defineNoFile' rules have no diagnostics
78
91
79
92
data GetKnownTargets = GetKnownTargets
80
93
deriving (Show , Generic , Eq , Ord )
81
94
instance Hashable GetKnownTargets
82
95
instance NFData GetKnownTargets
83
96
instance Binary GetKnownTargets
84
97
type instance RuleResult GetKnownTargets = KnownTargets
98
+ instance HasNoDiagnostics GetKnownTargets
85
99
86
100
-- | Convert to Core, requires TypeCheck*
87
101
type instance RuleResult GenerateCore = ModGuts
@@ -99,6 +113,7 @@ instance NFData GetImportMap
99
113
instance Binary GetImportMap
100
114
101
115
type instance RuleResult GetImportMap = ImportMap
116
+ instance HasNoDiagnostics GetImportMap
102
117
newtype ImportMap = ImportMap
103
118
{ importMap :: M. Map ModuleName NormalizedFilePath -- ^ Where are the modules imported by this file located?
104
119
} deriving stock Show
@@ -212,6 +227,7 @@ type instance RuleResult GetHieAst = HieAstResult
212
227
213
228
-- | A IntervalMap telling us what is in scope at each point
214
229
type instance RuleResult GetBindings = Bindings
230
+ instance HasNoDiagnostics GetBindings
215
231
216
232
data DocAndKindMap = DKMap { getDocMap :: ! DocMap , getKindMap :: ! KindMap }
217
233
instance NFData DocAndKindMap where
@@ -221,12 +237,14 @@ instance Show DocAndKindMap where
221
237
show = const " docmap"
222
238
223
239
type instance RuleResult GetDocMap = DocAndKindMap
240
+ instance HasNoDiagnostics GetDocMap
224
241
225
242
-- | A GHC session that we reuse.
226
243
type instance RuleResult GhcSession = HscEnvEq
227
244
228
245
-- | A GHC session preloaded with all the dependencies
229
246
type instance RuleResult GhcSessionDeps = HscEnvEq
247
+ instance HasNoDiagnostics GhcSessionDeps
230
248
231
249
-- | Resolve the imports in a module to the file path of a module in the same package
232
250
type instance RuleResult GetLocatedImports = [(Located ModuleName , Maybe ArtifactsLocation )]
@@ -243,13 +261,15 @@ type instance RuleResult GetModIfaceFromDisk = HiFileResult
243
261
-- | GetModIfaceFromDisk and index the `.hie` file into the database.
244
262
-- This is an internal rule, use 'GetModIface' instead.
245
263
type instance RuleResult GetModIfaceFromDiskAndIndex = HiFileResult
264
+ instance HasNoDiagnostics GetModIfaceFromDiskAndIndex
246
265
247
266
-- | Get a module interface details, either from an interface file or a typechecked module
248
267
type instance RuleResult GetModIface = HiFileResult
249
268
250
269
-- | Get a module interface details, without the Linkable
251
270
-- For better early cuttoff
252
271
type instance RuleResult GetModIfaceWithoutLinkable = HiFileResult
272
+ instance HasNoDiagnostics GetModIfaceWithoutLinkable
253
273
254
274
-- | Get the contents of a file, either dirty (if the buffer is modified) or Nothing to mean use from disk.
255
275
type instance RuleResult GetFileContents = (FileVersion , Maybe Text )
@@ -279,6 +299,8 @@ pattern GetModificationTime = GetModificationTime_ {missingFileDiagnostics=True}
279
299
280
300
-- | Get the modification time of a file.
281
301
type instance RuleResult GetModificationTime = FileVersion
302
+ instance HasNoDiagnostics GetModificationTime where
303
+ hasDiagnostics GetModificationTime_ {.. } = missingFileDiagnostics
282
304
283
305
data FileVersion
284
306
= VFSVersion ! Int
@@ -335,6 +357,7 @@ type instance RuleResult GetModSummary = ModSummaryResult
335
357
336
358
-- | Generate a ModSummary with the timestamps and preprocessed content elided, for more successful early cutoff
337
359
type instance RuleResult GetModSummaryWithoutTimestamps = ModSummaryResult
360
+ instance HasNoDiagnostics GetModSummaryWithoutTimestamps
338
361
339
362
data GetParsedModule = GetParsedModule
340
363
deriving (Eq , Show , Typeable , Generic )
0 commit comments