Skip to content

Commit d7b65bb

Browse files
committed
HasNoDiagnostics
1 parent 6fab02b commit d7b65bb

File tree

6 files changed

+34
-2
lines changed

6 files changed

+34
-2
lines changed

ghcide/src/Development/IDE/Core/OfInterest.hs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ newtype OfInterestVar = OfInterestVar (Var (HashMap NormalizedFilePath FileOfInt
4444
instance IsIdeGlobal OfInterestVar
4545

4646
type instance RuleResult GetFilesOfInterest = HashMap NormalizedFilePath FileOfInterestStatus
47+
instance HasNoDiagnostics GetFilesOfInterest
4748

4849
data GetFilesOfInterest = GetFilesOfInterest
4950
deriving (Eq, Show, Typeable, Generic)

ghcide/src/Development/IDE/Core/RuleTypes.hs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,16 @@ import GHC.Serialized (Serialized)
4949
import Language.LSP.Types (NormalizedFilePath)
5050
import TcRnMonad (TcGblEnv)
5151

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+
5262
data LinkableType = ObjectLinkable | BCOLinkable
5363
deriving (Eq,Ord,Show, Generic)
5464
instance Hashable LinkableType
@@ -69,19 +79,23 @@ type instance RuleResult GetParsedModuleWithComments = ParsedModule
6979
-- This rule will succeed even if there is an error, e.g., a module could not be located,
7080
-- a module could not be parsed or an import cycle.
7181
type instance RuleResult GetDependencyInformation = DependencyInformation
82+
instance HasNoDiagnostics GetDependencyInformation
7283

7384
-- | Transitive module and pkg dependencies based on the information produced by GetDependencyInformation.
7485
-- This rule is also responsible for calling ReportImportCycles for each file in the transitive closure.
7586
type instance RuleResult GetDependencies = TransitiveDependencies
87+
instance HasNoDiagnostics GetDependencies
7688

7789
type instance RuleResult GetModuleGraph = DependencyInformation
90+
instance HasNoDiagnostics GetModuleGraph -- 'defineNoFile' rules have no diagnostics
7891

7992
data GetKnownTargets = GetKnownTargets
8093
deriving (Show, Generic, Eq, Ord)
8194
instance Hashable GetKnownTargets
8295
instance NFData GetKnownTargets
8396
instance Binary GetKnownTargets
8497
type instance RuleResult GetKnownTargets = KnownTargets
98+
instance HasNoDiagnostics GetKnownTargets
8599

86100
-- | Convert to Core, requires TypeCheck*
87101
type instance RuleResult GenerateCore = ModGuts
@@ -99,6 +113,7 @@ instance NFData GetImportMap
99113
instance Binary GetImportMap
100114

101115
type instance RuleResult GetImportMap = ImportMap
116+
instance HasNoDiagnostics GetImportMap
102117
newtype ImportMap = ImportMap
103118
{ importMap :: M.Map ModuleName NormalizedFilePath -- ^ Where are the modules imported by this file located?
104119
} deriving stock Show
@@ -212,6 +227,7 @@ type instance RuleResult GetHieAst = HieAstResult
212227

213228
-- | A IntervalMap telling us what is in scope at each point
214229
type instance RuleResult GetBindings = Bindings
230+
instance HasNoDiagnostics GetBindings
215231

216232
data DocAndKindMap = DKMap {getDocMap :: !DocMap, getKindMap :: !KindMap}
217233
instance NFData DocAndKindMap where
@@ -221,12 +237,14 @@ instance Show DocAndKindMap where
221237
show = const "docmap"
222238

223239
type instance RuleResult GetDocMap = DocAndKindMap
240+
instance HasNoDiagnostics GetDocMap
224241

225242
-- | A GHC session that we reuse.
226243
type instance RuleResult GhcSession = HscEnvEq
227244

228245
-- | A GHC session preloaded with all the dependencies
229246
type instance RuleResult GhcSessionDeps = HscEnvEq
247+
instance HasNoDiagnostics GhcSessionDeps
230248

231249
-- | Resolve the imports in a module to the file path of a module in the same package
232250
type instance RuleResult GetLocatedImports = [(Located ModuleName, Maybe ArtifactsLocation)]
@@ -243,13 +261,15 @@ type instance RuleResult GetModIfaceFromDisk = HiFileResult
243261
-- | GetModIfaceFromDisk and index the `.hie` file into the database.
244262
-- This is an internal rule, use 'GetModIface' instead.
245263
type instance RuleResult GetModIfaceFromDiskAndIndex = HiFileResult
264+
instance HasNoDiagnostics GetModIfaceFromDiskAndIndex
246265

247266
-- | Get a module interface details, either from an interface file or a typechecked module
248267
type instance RuleResult GetModIface = HiFileResult
249268

250269
-- | Get a module interface details, without the Linkable
251270
-- For better early cuttoff
252271
type instance RuleResult GetModIfaceWithoutLinkable = HiFileResult
272+
instance HasNoDiagnostics GetModIfaceWithoutLinkable
253273

254274
-- | Get the contents of a file, either dirty (if the buffer is modified) or Nothing to mean use from disk.
255275
type instance RuleResult GetFileContents = (FileVersion, Maybe Text)
@@ -279,6 +299,8 @@ pattern GetModificationTime = GetModificationTime_ {missingFileDiagnostics=True}
279299

280300
-- | Get the modification time of a file.
281301
type instance RuleResult GetModificationTime = FileVersion
302+
instance HasNoDiagnostics GetModificationTime where
303+
hasDiagnostics GetModificationTime_{..} = missingFileDiagnostics
282304

283305
data FileVersion
284306
= VFSVersion !Int
@@ -335,6 +357,7 @@ type instance RuleResult GetModSummary = ModSummaryResult
335357

336358
-- | Generate a ModSummary with the timestamps and preprocessed content elided, for more successful early cutoff
337359
type instance RuleResult GetModSummaryWithoutTimestamps = ModSummaryResult
360+
instance HasNoDiagnostics GetModSummaryWithoutTimestamps
338361

339362
data GetParsedModule = GetParsedModule
340363
deriving (Eq, Show, Typeable, Generic)

ghcide/src/Development/IDE/Core/Rules.hs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1133,3 +1133,4 @@ instance NFData IsHiFileStable
11331133
instance Binary IsHiFileStable
11341134

11351135
type instance RuleResult IsHiFileStable = SourceModified
1136+
instance HasNoDiagnostics IsHiFileStable

ghcide/src/Development/IDE/Core/Shake.hs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
-- * The 'Values' type stores a map of keys to values. These values are
2323
-- always stored as real Haskell values, whereas Shake serialises all 'A' values
2424
-- between runs. To deserialise a Shake value, we just consult Values.
25+
{-# LANGUAGE FlexibleInstances #-}
2526
module Development.IDE.Core.Shake(
2627
IdeState, shakeExtras,
2728
ShakeExtras(..), getShakeExtras, getShakeExtrasRules,
@@ -369,6 +370,7 @@ mappingForVersion allMappings file ver =
369370
type IdeRule k v =
370371
( Shake.RuleResult k ~ v
371372
, Shake.ShakeValue k
373+
, HasNoDiagnostics k
372374
, Show v
373375
, Typeable v
374376
, NFData v
@@ -921,7 +923,8 @@ defineEarlyCutoff op = addBuiltinRule noLint noIdentity $ \(Q (key, file)) (old
921923
-- No changes in the dependencies and we have
922924
-- an existing result.
923925
Just (v, diags) -> do
924-
updateFileDiagnostics file (Key key) extras $ map (\(_,y,z) -> (y,z)) $ Vector.toList diags
926+
when (hasDiagnostics key) $
927+
updateFileDiagnostics file (Key key) extras $ map (\(_,y,z) -> (y,z)) $ Vector.toList diags
925928
return $ Just $ RunResult ChangedNothing old $ A v
926929
_ -> return Nothing
927930
_ -> return Nothing
@@ -946,7 +949,8 @@ defineEarlyCutoff op = addBuiltinRule noLint noIdentity $ \(Q (key, file)) (old
946949
(toShakeValue ShakeResult bs, Failed b)
947950
Just v -> pure (maybe ShakeNoCutoff ShakeResult bs, Succeeded (vfsVersion =<< modTime) v)
948951
liftIO $ setValues state key file res (Vector.fromList diags)
949-
updateFileDiagnostics file (Key key) extras $ map (\(_,y,z) -> (y,z)) diags
952+
when (hasDiagnostics key) $
953+
updateFileDiagnostics file (Key key) extras $ map (\(_,y,z) -> (y,z)) diags
950954
let eq = case (bs, fmap decodeShakeValue old) of
951955
(ShakeResult a, Just (ShakeResult b)) -> a == b
952956
(ShakeStale a, Just (ShakeStale b)) -> a == b

ghcide/src/Development/IDE/GHC/ExactPrint.hs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ instance Hashable GetAnnotatedParsedSource
8383
instance NFData GetAnnotatedParsedSource
8484
instance Binary GetAnnotatedParsedSource
8585
type instance RuleResult GetAnnotatedParsedSource = Annotated ParsedSource
86+
instance HasNoDiagnostics GetAnnotatedParsedSource
8687

8788
-- | Get the latest version of the annotated parse source with comments.
8889
getAnnotatedParsedSourceRule :: Rules ()

ghcide/src/Development/IDE/Plugin/Completions.hs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,8 @@ dropListFromImportDecl iDecl = let
9393
-- | Produce completions info for a file
9494
type instance RuleResult LocalCompletions = CachedCompletions
9595
type instance RuleResult NonLocalCompletions = CachedCompletions
96+
instance HasNoDiagnostics LocalCompletions
97+
instance HasNoDiagnostics NonLocalCompletions
9698

9799
data LocalCompletions = LocalCompletions
98100
deriving (Eq, Show, Typeable, Generic)

0 commit comments

Comments
 (0)