Skip to content

Commit

Permalink
rename and avoid resetting FOIs
Browse files Browse the repository at this point in the history
  • Loading branch information
pepeiborra committed Mar 5, 2021
1 parent 4b56260 commit 2b6338e
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 10 deletions.
19 changes: 12 additions & 7 deletions ghcide/src/Development/IDE/Core/FileStore.hs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ module Development.IDE.Core.FileStore(
makeVFSHandle,
makeLSPVFSHandle,
isFileOfInterestRule
,modifyFileStore) where
,resetFileStore) where

import Control.Concurrent.Extra
import Control.Concurrent.STM (atomically)
Expand All @@ -31,7 +31,7 @@ import Data.Maybe
import qualified Data.Rope.UTF16 as Rope
import qualified Data.Text as T
import Data.Time
import Development.IDE.Core.OfInterest (getFilesOfInterest)
import Development.IDE.Core.OfInterest (getFilesOfInterest, OfInterestVar(..))
import Development.IDE.Core.RuleTypes
import Development.IDE.Core.Shake
import Development.IDE.GHC.Orphans ()
Expand Down Expand Up @@ -65,7 +65,7 @@ import Language.LSP.Server hiding
import qualified Language.LSP.Server as LSP
import Language.LSP.Types (FileChangeType (FcChanged),
FileEvent (FileEvent),
uriToFilePath)
uriToFilePath, toNormalizedFilePath)
import Language.LSP.VFS

makeVFSHandle :: IO VFSHandle
Expand Down Expand Up @@ -119,15 +119,20 @@ getModificationTimeRule vfs isWatched =
else return (Nothing, ([diag], Nothing))

-- | Reset the GetModificationTime state of watched files
modifyFileStore :: IdeState -> [FileEvent] -> IO ()
modifyFileStore state changes = mask $ \_ ->
resetFileStore :: IdeState -> [FileEvent] -> IO ()
resetFileStore ideState changes = mask $ \_ ->
forM_ changes $ \(FileEvent uri c) ->
case c of
FcChanged
| Just f <- uriToFilePath uri
-> do
deleteValue state (GetModificationTime_ True) (toNormalizedFilePath' f)
deleteValue state (GetModificationTime_ False) (toNormalizedFilePath' f)
-- we record FOIs document versions in all the stored values
-- so NEVER reset FOIs to avoid losing their versions
OfInterestVar foisVar <- getIdeGlobalExtras (shakeExtras ideState)
fois <- readVar foisVar
unless (HM.member (toNormalizedFilePath f) fois) $ do
deleteValue ideState (GetModificationTime_ True) (toNormalizedFilePath' f)
deleteValue ideState (GetModificationTime_ False) (toNormalizedFilePath' f)
_ -> pure ()

-- Dir.getModificationTime is surprisingly slow since it performs
Expand Down
3 changes: 2 additions & 1 deletion ghcide/src/Development/IDE/Core/OfInterest.hs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
module Development.IDE.Core.OfInterest(
ofInterestRules,
getFilesOfInterest, setFilesOfInterest, modifyFilesOfInterest,
kick, FileOfInterestStatus(..)
kick, FileOfInterestStatus(..),
OfInterestVar(..)
) where

import Control.Concurrent.Extra
Expand Down
4 changes: 2 additions & 2 deletions ghcide/src/Development/IDE/LSP/Notifications.hs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import qualified Data.Text as Text
import Control.Monad.IO.Class
import Development.IDE.Core.FileExists (modifyFileExists,
watchedGlobs)
import Development.IDE.Core.FileStore (modifyFileStore,
import Development.IDE.Core.FileStore (resetFileStore,
setFileModified,
setSomethingModified,
typecheckParents)
Expand Down Expand Up @@ -85,7 +85,7 @@ setHandlersNotifications = mconcat
let msg = Text.pack $ show fileEvents
logDebug (ideLogger ide) $ "Watched file events: " <> msg
modifyFileExists ide fileEvents
modifyFileStore ide fileEvents
resetFileStore ide fileEvents
setSomethingModified ide

, notificationHandler LSP.SWorkspaceDidChangeWorkspaceFolders $
Expand Down

0 comments on commit 2b6338e

Please sign in to comment.