@@ -157,8 +157,8 @@ allExtensions opts = [extIncBoot | ext <- optExtensions opts, extIncBoot <- [ext
157157-- | Installs the 'getFileExists' rules.
158158-- Provides a fast implementation if client supports dynamic watched files.
159159-- 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
162162 supportsWatchedFiles <- case lspEnv of
163163 Nothing -> pure False
164164 Just lspEnv' -> liftIO $ runLspT lspEnv' isWatchSupported
@@ -179,19 +179,19 @@ fileExistsRules lspEnv vfs = do
179179 else const $ pure False
180180
181181 if supportsWatchedFiles
182- then fileExistsRulesFast isWatched vfs
183- else fileExistsRulesSlow vfs
182+ then fileExistsRulesFast isWatched
183+ else fileExistsRulesSlow
184184
185- fileStoreRules vfs isWatched
185+ fileStoreRules isWatched
186186
187187-- 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 =
190190 defineEarlyCutoff $ RuleNoDiagnostics $ \ GetFileExists file -> do
191191 isWF <- isWatched file
192192 if isWF
193- then fileExistsFast vfs file
194- else fileExistsSlow vfs file
193+ then fileExistsFast file
194+ else fileExistsSlow file
195195
196196{- Note [Invalidating file existence results]
197197We 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
209209we use 'alwaysRerun'.
210210-}
211211
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
214214 -- Could in principle use 'alwaysRerun' here, but it's too slwo, See Note [Invalidating file existence results]
215215 mp <- getFileExistsMapUntracked
216216
@@ -219,28 +219,27 @@ fileExistsFast vfs file = do
219219 Just exist -> pure exist
220220 -- We don't know about it: use the slow route.
221221 -- Note that we do *not* call 'fileExistsSlow', as that would trigger 'alwaysRerun'.
222- Nothing -> liftIO $ getFileExistsVFS vfs file
222+ Nothing -> getFileExistsVFS file
223223 pure (summarizeExists exist, Just exist)
224224
225225summarizeExists :: Bool -> Maybe BS. ByteString
226226summarizeExists x = Just $ if x then BS. singleton 1 else BS. empty
227227
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
231231
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
234234 -- See Note [Invalidating file existence results]
235235 alwaysRerun
236- exist <- liftIO $ getFileExistsVFS vfs file
236+ exist <- getFileExistsVFS file
237237 pure (summarizeExists exist, Just exist)
238238
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