Skip to content

Ignore null WatchedFile events #2278

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Oct 17, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 2 additions & 6 deletions ghcide/src/Development/IDE/Core/FileExists.hs
Original file line number Diff line number Diff line change
Expand Up @@ -88,14 +88,10 @@ getFileExistsMapUntracked = do
liftIO $ readVar v

-- | Modify the global store of file exists.
modifyFileExists :: IdeState -> [FileEvent] -> IO ()
modifyFileExists :: IdeState -> [(NormalizedFilePath, FileChangeType)] -> IO ()
modifyFileExists state changes = do
FileExistsMapVar var <- getIdeGlobalState state
changesMap <- evaluate $ HashMap.fromList $
[ (toNormalizedFilePath' f, change)
| FileEvent uri change <- changes
, Just f <- [uriToFilePath uri]
]
changesMap <- evaluate $ HashMap.fromList changes
-- Masked to ensure that the previous values are flushed together with the map update
mask $ \_ -> do
-- update the map
Expand Down
19 changes: 6 additions & 13 deletions ghcide/src/Development/IDE/Core/FileStore.hs
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,12 @@ import Control.Monad.Extra
import Control.Monad.IO.Class
import qualified Data.ByteString as BS
import Data.Either.Extra
import qualified Data.HashMap.Strict as HM
import qualified Data.Map.Strict as Map
import Data.Maybe
import qualified Data.Rope.UTF16 as Rope
import qualified Data.Text as T
import Data.Time
import Data.Time.Clock.POSIX
import Development.IDE.Core.OfInterest (OfInterestVar (..))
import Development.IDE.Core.RuleTypes
import Development.IDE.Core.Shake
import Development.IDE.GHC.Orphans ()
Expand Down Expand Up @@ -74,12 +72,9 @@ import Language.LSP.Server hiding
import qualified Language.LSP.Server as LSP
import Language.LSP.Types (DidChangeWatchedFilesRegistrationOptions (DidChangeWatchedFilesRegistrationOptions),
FileChangeType (FcChanged),
FileEvent (FileEvent),
FileSystemWatcher (..),
WatchKind (..),
_watchers,
toNormalizedFilePath,
uriToFilePath)
_watchers)
import qualified Language.LSP.Types as LSP
import qualified Language.LSP.Types.Capabilities as LSP
import Language.LSP.VFS
Expand Down Expand Up @@ -170,18 +165,16 @@ resetInterfaceStore state f = do
deleteValue state GetModificationTime f

-- | Reset the GetModificationTime state of watched files
resetFileStore :: IdeState -> [FileEvent] -> IO ()
-- Assumes the list does not include any FOIs
resetFileStore :: IdeState -> [(NormalizedFilePath, FileChangeType)] -> IO ()
resetFileStore ideState changes = mask $ \_ -> do
-- 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
forM_ changes $ \(FileEvent uri c) -> do
-- FOI filtering is done by the caller (LSP Notification handler)
forM_ changes $ \(nfp, c) -> do
case c of
FcChanged
| Just f <- uriToFilePath uri
, nfp <- toNormalizedFilePath f
, not $ HM.member nfp fois
-- already checked elsewhere | not $ HM.member nfp fois
-> deleteValue (shakeExtras ideState) GetModificationTime nfp
_ -> pure ()

Expand Down
16 changes: 9 additions & 7 deletions ghcide/src/Development/IDE/LSP/Notifications.hs
Original file line number Diff line number Diff line change
Expand Up @@ -87,15 +87,17 @@ descriptor plId = (defaultPluginDescriptor plId) { pluginNotificationHandlers =
-- filter also uris that do not map to filenames, since we cannot handle them
filesOfInterest <- getFilesOfInterest ide
let fileEvents' =
[ f | f@(FileEvent uri _) <- fileEvents
[ (nfp, event) | (FileEvent uri event) <- fileEvents
, Just fp <- [uriToFilePath uri]
, not $ HM.member (toNormalizedFilePath fp) filesOfInterest
, let nfp = toNormalizedFilePath fp
, not $ HM.member nfp filesOfInterest
]
let msg = show fileEvents'
logDebug (ideLogger ide) $ "Watched file events: " <> Text.pack msg
modifyFileExists ide fileEvents'
resetFileStore ide fileEvents'
setSomethingModified ide [] msg
unless (null fileEvents') $ do
let msg = show fileEvents'
logDebug (ideLogger ide) $ "Watched file events: " <> Text.pack msg
modifyFileExists ide fileEvents'
resetFileStore ide fileEvents'
setSomethingModified ide [] msg

, mkPluginNotificationHandler LSP.SWorkspaceDidChangeWorkspaceFolders $
\ide _ (DidChangeWorkspaceFoldersParams events) -> liftIO $ do
Expand Down