Skip to content

Commit bafb42a

Browse files
committed
Define RuleInput type instances
1 parent bcc18e8 commit bafb42a

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

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

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import Development.IDE.GHC.Compat.Util
2929
import Development.IDE.GHC.CoreFile
3030
import Development.IDE.GHC.Util
3131
import Development.IDE.Graph
32+
import Development.IDE.Graph.Internal.RuleInput (Input(ProjectHaskellFile, DependencyHaskellFile, NoFile), RuleInput)
3233
import Development.IDE.Import.DependencyInformation
3334
import Development.IDE.Types.HscEnvEq (HscEnvEq)
3435
import Development.IDE.Types.KnownTargets
@@ -65,28 +66,34 @@ encodeLinkableType (Just ObjectLinkable) = "2"
6566

6667
-- | The parse tree for the file using GetFileContents
6768
type instance RuleResult GetParsedModule = ParsedModule
69+
type instance RuleInput GetParsedModule = '[ProjectHaskellFile, DependencyHaskellFile]
6870

6971
-- | The parse tree for the file using GetFileContents,
7072
-- all comments included using Opt_KeepRawTokenStream
7173
type instance RuleResult GetParsedModuleWithComments = ParsedModule
74+
type instance RuleInput GetParsedModuleWithComments = '[ProjectHaskellFile, DependencyHaskellFile]
7275

7376
type instance RuleResult GetModuleGraph = DependencyInformation
77+
type instance RuleInput GetModuleGraph = '[ProjectHaskellFile]
7478

7579
data GetKnownTargets = GetKnownTargets
7680
deriving (Show, Generic, Eq, Ord)
7781
instance Hashable GetKnownTargets
7882
instance NFData GetKnownTargets
7983
type instance RuleResult GetKnownTargets = KnownTargets
84+
type instance RuleInput GetKnownTargets = '[NoFile]
8085

8186
-- | Convert to Core, requires TypeCheck*
8287
type instance RuleResult GenerateCore = ModGuts
88+
type instance RuleInput GenerateCore = '[ProjectHaskellFile]
8389

8490
data GenerateCore = GenerateCore
8591
deriving (Eq, Show, Typeable, Generic)
8692
instance Hashable GenerateCore
8793
instance NFData GenerateCore
8894

8995
type instance RuleResult GetLinkable = LinkableResult
96+
type instance RuleInput GetLinkable = '[ProjectHaskellFile]
9097

9198
data LinkableResult
9299
= LinkableResult
@@ -112,6 +119,7 @@ instance Hashable GetImportMap
112119
instance NFData GetImportMap
113120

114121
type instance RuleResult GetImportMap = ImportMap
122+
type instance RuleInput GetImportMap = '[ProjectHaskellFile]
115123
newtype ImportMap = ImportMap
116124
{ importMap :: M.Map ModuleName NormalizedFilePath -- ^ Where are the modules imported by this file located?
117125
} deriving stock Show
@@ -232,12 +240,15 @@ instance Show HieAstResult where
232240

233241
-- | The type checked version of this file, requires TypeCheck+
234242
type instance RuleResult TypeCheck = TcModuleResult
243+
type instance RuleInput TypeCheck = '[ProjectHaskellFile]
235244

236245
-- | The uncompressed HieAST
237246
type instance RuleResult GetHieAst = HieAstResult
247+
type instance RuleInput GetHieAst = '[ProjectHaskellFile, DependencyHaskellFile]
238248

239249
-- | A IntervalMap telling us what is in scope at each point
240250
type instance RuleResult GetBindings = Bindings
251+
type instance RuleInput GetBindings = '[ProjectHaskellFile]
241252

242253
data DocAndTyThingMap = DKMap {getDocMap :: !DocMap, getTyThingMap :: !TyThingMap}
243254
instance NFData DocAndTyThingMap where
@@ -247,39 +258,50 @@ instance Show DocAndTyThingMap where
247258
show = const "docmap"
248259

249260
type instance RuleResult GetDocMap = DocAndTyThingMap
261+
type instance RuleInput GetDocMap = '[ProjectHaskellFile]
250262

251263
-- | A GHC session that we reuse.
252264
type instance RuleResult GhcSession = HscEnvEq
265+
type instance RuleInput GhcSession = '[ProjectHaskellFile]
253266

254267
-- | A GHC session preloaded with all the dependencies
255268
-- This rule is also responsible for calling ReportImportCycles for the direct dependencies
256269
type instance RuleResult GhcSessionDeps = HscEnvEq
270+
type instance RuleInput GhcSessionDeps = '[ProjectHaskellFile]
257271

258272
-- | Resolve the imports in a module to the file path of a module in the same package
259273
type instance RuleResult GetLocatedImports = [(Located ModuleName, Maybe ArtifactsLocation)]
274+
type instance RuleInput GetLocatedImports = '[ProjectHaskellFile]
260275

