Skip to content
This repository has been archived by the owner on Jan 2, 2021. It is now read-only.

Fix performance of getFileExists #322

Merged
merged 17 commits into from
Jan 21, 2020
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Proper creation of request id
  • Loading branch information
pepeiborra committed Jan 13, 2020
commit 6af5073f69800879a455d59c5b89a9bcfb2901d3
12 changes: 6 additions & 6 deletions src/Development/IDE/Core/FileExists.hs
Original file line number Diff line number Diff line change
@@ -75,17 +75,17 @@ getFileExists fp = use_ GetFileExists fp
-- | Installs the 'getFileExists' rules.
-- Provides a fast implementation if client supports dynamic watched files.
-- Creates a global state as a side effect in that case.
fileExistsRules :: ClientCapabilities -> (NormalizedFilePath -> Action Bool) -> Rules ()
fileExistsRules ClientCapabilities{_workspace}
fileExistsRules :: IO LspId -> ClientCapabilities -> (NormalizedFilePath -> Action Bool) -> Rules ()
fileExistsRules getLspId ClientCapabilities{_workspace}
| Just WorkspaceClientCapabilities{_didChangeWatchedFiles} <- _workspace
, Just DidChangeWatchedFilesClientCapabilities{_dynamicRegistration} <- _didChangeWatchedFiles
, Just True <- _dynamicRegistration
= fileExistsRulesFast
= fileExistsRulesFast getLspId
| otherwise = fileExistsRulesSlow

-- Requires an lsp client that provides WatchedFiles notifications.
fileExistsRulesFast :: (NormalizedFilePath -> Action Bool) -> Rules ()
fileExistsRulesFast getFileExists = do
fileExistsRulesFast :: IO LspId -> (NormalizedFilePath -> Action Bool) -> Rules ()
fileExistsRulesFast getLspId getFileExists = do
addIdeGlobal . FileExistsMapVar =<< liftIO (newVar [])
defineEarlyCutoff $ \GetFileExists file -> do
fileExistsMap <- getFileExistsMapUntracked
pepeiborra marked this conversation as resolved.
Show resolved Hide resolved
@@ -107,9 +107,9 @@ fileExistsRulesFast getFileExists = do
where
createKey = Just . BS.toStrict . encode
addListener eventer fp = do
reqId <- getLspId
let
req = RequestMessage "2.0" reqId ClientRegisterCapability regParams
reqId = IdString fpAsId
fpAsId = T.pack $ fromNormalizedFilePath fp
regParams = RegistrationParams (List [registration])
registration = Registration fpAsId
2 changes: 1 addition & 1 deletion src/Development/IDE/Core/Service.hs
Original file line number Diff line number Diff line change
@@ -66,7 +66,7 @@ initialise caps mainRule getLspId toDiags logger options vfs =
addIdeGlobal $ GlobalIdeOptions options
fileStoreRules vfs
ofInterestRules
fileExistsRules caps (liftIO . getFileExists vfs)
fileExistsRules getLspId caps (liftIO . getFileExists vfs)
mainRule

writeProfile :: IdeState -> FilePath -> IO ()