@@ -174,7 +174,7 @@ import qualified StmContainers.Map as STM
174174import System.FilePath hiding (makeRelative )
175175import System.IO.Unsafe (unsafePerformIO )
176176import System.Time.Extra
177-
177+ import qualified Prettyprinter as Pretty
178178-- See Note [Guidelines For Using CPP In GHCIDE Import Statements]
179179
180180#if !MIN_VERSION_ghc(9,3,0)
@@ -193,6 +193,12 @@ data Log
193193 | LogDiagsDiffButNoLspEnv ! [FileDiagnostic ]
194194 | LogDefineEarlyCutoffRuleNoDiagHasDiag ! FileDiagnostic
195195 | LogDefineEarlyCutoffRuleCustomNewnessHasDiag ! FileDiagnostic
196+ | LogCancelledAction ! T. Text
197+ | LogSessionInitialised
198+ | LogLookupPersistentKey ! T. Text
199+ | LogShakeGarbageCollection ! T. Text ! Int ! Seconds
200+ -- * OfInterest Log messages
201+ | LogSetFilesOfInterest ! [(NormalizedFilePath , FileOfInterestStatus )]
196202 deriving Show
197203
198204instance Pretty Log where
@@ -226,6 +232,16 @@ instance Pretty Log where
226232 LogDefineEarlyCutoffRuleCustomNewnessHasDiag fileDiagnostic ->
227233 " defineEarlyCutoff RuleWithCustomNewnessCheck - file diagnostic:"
228234 <+> pretty (showDiagnosticsColored [fileDiagnostic])
235+ LogCancelledAction action ->
236+ pretty action <+> " was cancelled"
237+ LogSessionInitialised -> " Shake session initialized"
238+ LogLookupPersistentKey key ->
239+ " LOOKUP PERSISTENT FOR:" <+> pretty key
240+ LogShakeGarbageCollection label number duration ->
241+ pretty label <+> " of" <+> pretty number <+> " keys (took " <+> pretty (showDuration duration) <> " )"
242+ LogSetFilesOfInterest ofInterest ->
243+ " Set files of interst to" <> Pretty. line
244+ <> indent 4 (pretty $ fmap (first fromNormalizedFilePath) ofInterest)
229245
230246-- | We need to serialize writes to the database, so we send any function that
231247-- needs to write to the database over the channel, where it will be picked up by
@@ -256,7 +272,7 @@ data ShakeExtras = ShakeExtras
256272 { -- eventer :: LSP.FromServerMessage -> IO ()
257273 lspEnv :: Maybe (LSP. LanguageContextEnv Config )
258274 ,debouncer :: Debouncer NormalizedUri
259- ,logger :: Logger
275+ ,shakeRecorder :: Recorder ( WithPriority Log )
260276 ,idePlugins :: IdePlugins IdeState
261277 ,globals :: TVar (HMap. HashMap TypeRep Dynamic )
262278 -- ^ Registry of global state used by rules.
@@ -441,7 +457,7 @@ lastValueIO s@ShakeExtras{positionMapping,persistentKeys,state} k file = do
441457 | otherwise = do
442458 pmap <- readTVarIO persistentKeys
443459 mv <- runMaybeT $ do
444- liftIO $ Logger. logDebug (logger s) $ T. pack $ " LOOKUP PERSISTENT FOR: " ++ show k
460+ liftIO $ logWith (shakeRecorder s) Debug $ LogLookupPersistentKey ( T. pack $ show k)
445461 f <- MaybeT $ pure $ lookupKeyMap (newKey k) pmap
446462 (dv,del,ver) <- MaybeT $ runIdeAction " lastValueIO" s $ f file
447463 MaybeT $ pure $ (,del,ver) <$> fromDynamic dv
@@ -662,7 +678,7 @@ shakeOpen recorder lspEnv defaultConfig idePlugins logger debouncer
662678 dirtyKeys <- newTVarIO mempty
663679 -- Take one VFS snapshot at the start
664680 vfsVar <- newTVarIO =<< vfsSnapshot lspEnv
665- pure ShakeExtras {.. }
681+ pure ShakeExtras {shakeRecorder = recorder, .. }
666682 shakeDb <-
667683 shakeNewDatabase
668684 opts { shakeExtra = newShakeExtra shakeExtras }
@@ -709,7 +725,7 @@ shakeSessionInit recorder ide@IdeState{..} = do
709725 vfs <- vfsSnapshot (lspEnv shakeExtras)
710726 initSession <- newSession recorder shakeExtras (VFSModified vfs) shakeDb [] " shakeSessionInit"
711727 putMVar shakeSession initSession
712- logDebug (ideLogger ide) " Shake session initialized "
728+ logWith recorder Debug LogSessionInitialised
713729
714730shakeShut :: IdeState -> IO ()
715731shakeShut IdeState {.. } = do
@@ -777,7 +793,7 @@ shakeRestart recorder IdeState{..} vfs reason acts =
777793--
778794-- Appropriate for user actions other than edits.
779795shakeEnqueue :: ShakeExtras -> DelayedAction a -> IO (IO a )
780- shakeEnqueue ShakeExtras {actionQueue, logger } act = do
796+ shakeEnqueue ShakeExtras {actionQueue, shakeRecorder } act = do
781797 (b, dai) <- instantiateDelayedAction act
782798 atomicallyNamed " actionQueue - push" $ pushQueue dai actionQueue
783799 let wait' barrier =
@@ -786,7 +802,7 @@ shakeEnqueue ShakeExtras{actionQueue, logger} act = do
786802 fail $ " internal bug: forever blocked on MVar for " <>
787803 actionName act)
788804 , Handler (\ e@ AsyncCancelled -> do
789- logPriority logger Debug $ T. pack $ actionName act <> " was cancelled "
805+ logWith shakeRecorder Debug $ LogCancelledAction ( T. pack $ actionName act)
790806
791807 atomicallyNamed " actionQueue - abort" $ abortQueue dai actionQueue
792808 throw e)
@@ -910,13 +926,12 @@ garbageCollectDirtyKeysOlderThan maxAge checkParents = otTracedGarbageCollection
910926garbageCollectKeys :: String -> Int -> CheckParents -> [(Key , Int )] -> Action [Key ]
911927garbageCollectKeys label maxAge checkParents agedKeys = do
912928 start <- liftIO offsetTime
913- ShakeExtras {state, dirtyKeys, lspEnv, logger , ideTesting} <- getShakeExtras
929+ ShakeExtras {state, dirtyKeys, lspEnv, shakeRecorder , ideTesting} <- getShakeExtras
914930 (n:: Int , garbage ) <- liftIO $
915931 foldM (removeDirtyKey dirtyKeys state) (0 ,[] ) agedKeys
916932 t <- liftIO start
917933 when (n> 0 ) $ liftIO $ do
918- logDebug logger $ T. pack $
919- label <> " of " <> show n <> " keys (took " <> showDuration t <> " )"
934+ logWith shakeRecorder Debug $ LogShakeGarbageCollection (T. pack label) n t
920935 when (coerce ideTesting) $ liftIO $ mRunLspT lspEnv $
921936 LSP. sendNotification (SMethod_CustomMethod (Proxy @ " ghcide/GC" ))
922937 (toJSON $ mapMaybe (fmap showKey . fromKeyType) garbage)
@@ -1312,13 +1327,11 @@ newtype Priority = Priority Double
13121327setPriority :: Priority -> Action ()
13131328setPriority (Priority p) = reschedule p
13141329
1315- ideLogger :: IdeState -> Logger
1316- ideLogger IdeState {shakeExtras= ShakeExtras {logger }} = logger
1330+ ideLogger :: IdeState -> Recorder ( WithPriority Log )
1331+ ideLogger IdeState {shakeExtras= ShakeExtras {shakeRecorder }} = shakeRecorder
13171332
1318- actionLogger :: Action Logger
1319- actionLogger = do
1320- ShakeExtras {logger} <- getShakeExtras
1321- return logger
1333+ actionLogger :: Action (Recorder (WithPriority Log ))
1334+ actionLogger = shakeRecorder <$> getShakeExtras
13221335
13231336--------------------------------------------------------------------------------
13241337type STMDiagnosticStore = STM. Map NormalizedUri StoreItem
0 commit comments