Skip to content

Commit 06b68c0

Browse files
committed
Merge branch 'codex/extract-dokick-optimization' into codex/hls-graph-runtime-engine
2 parents 027d588 + 089a781 commit 06b68c0

3 files changed

Lines changed: 27 additions & 6 deletions

File tree

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

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ module Development.IDE.Core.OfInterest(
1515
kick, FileOfInterestStatus(..),
1616
OfInterestVar(..),
1717
scheduleGarbageCollection,
18-
Log(..)
18+
Log(..), doKick
1919
) where
2020

2121
import Control.Concurrent.Strict
@@ -39,7 +39,7 @@ import Development.IDE.Plugin.Completions.Types
3939
import Development.IDE.Types.Exports
4040
import Development.IDE.Types.Location
4141
import Development.IDE.Types.Options (IdeTesting (..))
42-
import Development.IDE.Types.Shake (toKey)
42+
import Development.IDE.Types.Shake (toKey, toNoFileKey)
4343
import GHC.TypeLits (KnownSymbol)
4444
import Ide.Logger (Pretty (pretty),
4545
Priority (..),
@@ -66,6 +66,10 @@ ofInterestRules :: Recorder (WithPriority Log) -> Rules ()
6666
ofInterestRules recorder = do
6767
addIdeGlobal . OfInterestVar =<< liftIO (newVar HashMap.empty)
6868
addIdeGlobal . GarbageCollectVar =<< liftIO (newVar False)
69+
-- A no-file rule to perform the global kick action
70+
defineEarlyCutOffNoFile (cmapWithPrio LogShake recorder) $ \Kick -> do
71+
kick
72+
pure ("", ())
6973
defineEarlyCutoff (cmapWithPrio LogShake recorder) $ RuleNoDiagnostics $ \IsFileOfInterest f -> do
7074
alwaysRerun
7175
filesOfInterest <- getFilesOfInterestUntracked
@@ -113,7 +117,7 @@ addFileOfInterest state f v = do
113117
then do
114118
logWith (ideLogger state) Debug $
115119
LogSetFilesOfInterest (HashMap.toList files)
116-
return [toKey IsFileOfInterest f]
120+
return [toKey IsFileOfInterest f, toNoFileKey Kick]
117121
else return []
118122

119123
deleteFileOfInterest :: IdeState -> NormalizedFilePath -> IO [Key]
@@ -122,12 +126,21 @@ deleteFileOfInterest state f = do
122126
files <- modifyVar' var $ HashMap.delete f
123127
logWith (ideLogger state) Debug $
124128
LogSetFilesOfInterest (HashMap.toList files)
125-
return [toKey IsFileOfInterest f]
129+
return [toKey IsFileOfInterest f, toNoFileKey Kick]
126130
scheduleGarbageCollection :: IdeState -> IO ()
127131
scheduleGarbageCollection state = do
128132
GarbageCollectVar var <- getIdeGlobalState state
129133
writeVar var True
130134

135+
doKick :: Action ()
136+
doKick = do
137+
ShakeExtras{ideTesting = IdeTesting testing} <- getShakeExtras
138+
-- only kick always if testing, otherwise we rely on the kick rule
139+
if testing
140+
then kick
141+
else void $ useNoFile Kick
142+
143+
131144
-- | Typecheck all the files of interest.
132145
-- Could be improved
133146
kick :: Action ()

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -518,6 +518,14 @@ data IsFileOfInterest = IsFileOfInterest
518518
instance Hashable IsFileOfInterest
519519
instance NFData IsFileOfInterest
520520

521+
-- | A no-file rule that triggers the IDE "kick" action
522+
data Kick = Kick
523+
deriving (Eq, Show, Generic)
524+
instance Hashable Kick
525+
instance NFData Kick
526+
527+
type instance RuleResult Kick = ()
528+
521529
data GetModSummaryWithoutTimestamps = GetModSummaryWithoutTimestamps
522530
deriving (Eq, Show, Generic)
523531
instance Hashable GetModSummaryWithoutTimestamps

ghcide/src/Development/IDE/Main.hs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ import Development.IDE.Core.IdeConfiguration (IdeConfiguration (..)
4040
modifyClientSettings,
4141
registerIdeConfiguration)
4242
import Development.IDE.Core.OfInterest (FileOfInterestStatus (OnDisk),
43-
kick,
43+
doKick,
4444
setFilesOfInterest)
4545
import Development.IDE.Core.Rules (mainRule)
4646
import qualified Development.IDE.Core.Rules as Rules
@@ -304,7 +304,7 @@ defaultMain recorder Arguments{..} = withHeapStats (cmapWithPrio LogHeapStats re
304304
argsParseConfig = getConfigFromNotification argsHlsPlugins
305305
rules = do
306306
argsRules
307-
unless argsDisableKick $ action kick
307+
unless argsDisableKick $ action $ doKick
308308
pluginRules plugins
309309
-- install the main and ghcide-plugin rules
310310
-- install the kick action, which triggers a typecheck on every

0 commit comments

Comments
 (0)