Skip to content

Commit fdad0bd

Browse files
committed
rename and avoid resetting FOIs
1 parent 4b56260 commit fdad0bd

File tree

2 files changed

+14
-8
lines changed

2 files changed

+14
-8
lines changed

ghcide/src/Development/IDE/Core/FileStore.hs

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ module Development.IDE.Core.FileStore(
1515
makeVFSHandle,
1616
makeLSPVFSHandle,
1717
isFileOfInterestRule
18-
,modifyFileStore) where
18+
,resetFileStore) where
1919

2020
import Control.Concurrent.Extra
2121
import Control.Concurrent.STM (atomically)
@@ -31,7 +31,7 @@ import Data.Maybe
3131
import qualified Data.Rope.UTF16 as Rope
3232
import qualified Data.Text as T
3333
import Data.Time
34-
import Development.IDE.Core.OfInterest (getFilesOfInterest)
34+
import Development.IDE.Core.OfInterest (getFilesOfInterest, OfInterestVar(..))
3535
import Development.IDE.Core.RuleTypes
3636
import Development.IDE.Core.Shake
3737
import Development.IDE.GHC.Orphans ()
@@ -65,7 +65,7 @@ import Language.LSP.Server hiding
6565
import qualified Language.LSP.Server as LSP
6666
import Language.LSP.Types (FileChangeType (FcChanged),
6767
FileEvent (FileEvent),
68-
uriToFilePath)
68+
uriToFilePath, toNormalizedFilePath)
6969
import Language.LSP.VFS
7070

7171
makeVFSHandle :: IO VFSHandle
@@ -119,15 +119,20 @@ getModificationTimeRule vfs isWatched =
119119
else return (Nothing, ([diag], Nothing))
120120

121121
-- | Reset the GetModificationTime state of watched files
122-
modifyFileStore :: IdeState -> [FileEvent] -> IO ()
123-
modifyFileStore state changes = mask $ \_ ->
122+
resetFileStore :: IdeState -> [FileEvent] -> IO ()
123+
resetFileStore ideState changes = mask $ \_ ->
124124
forM_ changes $ \(FileEvent uri c) ->
125125
case c of
126126
FcChanged
127127
| Just f <- uriToFilePath uri
128128
-> do
129-
deleteValue state (GetModificationTime_ True) (toNormalizedFilePath' f)
130-
deleteValue state (GetModificationTime_ False) (toNormalizedFilePath' f)
129+
-- we record FOIs document versions in all the stored values
130+
-- so NEVER reset FOIs to avoid losing their versions
131+
OfInterestVar foisVar <- getIdeGlobalExtras (shakeExtras ideState)
132+
fois <- readVar foisVar
133+
unless (HM.member (toNormalizedFilePath f) fois) $ do
134+
deleteValue ideState (GetModificationTime_ True) (toNormalizedFilePath' f)
135+
deleteValue ideState (GetModificationTime_ False) (toNormalizedFilePath' f)
131136
_ -> pure ()
132137

133138
-- Dir.getModificationTime is surprisingly slow since it performs

ghcide/src/Development/IDE/Core/OfInterest.hs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@
99
module Development.IDE.Core.OfInterest(
1010
ofInterestRules,
1111
getFilesOfInterest, setFilesOfInterest, modifyFilesOfInterest,
12-
kick, FileOfInterestStatus(..)
12+
kick, FileOfInterestStatus(..),
13+
OfInterestVar(..)
1314
) where
1415

1516
import Control.Concurrent.Extra

0 commit comments

Comments
 (0)