@@ -157,8 +157,8 @@ allExtensions opts = [extIncBoot | ext <- optExtensions opts, extIncBoot <- [ext
157
157
-- | Installs the 'getFileExists' rules.
158
158
-- Provides a fast implementation if client supports dynamic watched files.
159
159
-- Creates a global state as a side effect in that case.
160
- fileExistsRules :: Maybe (LanguageContextEnv Config ) -> VFSHandle -> Rules ()
161
- fileExistsRules lspEnv vfs = do
160
+ fileExistsRules :: Maybe (LanguageContextEnv Config ) -> Rules ()
161
+ fileExistsRules lspEnv = do
162
162
supportsWatchedFiles <- case lspEnv of
163
163
Nothing -> pure False
164
164
Just lspEnv' -> liftIO $ runLspT lspEnv' isWatchSupported
@@ -179,19 +179,19 @@ fileExistsRules lspEnv vfs = do
179
179
else const $ pure False
180
180
181
181
if supportsWatchedFiles
182
- then fileExistsRulesFast isWatched vfs
183
- else fileExistsRulesSlow vfs
182
+ then fileExistsRulesFast isWatched
183
+ else fileExistsRulesSlow
184
184
185
- fileStoreRules vfs isWatched
185
+ fileStoreRules isWatched
186
186
187
187
-- Requires an lsp client that provides WatchedFiles notifications, but assumes that this has already been checked.
188
- fileExistsRulesFast :: (NormalizedFilePath -> Action Bool ) -> VFSHandle -> Rules ()
189
- fileExistsRulesFast isWatched vfs =
188
+ fileExistsRulesFast :: (NormalizedFilePath -> Action Bool ) -> Rules ()
189
+ fileExistsRulesFast isWatched =
190
190
defineEarlyCutoff $ RuleNoDiagnostics $ \ GetFileExists file -> do
191
191
isWF <- isWatched file
192
192
if isWF
193
- then fileExistsFast vfs file
194
- else fileExistsSlow vfs file
193
+ then fileExistsFast file
194
+ else fileExistsSlow file
195
195
196
196
{- Note [Invalidating file existence results]
197
197
We have two mechanisms for getting file existence information:
@@ -209,8 +209,8 @@ For the VFS lookup, however, we won't get prompted to flush the result, so inste
209
209
we use 'alwaysRerun'.
210
210
-}
211
211
212
- fileExistsFast :: VFSHandle -> NormalizedFilePath -> Action (Maybe BS. ByteString , Maybe Bool )
213
- fileExistsFast vfs file = do
212
+ fileExistsFast :: NormalizedFilePath -> Action (Maybe BS. ByteString , Maybe Bool )
213
+ fileExistsFast file = do
214
214
-- Could in principle use 'alwaysRerun' here, but it's too slwo, See Note [Invalidating file existence results]
215
215
mp <- getFileExistsMapUntracked
216
216
@@ -219,28 +219,27 @@ fileExistsFast vfs file = do
219
219
Just exist -> pure exist
220
220
-- We don't know about it: use the slow route.
221
221
-- Note that we do *not* call 'fileExistsSlow', as that would trigger 'alwaysRerun'.
222
- Nothing -> liftIO $ getFileExistsVFS vfs file
222
+ Nothing -> getFileExistsVFS file
223
223
pure (summarizeExists exist, Just exist)
224
224
225
225
summarizeExists :: Bool -> Maybe BS. ByteString
226
226
summarizeExists x = Just $ if x then BS. singleton 1 else BS. empty
227
227
228
- fileExistsRulesSlow :: VFSHandle -> Rules ()
229
- fileExistsRulesSlow vfs =
230
- defineEarlyCutoff $ RuleNoDiagnostics $ \ GetFileExists file -> fileExistsSlow vfs file
228
+ fileExistsRulesSlow :: Rules ()
229
+ fileExistsRulesSlow =
230
+ defineEarlyCutoff $ RuleNoDiagnostics $ \ GetFileExists file -> fileExistsSlow file
231
231
232
- fileExistsSlow :: VFSHandle -> NormalizedFilePath -> Action (Maybe BS. ByteString , Maybe Bool )
233
- fileExistsSlow vfs file = do
232
+ fileExistsSlow :: NormalizedFilePath -> Action (Maybe BS. ByteString , Maybe Bool )
233
+ fileExistsSlow file = do
234
234
-- See Note [Invalidating file existence results]
235
235
alwaysRerun
236
- exist <- liftIO $ getFileExistsVFS vfs file
236
+ exist <- getFileExistsVFS file
237
237
pure (summarizeExists exist, Just exist)
238
238
239
- getFileExistsVFS :: VFSHandle -> NormalizedFilePath -> IO Bool
240
- getFileExistsVFS vfs file = do
241
- -- we deliberately and intentionally wrap the file as an FilePath WITHOUT mkAbsolute
242
- -- so that if the file doesn't exist, is on a shared drive that is unmounted etc we get a properly
243
- -- cached 'No' rather than an exception in the wrong place
244
- handle (\ (_ :: IOException ) -> return False ) $
245
- (isJust <$> getVirtualFile vfs (filePathToUri' file)) ||^
246
- Dir. doesFileExist (fromNormalizedFilePath file)
239
+ getFileExistsVFS :: NormalizedFilePath -> Action Bool
240
+ getFileExistsVFS file = do
241
+ vf <- getVirtualFile file
242
+ if isJust vf
243
+ then pure True
244
+ else liftIO $ handle (\ (_ :: IOException ) -> return False ) $
245
+ Dir. doesFileExist (fromNormalizedFilePath file)
0 commit comments