@@ -174,7 +174,7 @@ import qualified StmContainers.Map as STM
174
174
import System.FilePath hiding (makeRelative )
175
175
import System.IO.Unsafe (unsafePerformIO )
176
176
import System.Time.Extra
177
-
177
+ import qualified Prettyprinter as Pretty
178
178
-- See Note [Guidelines For Using CPP In GHCIDE Import Statements]
179
179
180
180
#if !MIN_VERSION_ghc(9,3,0)
@@ -193,6 +193,12 @@ data Log
193
193
| LogDiagsDiffButNoLspEnv ! [FileDiagnostic ]
194
194
| LogDefineEarlyCutoffRuleNoDiagHasDiag ! FileDiagnostic
195
195
| 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 )]
196
202
deriving Show
197
203
198
204
instance Pretty Log where
@@ -226,6 +232,16 @@ instance Pretty Log where
226
232
LogDefineEarlyCutoffRuleCustomNewnessHasDiag fileDiagnostic ->
227
233
" defineEarlyCutoff RuleWithCustomNewnessCheck - file diagnostic:"
228
234
<+> 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)
229
245
230
246
-- | We need to serialize writes to the database, so we send any function that
231
247
-- needs to write to the database over the channel, where it will be picked up by
@@ -256,7 +272,7 @@ data ShakeExtras = ShakeExtras
256
272
{ -- eventer :: LSP.FromServerMessage -> IO ()
257
273
lspEnv :: Maybe (LSP. LanguageContextEnv Config )
258
274
,debouncer :: Debouncer NormalizedUri
259
- ,logger :: Logger
275
+ ,shakeRecorder :: Recorder ( WithPriority Log )
260
276
,idePlugins :: IdePlugins IdeState
261
277
,globals :: TVar (HMap. HashMap TypeRep Dynamic )
262
278
-- ^ Registry of global state used by rules.
@@ -441,7 +457,7 @@ lastValueIO s@ShakeExtras{positionMapping,persistentKeys,state} k file = do
441
457
| otherwise = do
442
458
pmap <- readTVarIO persistentKeys
443
459
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)
445
461
f <- MaybeT $ pure $ lookupKeyMap (newKey k) pmap
446
462
(dv,del,ver) <- MaybeT $ runIdeAction " lastValueIO" s $ f file
447
463
MaybeT $ pure $ (,del,ver) <$> fromDynamic dv
@@ -662,7 +678,7 @@ shakeOpen recorder lspEnv defaultConfig idePlugins logger debouncer
662
678
dirtyKeys <- newTVarIO mempty
663
679
-- Take one VFS snapshot at the start
664
680
vfsVar <- newTVarIO =<< vfsSnapshot lspEnv
665
- pure ShakeExtras {.. }
681
+ pure ShakeExtras {shakeRecorder = recorder, .. }
666
682
shakeDb <-
667
683
shakeNewDatabase
668
684
opts { shakeExtra = newShakeExtra shakeExtras }
@@ -709,7 +725,7 @@ shakeSessionInit recorder ide@IdeState{..} = do
709
725
vfs <- vfsSnapshot (lspEnv shakeExtras)
710
726
initSession <- newSession recorder shakeExtras (VFSModified vfs) shakeDb [] " shakeSessionInit"
711
727
putMVar shakeSession initSession
712
- logDebug (ideLogger ide) " Shake session initialized "
728
+ logWith recorder Debug LogSessionInitialised
713
729
714
730
shakeShut :: IdeState -> IO ()
715
731
shakeShut IdeState {.. } = do
@@ -777,7 +793,7 @@ shakeRestart recorder IdeState{..} vfs reason acts =
777
793
--
778
794
-- Appropriate for user actions other than edits.
779
795
shakeEnqueue :: ShakeExtras -> DelayedAction a -> IO (IO a )
780
- shakeEnqueue ShakeExtras {actionQueue, logger } act = do
796
+ shakeEnqueue ShakeExtras {actionQueue, shakeRecorder } act = do
781
797
(b, dai) <- instantiateDelayedAction act
782
798
atomicallyNamed " actionQueue - push" $ pushQueue dai actionQueue
783
799
let wait' barrier =
@@ -786,7 +802,7 @@ shakeEnqueue ShakeExtras{actionQueue, logger} act = do
786
802
fail $ " internal bug: forever blocked on MVar for " <>
787
803
actionName act)
788
804
, Handler (\ e@ AsyncCancelled -> do
789
- logPriority logger Debug $ T. pack $ actionName act <> " was cancelled "
805
+ logWith shakeRecorder Debug $ LogCancelledAction ( T. pack $ actionName act)
790
806
791
807
atomicallyNamed " actionQueue - abort" $ abortQueue dai actionQueue
792
808
throw e)
@@ -910,13 +926,12 @@ garbageCollectDirtyKeysOlderThan maxAge checkParents = otTracedGarbageCollection
910
926
garbageCollectKeys :: String -> Int -> CheckParents -> [(Key , Int )] -> Action [Key ]
911
927
garbageCollectKeys label maxAge checkParents agedKeys = do
912
928
start <- liftIO offsetTime
913
- ShakeExtras {state, dirtyKeys, lspEnv, logger , ideTesting} <- getShakeExtras
929
+ ShakeExtras {state, dirtyKeys, lspEnv, shakeRecorder , ideTesting} <- getShakeExtras
914
930
(n:: Int , garbage ) <- liftIO $
915
931
foldM (removeDirtyKey dirtyKeys state) (0 ,[] ) agedKeys
916
932
t <- liftIO start
917
933
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
920
935
when (coerce ideTesting) $ liftIO $ mRunLspT lspEnv $
921
936
LSP. sendNotification (SMethod_CustomMethod (Proxy @ " ghcide/GC" ))
922
937
(toJSON $ mapMaybe (fmap showKey . fromKeyType) garbage)
@@ -1312,13 +1327,11 @@ newtype Priority = Priority Double
1312
1327
setPriority :: Priority -> Action ()
1313
1328
setPriority (Priority p) = reschedule p
1314
1329
1315
- ideLogger :: IdeState -> Logger
1316
- ideLogger IdeState {shakeExtras= ShakeExtras {logger }} = logger
1330
+ ideLogger :: IdeState -> Recorder ( WithPriority Log )
1331
+ ideLogger IdeState {shakeExtras= ShakeExtras {shakeRecorder }} = shakeRecorder
1317
1332
1318
- actionLogger :: Action Logger
1319
- actionLogger = do
1320
- ShakeExtras {logger} <- getShakeExtras
1321
- return logger
1333
+ actionLogger :: Action (Recorder (WithPriority Log ))
1334
+ actionLogger = shakeRecorder <$> getShakeExtras
1322
1335
1323
1336
--------------------------------------------------------------------------------
1324
1337
type STMDiagnosticStore = STM. Map NormalizedUri StoreItem
0 commit comments