@@ -22,7 +22,6 @@ import Data.HashMap.Strict (HashMap)
22
22
import qualified Data.HashMap.Strict as HashMap
23
23
import qualified Data.List.NonEmpty as NE
24
24
import Data.Maybe (mapMaybe )
25
- import qualified Data.Text as T
26
25
import qualified Data.Text.Encoding as Encoding
27
26
import Data.Typeable
28
27
import Development.IDE as D
@@ -47,6 +46,7 @@ data Log
47
46
| LogDocModified Uri
48
47
| LogDocSaved Uri
49
48
| LogDocClosed Uri
49
+ | LogFOI (HashMap NormalizedFilePath FileOfInterestStatus )
50
50
deriving Show
51
51
52
52
instance Pretty Log where
@@ -62,6 +62,9 @@ instance Pretty Log where
62
62
" Saved text document:" <+> pretty (getUri uri)
63
63
LogDocClosed uri ->
64
64
" Closed text document:" <+> pretty (getUri uri)
65
+ LogFOI files ->
66
+ " Set files of interest to:" <+> viaShow files
67
+
65
68
66
69
descriptor :: Recorder (WithPriority Log ) -> PluginId -> PluginDescriptor IdeState
67
70
descriptor recorder plId = (defaultCabalPluginDescriptor plId)
@@ -72,29 +75,29 @@ descriptor recorder plId = (defaultCabalPluginDescriptor plId)
72
75
\ ide vfs _ (DidOpenTextDocumentParams TextDocumentItem {_uri,_version}) -> liftIO $ do
73
76
whenUriFile _uri $ \ file -> do
74
77
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)"
77
80
78
81
, mkPluginNotificationHandler LSP. STextDocumentDidChange $
79
82
\ ide vfs _ (DidChangeTextDocumentParams VersionedTextDocumentIdentifier {_uri} _) -> liftIO $ do
80
83
whenUriFile _uri $ \ file -> do
81
84
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)"
84
87
85
88
, mkPluginNotificationHandler LSP. STextDocumentDidSave $
86
89
\ ide vfs _ (DidSaveTextDocumentParams TextDocumentIdentifier {_uri} _) -> liftIO $ do
87
90
whenUriFile _uri $ \ file -> do
88
91
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)"
91
94
92
95
, mkPluginNotificationHandler LSP. STextDocumentDidClose $
93
96
\ ide vfs _ (DidCloseTextDocumentParams TextDocumentIdentifier {_uri}) -> liftIO $ do
94
97
whenUriFile _uri $ \ file -> do
95
98
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)"
98
101
]
99
102
}
100
103
where
@@ -106,10 +109,10 @@ descriptor recorder plId = (defaultCabalPluginDescriptor plId)
106
109
-- | Helper function to restart the shake session, specifically for modifying .cabal files.
107
110
-- No special logic, just group up a bunch of functions you need for the base
108
111
-- 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) []
113
116
114
117
-- ----------------------------------------------------------------
115
118
-- Plugin Rules
@@ -222,25 +225,28 @@ ofInterestRules recorder = do
222
225
summarize (IsCabalFOI (Modified False )) = BS. singleton 2
223
226
summarize (IsCabalFOI (Modified True )) = BS. singleton 3
224
227
225
- getCabalFilesOfInterestUntracked :: Action (HashMap NormalizedFilePath FileOfInterestStatus )
228
+ getCabalFilesOfInterestUntracked :: Action (HashMap NormalizedFilePath FileOfInterestStatus )
226
229
getCabalFilesOfInterestUntracked = do
227
230
OfInterestCabalVar var <- Shake. getIdeGlobalAction
228
231
liftIO $ readVar var
229
232
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
232
235
OfInterestCabalVar var <- Shake. getIdeGlobalState state
233
236
(prev, files) <- modifyVar var $ \ dict -> do
234
237
let (prev, new) = HashMap. alterF (, Just v) f dict
235
238
pure (new, (prev, new))
236
239
when (prev /= Just v) $ do
237
240
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
240
244
241
- deleteFileOfInterest :: IdeState -> NormalizedFilePath -> IO ()
242
- deleteFileOfInterest state f = do
245
+ deleteFileOfInterest :: Recorder ( WithPriority Log ) -> IdeState -> NormalizedFilePath -> IO ()
246
+ deleteFileOfInterest recorder state f = do
243
247
OfInterestCabalVar var <- Shake. getIdeGlobalState state
244
248
files <- modifyVar' var $ HashMap. delete f
245
249
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