on master help sign in
#599. register FileExistsMapVar global unconditionally (#600)
commit51907fe47a74308ff5c04f9eccd124d292bbaa5f authorNeil Mitchell <ndmitchell@gmail.com> dateTue 2 Jun 2020, 09:24 (6 years ago) parent3c6c547
1 file changed+15−11
src/Development/IDE/Core/FileExists.hs+15−11
src/Development/IDE/Core/FileExists.hs+15−11
@@ -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.
9393fileExistsRules :: 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.
105110fileExistsRulesFast :: 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