261276
-- | This rule is used to report import cycles. It depends on GetModuleGraph.
262277
-- We cannot report the cycles directly from GetModuleGraph since
263278
-- we can only report diagnostics for the current file.
264279
type instance RuleResult ReportImportCycles = ()
280+
type instance RuleInput ReportImportCycles = '[ProjectHaskellFile]
265281

266282
-- | Read the module interface file from disk. Throws an error for VFS files.
267283
-- This is an internal rule, use 'GetModIface' instead.
268284
type instance RuleResult GetModIfaceFromDisk = HiFileResult
285+
type instance RuleInput GetModIfaceFromDisk = '[ProjectHaskellFile]
269286

270287
-- | GetModIfaceFromDisk and index the `.hie` file into the database.
271288
-- This is an internal rule, use 'GetModIface' instead.
272289
type instance RuleResult GetModIfaceFromDiskAndIndex = HiFileResult
290+
type instance RuleInput GetModIfaceFromDiskAndIndex = '[ProjectHaskellFile]
273291

274292
-- | Get a module interface details, either from an interface file or a typechecked module
275293
type instance RuleResult GetModIface = HiFileResult
294+
type instance RuleInput GetModIface = '[ProjectHaskellFile, DependencyHaskellFile]
276295

277296
-- | Get the contents of a file, either dirty (if the buffer is modified) or Nothing to mean use from disk.
278297
type instance RuleResult GetFileContents = (FileVersion, Maybe Text)
298+
type instance RuleInput GetFileContents = '[ProjectHaskellFile, DependencyHaskellFile]
279299

280300
type instance RuleResult GetFileExists = Bool
301+
type instance RuleInput GetFileExists = '[ProjectHaskellFile, DependencyHaskellFile]
281302

282303
type instance RuleResult AddWatchedFile = Bool
304+
type instance RuleInput AddWatchedFile = '[ProjectHaskellFile]
283305

284306

285307
-- The Shake key type for getModificationTime queries
@@ -309,6 +331,7 @@ pattern GetModificationTime = GetModificationTime_ {missingFileDiagnostics=True}
309331

310332
-- | Get the modification time of a file.
311333
type instance RuleResult GetModificationTime = FileVersion
334+
type instance RuleInput GetModificationTime = '[ProjectHaskellFile, DependencyHaskellFile]
312335

313336
-- | Either the mtime from disk or an LSP version
314337
-- LSP versions always compare as greater than on disk versions
@@ -351,6 +374,7 @@ instance Hashable IsFileOfInterestResult
351374
instance NFData IsFileOfInterestResult
352375

353376
type instance RuleResult IsFileOfInterest = IsFileOfInterestResult
377+
type instance RuleInput IsFileOfInterest = '[ProjectHaskellFile, DependencyHaskellFile]
354378

355379
data ModSummaryResult = ModSummaryResult
356380
{ msrModSummary :: !ModSummary
@@ -373,9 +397,11 @@ instance NFData ModSummaryResult where
373397
-- | Generate a ModSummary that has enough information to be used to get .hi and .hie files.
374398
-- without needing to parse the entire source
375399
type instance RuleResult GetModSummary = ModSummaryResult
400+
type instance RuleInput GetModSummary = '[ProjectHaskellFile, DependencyHaskellFile]
376401

377402
-- | Generate a ModSummary with the timestamps and preprocessed content elided, for more successful early cutoff
378403
type instance RuleResult GetModSummaryWithoutTimestamps = ModSummaryResult
404+
type instance RuleInput GetModSummaryWithoutTimestamps = '[ProjectHaskellFile, DependencyHaskellFile]
379405

380406
data GetParsedModule = GetParsedModule
381407
deriving (Eq, Show, Typeable, Generic)
@@ -394,6 +420,7 @@ instance NFData GetLocatedImports
394420

395421
-- | Does this module need to be compiled?
396422
type instance RuleResult NeedsCompilation = Maybe LinkableType
423+
type instance RuleInput NeedsCompilation = '[ProjectHaskellFile]
397424

398425
data NeedsCompilation = NeedsCompilation
399426
deriving (Eq, Show, Typeable, Generic)
@@ -487,6 +514,7 @@ instance Hashable GetClientSettings
487514
instance NFData GetClientSettings
488515

489516
type instance RuleResult GetClientSettings = Hashed (Maybe Value)
517+
type instance RuleInput GetClientSettings = '[ProjectHaskellFile]
490518

491519
data AddWatchedFile = AddWatchedFile deriving (Eq, Show, Typeable, Generic)
492520
instance Hashable AddWatchedFile
@@ -497,6 +525,7 @@ instance NFData AddWatchedFile
497525
-- thread killed exception issues, so we lift it to a full rule.
498526
-- https://github.com/digital-asset/daml/pull/2808#issuecomment-529639547
499527
type instance RuleResult GhcSessionIO = IdeGhcSession
528+
type instance RuleInput GhcSessionIO = '[ProjectHaskellFile]
500529

501530
data IdeGhcSession = IdeGhcSession
502531
{ loadSessionFun :: FilePath -> IO (IdeResult HscEnvEq, [FilePath])

0 commit comments

Comments
 (0)