From 3d7195da4121e17c7d0c30724bb9a6e043d9ab68 Mon Sep 17 00:00:00 2001 From: Pepe Iborra Date: Sat, 27 Mar 2021 11:10:00 +0000 Subject: [PATCH 1/4] Avoid creating IsFileOfInterest keys for non workspace files --- ghcide/src/Development/IDE/Core/FileStore.hs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/ghcide/src/Development/IDE/Core/FileStore.hs b/ghcide/src/Development/IDE/Core/FileStore.hs index 0c0c8ca23f..ac2a512e09 100644 --- a/ghcide/src/Development/IDE/Core/FileStore.hs +++ b/ghcide/src/Development/IDE/Core/FileStore.hs @@ -67,6 +67,7 @@ import qualified Development.IDE.Types.Logger as L import qualified Data.Binary as B import qualified Data.ByteString.Lazy as LBS +import Development.IDE.Core.IdeConfiguration (isWorkspaceFile) import Language.LSP.Server hiding (getVirtualFile) import qualified Language.LSP.Server as LSP @@ -129,7 +130,8 @@ getModificationTimeImpl vfs isWatched missingFileDiags file = do mbVirtual <- liftIO $ getVirtualFile vfs $ filePathToUri' file -- we use 'getVirtualFile' to discriminate FOIs so make that -- dependency explicit by using the IsFileOfInterest rule - _ <- use_ IsFileOfInterest file + isWF <- isWorkspaceFile file + when isWF $ void $ use_ IsFileOfInterest file case mbVirtual of Just (virtualFileVersion -> ver) -> do alwaysRerun From bf61949cec307e74e94e8c849f80ad9604882e94 Mon Sep 17 00:00:00 2001 From: Pepe Iborra Date: Sun, 4 Apr 2021 09:04:10 +0100 Subject: [PATCH 2/4] Only add the IsFileOfInterest dependency when needed --- ghcide/src/Development/IDE/Core/FileStore.hs | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/ghcide/src/Development/IDE/Core/FileStore.hs b/ghcide/src/Development/IDE/Core/FileStore.hs index ac2a512e09..e78f90d976 100644 --- a/ghcide/src/Development/IDE/Core/FileStore.hs +++ b/ghcide/src/Development/IDE/Core/FileStore.hs @@ -128,17 +128,20 @@ getModificationTimeImpl vfs isWatched missingFileDiags file = do let file' = fromNormalizedFilePath file let wrap time@(l,s) = (Just $ LBS.toStrict $ B.encode time, ([], Just $ ModificationTime l s)) mbVirtual <- liftIO $ getVirtualFile vfs $ filePathToUri' file - -- we use 'getVirtualFile' to discriminate FOIs so make that - -- dependency explicit by using the IsFileOfInterest rule - isWF <- isWorkspaceFile file - when isWF $ void $ use_ IsFileOfInterest file case mbVirtual of Just (virtualFileVersion -> ver) -> do alwaysRerun pure (Just $ LBS.toStrict $ B.encode ver, ([], Just $ VFSVersion ver)) Nothing -> do isWF <- isWatched file - unless (isWF || isInterface file) alwaysRerun + unless (isWF || isInterface file) + -- If the file is watched, we don't need alwaysRerun. + -- Interface files are not watched by the LSP client but + -- we keep track of their freshness, so no alwaysRerun + alwaysRerun + when (isWF && not (isInterface file)) $ + -- we use 'getVirtualFile' to discriminate FOIs so make that dependency explicit + void $ use_ IsFileOfInterest file liftIO $ fmap wrap (getModTime file') `catch` \(e :: IOException) -> do let err | isDoesNotExistError e = "File does not exist: " ++ file' From 035edc830af45e16f9ab0355518c4c01f51c2ab3 Mon Sep 17 00:00:00 2001 From: Pepe Iborra Date: Mon, 5 Apr 2021 11:35:32 +0100 Subject: [PATCH 3/4] Clarify logic --- ghcide/src/Development/IDE/Core/FileStore.hs | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/ghcide/src/Development/IDE/Core/FileStore.hs b/ghcide/src/Development/IDE/Core/FileStore.hs index e78f90d976..49064beb62 100644 --- a/ghcide/src/Development/IDE/Core/FileStore.hs +++ b/ghcide/src/Development/IDE/Core/FileStore.hs @@ -134,11 +134,17 @@ getModificationTimeImpl vfs isWatched missingFileDiags file = do pure (Just $ LBS.toStrict $ B.encode ver, ([], Just $ VFSVersion ver)) Nothing -> do isWF <- isWatched file - unless (isWF || isInterface file) - -- If the file is watched, we don't need alwaysRerun. - -- Interface files are not watched by the LSP client but - -- we keep track of their freshness, so no alwaysRerun - alwaysRerun + if isWF + then -- the file is watched so we can rely on FileWatched notifications, + -- but also need a dependency on IsFileOfInterest to reinstall + -- alwaysRerun when the file becomes VFS + void (use_ IsFileOfInterest file) + else if isInterface file + then -- interface files are tracked specially using the closed world assumption + pure () + else -- in all other cases we will need to freshly check the file system + alwaysRerun + when (isWF && not (isInterface file)) $ -- we use 'getVirtualFile' to discriminate FOIs so make that dependency explicit void $ use_ IsFileOfInterest file From 3d3f36b9173e78f4468a6c62fe941df58eb939c4 Mon Sep 17 00:00:00 2001 From: Pepe Iborra Date: Mon, 5 Apr 2021 11:44:20 +0100 Subject: [PATCH 4/4] fixup! Clarify logic --- ghcide/src/Development/IDE/Core/FileStore.hs | 3 --- 1 file changed, 3 deletions(-) diff --git a/ghcide/src/Development/IDE/Core/FileStore.hs b/ghcide/src/Development/IDE/Core/FileStore.hs index 49064beb62..098756f71d 100644 --- a/ghcide/src/Development/IDE/Core/FileStore.hs +++ b/ghcide/src/Development/IDE/Core/FileStore.hs @@ -145,9 +145,6 @@ getModificationTimeImpl vfs isWatched missingFileDiags file = do else -- in all other cases we will need to freshly check the file system alwaysRerun - when (isWF && not (isInterface file)) $ - -- we use 'getVirtualFile' to discriminate FOIs so make that dependency explicit - void $ use_ IsFileOfInterest file liftIO $ fmap wrap (getModTime file') `catch` \(e :: IOException) -> do let err | isDoesNotExistError e = "File does not exist: " ++ file'