@@ -97,7 +97,7 @@ instance Pretty Log where
97
97
descriptor :: Recorder (WithPriority Log ) -> PluginId -> PluginDescriptor IdeState
98
98
descriptor recorder plId =
99
99
(defaultCabalProjectPluginDescriptor plId " Provides a variety of IDE features in cabal.project files" )
100
- { pluginRules = cabalRules recorder plId
100
+ { pluginRules = cabalProjectRules recorder plId
101
101
, pluginHandlers =
102
102
mconcat
103
103
[
@@ -109,25 +109,25 @@ descriptor recorder plId =
109
109
\ ide vfs _ (DidOpenTextDocumentParams TextDocumentItem {_uri, _version}) -> liftIO $ do
110
110
whenUriFile _uri $ \ file -> do
111
111
log' Debug $ LogDocOpened _uri
112
- restartCabalShakeSession (shakeExtras ide) vfs file " (opened)" $
112
+ restartCabalProjectShakeSession (shakeExtras ide) vfs file " (opened)" $
113
113
addFileOfInterest recorder ide file Modified {firstOpen = True }
114
114
, mkPluginNotificationHandler LSP. SMethod_TextDocumentDidChange $
115
115
\ ide vfs _ (DidChangeTextDocumentParams VersionedTextDocumentIdentifier {_uri} _) -> liftIO $ do
116
116
whenUriFile _uri $ \ file-> do
117
117
log' Debug $ LogDocModified _uri
118
- restartCabalShakeSession (shakeExtras ide) vfs file " (changed)" $
118
+ restartCabalProjectShakeSession (shakeExtras ide) vfs file " (changed)" $
119
119
addFileOfInterest recorder ide file Modified {firstOpen = False }
120
120
, mkPluginNotificationHandler LSP. SMethod_TextDocumentDidSave $
121
121
\ ide vfs _ (DidSaveTextDocumentParams TextDocumentIdentifier {_uri} _) -> liftIO $ do
122
122
whenUriFile _uri $ \ file -> do
123
123
log' Debug $ LogDocSaved _uri
124
- restartCabalShakeSession (shakeExtras ide) vfs file " (saved)" $
124
+ restartCabalProjectShakeSession (shakeExtras ide) vfs file " (saved)" $
125
125
addFileOfInterest recorder ide file OnDisk
126
126
, mkPluginNotificationHandler LSP. SMethod_TextDocumentDidClose $
127
127
\ ide vfs _ (DidCloseTextDocumentParams TextDocumentIdentifier {_uri}) -> liftIO $ do
128
128
whenUriFile _uri $ \ file -> do
129
129
log' Debug $ LogDocClosed _uri
130
- restartCabalShakeSession (shakeExtras ide) vfs file " (closed)" $
130
+ restartCabalProjectShakeSession (shakeExtras ide) vfs file " (closed)" $
131
131
deleteFileOfInterest recorder ide file
132
132
]
133
133
, 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
149
149
rule depends on.
150
150
Then we restart the shake session, so that changes to our virtual files are actually picked up.
151
151
-}
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
154
154
restartShakeSession shakeExtras (VFSModified vfs) (fromNormalizedFilePath file ++ " " ++ actionMsg) [] $ do
155
155
keys <- actionBetweenSession
156
156
return (toKey GetModificationTime file: keys)
157
157
158
158
159
- cabalRules :: Recorder (WithPriority Log ) -> PluginId -> Rules ()
160
- cabalRules recorder plId = do
159
+ cabalProjectRules :: Recorder (WithPriority Log ) -> PluginId -> Rules ()
160
+ cabalProjectRules recorder plId = do
161
161
-- Make sure we initialise the cabal project files-of-interest.
162
162
ofInterestRules recorder
163
163
-- Rule to produce diagnostics for cabal project files.
@@ -168,9 +168,9 @@ cabalRules recorder plId = do
168
168
else do
169
169
-- whenever this key is marked as dirty (e.g., when a user writes stuff to it),
170
170
-- we rerun this rule because this rule *depends* on GetModificationTime.
171
- (t, mCabalSource ) <- use_ GetFileContents file
171
+ (t, mCabalProjectSource ) <- use_ GetFileContents file
172
172
log' Debug $ LogModificationTime file t
173
- contents <- case mCabalSource of
173
+ contents <- case mCabalProjectSource of
174
174
Just sources ->
175
175
pure $ Encoding. encodeUtf8 $ Rope. toText sources
176
176
Nothing -> do
@@ -189,10 +189,10 @@ cabalRules recorder plId = do
189
189
else do
190
190
-- whenever this key is marked as dirty (e.g., when a user writes stuff to it),
191
191
-- we rerun this rule because this rule *depends* on GetModificationTime.
192
- (t, mCabalSource ) <- use_ GetFileContents file
192
+ (t, mCabalProjectSource ) <- use_ GetFileContents file
193
193
log' Debug $ LogModificationTime file t
194
194
195
- contents <- case mCabalSource of
195
+ contents <- case mCabalProjectSource of
196
196
Just sources ->
197
197
pure $ Encoding. encodeUtf8 $ Rope. toText sources
198
198
Nothing ->
@@ -226,79 +226,79 @@ function invocation.
226
226
-}
227
227
kick :: Action ()
228
228
kick = do
229
- files <- HashMap. keys <$> getCabalFilesOfInterestUntracked
229
+ files <- HashMap. keys <$> getCabalProjectFilesOfInterestUntracked
230
230
Shake. runWithSignal (Proxy @ " kick/start/cabal-project" ) (Proxy @ " kick/done/cabal-project" ) files Types. ParseCabalProjectFile
231
231
232
232
233
233
-- ----------------------------------------------------------------
234
234
-- Cabal project file of Interest rules and global variable
235
235
-- ----------------------------------------------------------------
236
236
237
- {- | Cabal files that are currently open in the lsp-client.
237
+ {- | Cabal project files that are currently open in the lsp-client.
238
238
Specific actions happen when these files are saved, closed or modified,
239
239
such as generating diagnostics, re-parsing, etc...
240
240
241
241
We need to store the open files to parse them again if we restart the shake session.
242
242
Restarting of the shake session happens whenever these files are modified.
243
243
-}
244
- newtype OfInterestCabalVar = OfInterestCabalVar (Var (HashMap NormalizedFilePath FileOfInterestStatus ))
244
+ newtype OfInterestCabalProjectVar = OfInterestCabalProjectVar (Var (HashMap NormalizedFilePath FileOfInterestStatus ))
245
245
246
- instance Shake. IsIdeGlobal OfInterestCabalVar
246
+ instance Shake. IsIdeGlobal OfInterestCabalProjectVar
247
247
248
- data IsCabalFileOfInterest = IsCabalFileOfInterest
248
+ data IsCabalProjectFileOfInterest = IsCabalProjectFileOfInterest
249
249
deriving (Eq , Show , Generic )
250
- instance Hashable IsCabalFileOfInterest
251
- instance NFData IsCabalFileOfInterest
250
+ instance Hashable IsCabalProjectFileOfInterest
251
+ instance NFData IsCabalProjectFileOfInterest
252
252
253
- type instance RuleResult IsCabalFileOfInterest = CabalFileOfInterestResult
253
+ type instance RuleResult IsCabalProjectFileOfInterest = CabalProjectFileOfInterestResult
254
254
255
- data CabalFileOfInterestResult = NotCabalFOI | IsCabalFOI FileOfInterestStatus
255
+ data CabalProjectFileOfInterestResult = NotCabalProjectFOI | IsCabalProjectFOI FileOfInterestStatus
256
256
deriving (Eq , Show , Generic )
257
- instance Hashable CabalFileOfInterestResult
258
- instance NFData CabalFileOfInterestResult
257
+ instance Hashable CabalProjectFileOfInterestResult
258
+ instance NFData CabalProjectFileOfInterestResult
259
259
260
260
{- | The rule that initialises the files of interest state.
261
261
262
262
Needs to be run on start-up.
263
263
-}
264
264
ofInterestRules :: Recorder (WithPriority Log ) -> Rules ()
265
265
ofInterestRules 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
268
268
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
271
271
fp = summarize foi
272
272
res = (Just fp, Just foi)
273
273
return res
274
274
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
283
283
liftIO $ readVar var
284
284
285
285
addFileOfInterest :: Recorder (WithPriority Log ) -> IdeState -> NormalizedFilePath -> FileOfInterestStatus -> IO [Key ]
286
286
addFileOfInterest recorder state f v = do
287
- OfInterestCabalVar var <- Shake. getIdeGlobalState state
287
+ OfInterestCabalProjectVar var <- Shake. getIdeGlobalState state
288
288
(prev, files) <- modifyVar var $ \ dict -> do
289
289
let (prev, new) = HashMap. alterF (,Just v) f dict
290
290
pure (new, (prev, new))
291
291
if prev /= Just v
292
292
then do
293
293
log' Debug $ LogFOI files
294
- return [toKey IsCabalFileOfInterest f]
294
+ return [toKey IsCabalProjectFileOfInterest f]
295
295
else return []
296
296
where
297
297
log' = logWith recorder
298
298
299
299
deleteFileOfInterest :: Recorder (WithPriority Log ) -> IdeState -> NormalizedFilePath -> IO [Key ]
300
300
deleteFileOfInterest recorder state f = do
301
- OfInterestCabalVar var <- Shake. getIdeGlobalState state
301
+ OfInterestCabalProjectVar var <- Shake. getIdeGlobalState state
302
302
files <- modifyVar' var $ HashMap. delete f
303
303
log' Debug $ LogFOI files
304
304
return [toKey IsFileOfInterest f]
0 commit comments