Skip to content

Commit 51907fe

Browse files
authored
#599. register FileExistsMapVar global unconditionally (#600)
1 parent 3c6c547 commit 51907fe

File tree

1 file changed

+15
-11
lines changed

1 file changed

+15
-11
lines changed

src/Development/IDE/Core/FileExists.hs

+15-11
Original file line numberDiff line numberDiff line change
@@ -91,20 +91,24 @@ getFileExists fp = use_ GetFileExists fp
9191
-- Provides a fast implementation if client supports dynamic watched files.
9292
-- Creates a global state as a side effect in that case.
9393
fileExistsRules :: IO LspId -> ClientCapabilities -> VFSHandle -> Rules ()
94-
fileExistsRules getLspId ClientCapabilities{_workspace} vfs
95-
| Just WorkspaceClientCapabilities{_didChangeWatchedFiles} <- _workspace
96-
, Just DidChangeWatchedFilesClientCapabilities{_dynamicRegistration} <- _didChangeWatchedFiles
97-
, Just True <- _dynamicRegistration
98-
= fileExistsRulesFast getLspId vfs
99-
| otherwise = do
100-
logger <- logger <$> getShakeExtrasRules
101-
liftIO $ logDebug logger "Warning: Client does not support watched files. Falling back to OS polling"
102-
fileExistsRulesSlow vfs
94+
fileExistsRules getLspId ClientCapabilities{_workspace} vfs = do
95+
-- Create the global always, although it should only be used if we have fast rules.
96+
-- But there's a chance someone will send unexpected notifications anyway,
97+
-- e.g. https://github.com/digital-asset/ghcide/issues/599
98+
addIdeGlobal . FileExistsMapVar =<< liftIO (newVar [])
99+
case () of
100+
_ | Just WorkspaceClientCapabilities{_didChangeWatchedFiles} <- _workspace
101+
, Just DidChangeWatchedFilesClientCapabilities{_dynamicRegistration} <- _didChangeWatchedFiles
102+
, Just True <- _dynamicRegistration
103+
-> fileExistsRulesFast getLspId vfs
104+
| otherwise -> do
105+
logger <- logger <$> getShakeExtrasRules
106+
liftIO $ logDebug logger "Warning: Client does not support watched files. Falling back to OS polling"
107+
fileExistsRulesSlow vfs
103108

104109
-- Requires an lsp client that provides WatchedFiles notifications.
105110
fileExistsRulesFast :: IO LspId -> VFSHandle -> Rules ()
106-
fileExistsRulesFast getLspId vfs = do
107-
addIdeGlobal . FileExistsMapVar =<< liftIO (newVar [])
111+
fileExistsRulesFast getLspId vfs =
108112
defineEarlyCutoff $ \GetFileExists file -> do
109113
isWf <- isWorkspaceFile file
110114
if isWf

0 commit comments

Comments
 (0)