@@ -97,7 +97,7 @@ instance Pretty Log where
9797descriptor :: Recorder (WithPriority Log ) -> PluginId -> PluginDescriptor IdeState
9898descriptor recorder plId =
9999 (defaultCabalProjectPluginDescriptor plId " Provides a variety of IDE features in cabal.project files" )
100- { pluginRules = cabalRules recorder plId
100+ { pluginRules = cabalProjectRules recorder plId
101101 , pluginHandlers =
102102 mconcat
103103 [
@@ -109,25 +109,25 @@ descriptor recorder plId =
109109 \ ide vfs _ (DidOpenTextDocumentParams TextDocumentItem {_uri, _version}) -> liftIO $ do
110110 whenUriFile _uri $ \ file -> do
111111 log' Debug $ LogDocOpened _uri
112- restartCabalShakeSession (shakeExtras ide) vfs file " (opened)" $
112+ restartCabalProjectShakeSession (shakeExtras ide) vfs file " (opened)" $
113113 addFileOfInterest recorder ide file Modified {firstOpen = True }
114114 , mkPluginNotificationHandler LSP. SMethod_TextDocumentDidChange $
115115 \ ide vfs _ (DidChangeTextDocumentParams VersionedTextDocumentIdentifier {_uri} _) -> liftIO $ do
116116 whenUriFile _uri $ \ file-> do
117117 log' Debug $ LogDocModified _uri
118- restartCabalShakeSession (shakeExtras ide) vfs file " (changed)" $
118+ restartCabalProjectShakeSession (shakeExtras ide) vfs file " (changed)" $
119119 addFileOfInterest recorder ide file Modified {firstOpen = False }
120120 , mkPluginNotificationHandler LSP. SMethod_TextDocumentDidSave $
121121 \ ide vfs _ (DidSaveTextDocumentParams TextDocumentIdentifier {_uri} _) -> liftIO $ do
122122 whenUriFile _uri $ \ file -> do
123123 log' Debug $ LogDocSaved _uri
124- restartCabalShakeSession (shakeExtras ide) vfs file " (saved)" $
124+ restartCabalProjectShakeSession (shakeExtras ide) vfs file " (saved)" $
125125 addFileOfInterest recorder ide file OnDisk
126126 , mkPluginNotificationHandler LSP. SMethod_TextDocumentDidClose $
127127 \ ide vfs _ (DidCloseTextDocumentParams TextDocumentIdentifier {_uri}) -> liftIO $ do
128128 whenUriFile _uri $ \ file -> do
129129 log' Debug $ LogDocClosed _uri
130- restartCabalShakeSession (shakeExtras ide) vfs file " (closed)" $
130+ restartCabalProjectShakeSession (shakeExtras ide) vfs file " (closed)" $
131131 deleteFileOfInterest recorder ide file
132132 ]
133133 , pluginConfigDescriptor = defaultConfigDescriptor
@@ -149,15 +149,15 @@ needs to be re-parsed. That's what we do when we record the dirty key that our p
149149rule depends on.
150150Then we restart the shake session, so that changes to our virtual files are actually picked up.
151151-}
152- restartCabalShakeSession :: ShakeExtras -> VFS. VFS -> NormalizedFilePath -> String -> IO [Key ] -> IO ()
153- restartCabalShakeSession shakeExtras vfs file actionMsg actionBetweenSession = do
152+ restartCabalProjectShakeSession :: ShakeExtras -> VFS. VFS -> NormalizedFilePath -> String -> IO [Key ] -> IO ()
153+ restartCabalProjectShakeSession shakeExtras vfs file actionMsg actionBetweenSession = do
154154 restartShakeSession shakeExtras (VFSModified vfs) (fromNormalizedFilePath file ++ " " ++ actionMsg) [] $ do
155155 keys <- actionBetweenSession
156156 return (toKey GetModificationTime file: keys)
157157
158158
159- cabalRules :: Recorder (WithPriority Log ) -> PluginId -> Rules ()
160- cabalRules recorder plId = do
159+ cabalProjectRules :: Recorder (WithPriority Log ) -> PluginId -> Rules ()
160+ cabalProjectRules recorder plId = do
161161 -- Make sure we initialise the cabal project files-of-interest.
162162 ofInterestRules recorder
163163 -- Rule to produce diagnostics for cabal project files.
@@ -168,9 +168,9 @@ cabalRules recorder plId = do
168168 else do
169169 -- whenever this key is marked as dirty (e.g., when a user writes stuff to it),
170170 -- we rerun this rule because this rule *depends* on GetModificationTime.
171- (t, mCabalSource ) <- use_ GetFileContents file
171+ (t, mCabalProjectSource ) <- use_ GetFileContents file
172172 log' Debug $ LogModificationTime file t
173- contents <- case mCabalSource of
173+ contents <- case mCabalProjectSource of
174174 Just sources ->
175175 pure $ Encoding. encodeUtf8 $ Rope. toText sources
176176 Nothing -> do
@@ -189,10 +189,10 @@ cabalRules recorder plId = do
189189 else do
190190 -- whenever this key is marked as dirty (e.g., when a user writes stuff to it),
191191 -- we rerun this rule because this rule *depends* on GetModificationTime.
192- (t, mCabalSource ) <- use_ GetFileContents file
192+ (t, mCabalProjectSource ) <- use_ GetFileContents file
193193 log' Debug $ LogModificationTime file t
194194
195- contents <- case mCabalSource of
195+ contents <- case mCabalProjectSource of
196196 Just sources ->
197197 pure $ Encoding. encodeUtf8 $ Rope. toText sources
198198 Nothing ->
@@ -226,79 +226,79 @@ function invocation.
226226-}
227227kick :: Action ()
228228kick = do
229- files <- HashMap. keys <$> getCabalFilesOfInterestUntracked
229+ files <- HashMap. keys <$> getCabalProjectFilesOfInterestUntracked
230230 Shake. runWithSignal (Proxy @ " kick/start/cabal-project" ) (Proxy @ " kick/done/cabal-project" ) files Types. ParseCabalProjectFile
231231
232232
233233-- ----------------------------------------------------------------
234234-- Cabal project file of Interest rules and global variable
235235-- ----------------------------------------------------------------
236236
237- {- | Cabal files that are currently open in the lsp-client.
237+ {- | Cabal project files that are currently open in the lsp-client.
238238Specific actions happen when these files are saved, closed or modified,
239239such as generating diagnostics, re-parsing, etc...
240240
241241We need to store the open files to parse them again if we restart the shake session.
242242Restarting of the shake session happens whenever these files are modified.
243243-}
244- newtype OfInterestCabalVar = OfInterestCabalVar (Var (HashMap NormalizedFilePath FileOfInterestStatus ))
244+ newtype OfInterestCabalProjectVar = OfInterestCabalProjectVar (Var (HashMap NormalizedFilePath FileOfInterestStatus ))
245245
246- instance Shake. IsIdeGlobal OfInterestCabalVar
246+ instance Shake. IsIdeGlobal OfInterestCabalProjectVar
247247
248- data IsCabalFileOfInterest = IsCabalFileOfInterest
248+ data IsCabalProjectFileOfInterest = IsCabalProjectFileOfInterest
249249 deriving (Eq , Show , Generic )
250- instance Hashable IsCabalFileOfInterest
251- instance NFData IsCabalFileOfInterest
250+ instance Hashable IsCabalProjectFileOfInterest
251+ instance NFData IsCabalProjectFileOfInterest
252252
253- type instance RuleResult IsCabalFileOfInterest = CabalFileOfInterestResult
253+ type instance RuleResult IsCabalProjectFileOfInterest = CabalProjectFileOfInterestResult
254254
255- data CabalFileOfInterestResult = NotCabalFOI | IsCabalFOI FileOfInterestStatus
255+ data CabalProjectFileOfInterestResult = NotCabalProjectFOI | IsCabalProjectFOI FileOfInterestStatus
256256 deriving (Eq , Show , Generic )
257- instance Hashable CabalFileOfInterestResult
258- instance NFData CabalFileOfInterestResult
257+ instance Hashable CabalProjectFileOfInterestResult
258+ instance NFData CabalProjectFileOfInterestResult
259259
260260{- | The rule that initialises the files of interest state.
261261
262262Needs to be run on start-up.
263263-}
264264ofInterestRules :: Recorder (WithPriority Log ) -> Rules ()
265265ofInterestRules recorder = do
266- Shake. addIdeGlobal . OfInterestCabalVar =<< liftIO (newVar HashMap. empty)
267- Shake. defineEarlyCutoff (cmapWithPrio LogShake recorder) $ RuleNoDiagnostics $ \ IsCabalFileOfInterest f -> do
266+ Shake. addIdeGlobal . OfInterestCabalProjectVar =<< liftIO (newVar HashMap. empty)
267+ Shake. defineEarlyCutoff (cmapWithPrio LogShake recorder) $ RuleNoDiagnostics $ \ IsCabalProjectFileOfInterest f -> do
268268 alwaysRerun
269- filesOfInterest <- getCabalFilesOfInterestUntracked
270- let foi = maybe NotCabalFOI IsCabalFOI $ f `HashMap.lookup` filesOfInterest
269+ filesOfInterest <- getCabalProjectFilesOfInterestUntracked
270+ let foi = maybe NotCabalProjectFOI IsCabalProjectFOI $ f `HashMap.lookup` filesOfInterest
271271 fp = summarize foi
272272 res = (Just fp, Just foi)
273273 return res
274274 where
275- summarize NotCabalFOI = BS. singleton 0
276- summarize (IsCabalFOI OnDisk ) = BS. singleton 1
277- summarize (IsCabalFOI (Modified False )) = BS. singleton 2
278- summarize (IsCabalFOI (Modified True )) = BS. singleton 3
279-
280- getCabalFilesOfInterestUntracked :: Action (HashMap NormalizedFilePath FileOfInterestStatus )
281- getCabalFilesOfInterestUntracked = do
282- OfInterestCabalVar var <- Shake. getIdeGlobalAction
275+ summarize NotCabalProjectFOI = BS. singleton 0
276+ summarize (IsCabalProjectFOI OnDisk ) = BS. singleton 1
277+ summarize (IsCabalProjectFOI (Modified False )) = BS. singleton 2
278+ summarize (IsCabalProjectFOI (Modified True )) = BS. singleton 3
279+
280+ getCabalProjectFilesOfInterestUntracked :: Action (HashMap NormalizedFilePath FileOfInterestStatus )
281+ getCabalProjectFilesOfInterestUntracked = do
282+ OfInterestCabalProjectVar var <- Shake. getIdeGlobalAction
283283 liftIO $ readVar var
284284
285285addFileOfInterest :: Recorder (WithPriority Log ) -> IdeState -> NormalizedFilePath -> FileOfInterestStatus -> IO [Key ]
286286addFileOfInterest recorder state f v = do
287- OfInterestCabalVar var <- Shake. getIdeGlobalState state
287+ OfInterestCabalProjectVar var <- Shake. getIdeGlobalState state
288288 (prev, files) <- modifyVar var $ \ dict -> do
289289 let (prev, new) = HashMap. alterF (,Just v) f dict
290290 pure (new, (prev, new))
291291 if prev /= Just v
292292 then do
293293 log' Debug $ LogFOI files
294- return [toKey IsCabalFileOfInterest f]
294+ return [toKey IsCabalProjectFileOfInterest f]
295295 else return []
296296 where
297297 log' = logWith recorder
298298
299299deleteFileOfInterest :: Recorder (WithPriority Log ) -> IdeState -> NormalizedFilePath -> IO [Key ]
300300deleteFileOfInterest recorder state f = do
301- OfInterestCabalVar var <- Shake. getIdeGlobalState state
301+ OfInterestCabalProjectVar var <- Shake. getIdeGlobalState state
302302 files <- modifyVar' var $ HashMap. delete f
303303 log' Debug $ LogFOI files
304304 return [toKey IsFileOfInterest f]
0 commit comments