@@ -22,7 +22,6 @@ import Data.HashMap.Strict (HashMap)
2222import qualified Data.HashMap.Strict as HashMap
2323import qualified Data.List.NonEmpty as NE
2424import Data.Maybe (mapMaybe )
25- import qualified Data.Text as T
2625import qualified Data.Text.Encoding as Encoding
2726import Data.Typeable
2827import Development.IDE as D
@@ -47,6 +46,7 @@ data Log
4746 | LogDocModified Uri
4847 | LogDocSaved Uri
4948 | LogDocClosed Uri
49+ | LogFOI (HashMap NormalizedFilePath FileOfInterestStatus )
5050 deriving Show
5151
5252instance Pretty Log where
@@ -62,6 +62,9 @@ instance Pretty Log where
6262 " Saved text document:" <+> pretty (getUri uri)
6363 LogDocClosed uri ->
6464 " Closed text document:" <+> pretty (getUri uri)
65+ LogFOI files ->
66+ " Set files of interest to:" <+> viaShow files
67+
6568
6669descriptor :: Recorder (WithPriority Log ) -> PluginId -> PluginDescriptor IdeState
6770descriptor recorder plId = (defaultCabalPluginDescriptor plId)
@@ -72,29 +75,29 @@ descriptor recorder plId = (defaultCabalPluginDescriptor plId)
7275 \ ide vfs _ (DidOpenTextDocumentParams TextDocumentItem {_uri,_version}) -> liftIO $ do
7376 whenUriFile _uri $ \ file -> do
7477 log' Debug $ LogDocOpened _uri
75- addFileOfInterest ide file Modified {firstOpen= True }
76- restartCabalShakeSession ide vfs file " (opened)"
78+ addFileOfInterest recorder ide file Modified {firstOpen= True }
79+ restartCabalShakeSession (shakeExtras ide) vfs file " (opened)"
7780
7881 , mkPluginNotificationHandler LSP. STextDocumentDidChange $
7982 \ ide vfs _ (DidChangeTextDocumentParams VersionedTextDocumentIdentifier {_uri} _) -> liftIO $ do
8083 whenUriFile _uri $ \ file -> do
8184 log' Debug $ LogDocModified _uri
82- addFileOfInterest ide file Modified {firstOpen= False }
83- restartCabalShakeSession ide vfs file " (changed)"
85+ addFileOfInterest recorder ide file Modified {firstOpen= False }
86+ restartCabalShakeSession (shakeExtras ide) vfs file " (changed)"
8487
8588 , mkPluginNotificationHandler LSP. STextDocumentDidSave $
8689 \ ide vfs _ (DidSaveTextDocumentParams TextDocumentIdentifier {_uri} _) -> liftIO $ do
8790 whenUriFile _uri $ \ file -> do
8891 log' Debug $ LogDocSaved _uri
89- addFileOfInterest ide file OnDisk
90- restartCabalShakeSession ide vfs file " (saved)"
92+ addFileOfInterest recorder ide file OnDisk
93+ restartCabalShakeSession (shakeExtras ide) vfs file " (saved)"
9194
9295 , mkPluginNotificationHandler LSP. STextDocumentDidClose $
9396 \ ide vfs _ (DidCloseTextDocumentParams TextDocumentIdentifier {_uri}) -> liftIO $ do
9497 whenUriFile _uri $ \ file -> do
9598 log' Debug $ LogDocClosed _uri
96- deleteFileOfInterest ide file
97- restartCabalShakeSession ide vfs file " (closed)"
99+ deleteFileOfInterest recorder ide file
100+ restartCabalShakeSession (shakeExtras ide) vfs file " (closed)"
98101 ]
99102 }
100103 where
@@ -106,10 +109,10 @@ descriptor recorder plId = (defaultCabalPluginDescriptor plId)
106109-- | Helper function to restart the shake session, specifically for modifying .cabal files.
107110-- No special logic, just group up a bunch of functions you need for the base
108111-- Notification Handlers.
109- restartCabalShakeSession :: IdeState -> VFS. VFS -> NormalizedFilePath -> String -> IO ()
110- restartCabalShakeSession ide vfs file actionMsg = do
111- join $ atomically $ Shake. recordDirtyKeys ( shakeExtras ide) GetModificationTime [file]
112- restartShakeSession ( shakeExtras ide) (VFSModified vfs) (fromNormalizedFilePath file ++ " " ++ actionMsg) []
112+ restartCabalShakeSession :: ShakeExtras -> VFS. VFS -> NormalizedFilePath -> String -> IO ()
113+ restartCabalShakeSession shakeExtras vfs file actionMsg = do
114+ join $ atomically $ Shake. recordDirtyKeys shakeExtras GetModificationTime [file]
115+ restartShakeSession shakeExtras (VFSModified vfs) (fromNormalizedFilePath file ++ " " ++ actionMsg) []
113116
114117-- ----------------------------------------------------------------
115118-- Plugin Rules
@@ -222,25 +225,28 @@ ofInterestRules recorder = do
222225 summarize (IsCabalFOI (Modified False )) = BS. singleton 2
223226 summarize (IsCabalFOI (Modified True )) = BS. singleton 3
224227
225- getCabalFilesOfInterestUntracked :: Action (HashMap NormalizedFilePath FileOfInterestStatus )
228+ getCabalFilesOfInterestUntracked :: Action (HashMap NormalizedFilePath FileOfInterestStatus )
226229getCabalFilesOfInterestUntracked = do
227230 OfInterestCabalVar var <- Shake. getIdeGlobalAction
228231 liftIO $ readVar var
229232
230- addFileOfInterest :: IdeState -> NormalizedFilePath -> FileOfInterestStatus -> IO ()
231- addFileOfInterest state f v = do
233+ addFileOfInterest :: Recorder ( WithPriority Log ) -> IdeState -> NormalizedFilePath -> FileOfInterestStatus -> IO ()
234+ addFileOfInterest recorder state f v = do
232235 OfInterestCabalVar var <- Shake. getIdeGlobalState state
233236 (prev, files) <- modifyVar var $ \ dict -> do
234237 let (prev, new) = HashMap. alterF (, Just v) f dict
235238 pure (new, (prev, new))
236239 when (prev /= Just v) $ do
237240 join $ atomically $ Shake. recordDirtyKeys (shakeExtras state) IsFileOfInterest [f]
238- logDebug (ideLogger state) $
239- " Set files of interest to: " <> T. pack (show files)
241+ log' Debug $ LogFOI files
242+ where
243+ log' = logWith recorder
240244
241- deleteFileOfInterest :: IdeState -> NormalizedFilePath -> IO ()
242- deleteFileOfInterest state f = do
245+ deleteFileOfInterest :: Recorder ( WithPriority Log ) -> IdeState -> NormalizedFilePath -> IO ()
246+ deleteFileOfInterest recorder state f = do
243247 OfInterestCabalVar var <- Shake. getIdeGlobalState state
244248 files <- modifyVar' var $ HashMap. delete f
245249 join $ atomically $ Shake. recordDirtyKeys (shakeExtras state) IsFileOfInterest [f]
246- logDebug (ideLogger state) $ " Set files of interest to: " <> T. pack (show files)
250+ log' Debug $ LogFOI files
251+ where
252+ log' = logWith recorder
0 commit comments