Skip to content

Commit

Permalink
avoid double rebuilds for FOIs
Browse files Browse the repository at this point in the history
With VSCode I get a WatchedFile notification immediately after of the TextDocumentDidChange notification, triggering a second rebuild unnecessarily
  • Loading branch information
pepeiborra committed Oct 8, 2021
1 parent 9d01c13 commit b57b779
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
8 changes: 7 additions & 1 deletion ghcide/src/Development/IDE/Core/OfInterest.hs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
-- open in the editor. The rule is 'IsFileOfInterest'
module Development.IDE.Core.OfInterest(
ofInterestRules,
getFilesOfInterest,
getFilesOfInterestUntracked,
addFileOfInterest,
deleteFileOfInterest,
Expand Down Expand Up @@ -58,6 +59,11 @@ ofInterestRules = do
------------------------------------------------------------
-- Exposed API

getFilesOfInterest :: IdeState -> IO( HashMap NormalizedFilePath FileOfInterestStatus)
getFilesOfInterest state = do
OfInterestVar var <- getIdeGlobalState state
readVar var

-- | Set the files-of-interest - not usually necessary or advisable.
-- The LSP client will keep this information up to date.
setFilesOfInterest :: IdeState -> HashMap NormalizedFilePath FileOfInterestStatus -> IO ()
Expand Down Expand Up @@ -107,4 +113,4 @@ kick = do

-- if idle, perform garbage collection
liftIO $ sleep 5
garbageCollectDirtyKeys
-- garbageCollectDirtyKeys
12 changes: 10 additions & 2 deletions ghcide/src/Development/IDE/LSP/Notifications.hs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import qualified Data.HashSet as S
import qualified Data.Text as Text

import Control.Monad.IO.Class
import qualified Data.HashMap.Strict as HM
import Development.IDE.Core.FileExists (modifyFileExists,
watchedGlobs)
import Development.IDE.Core.FileStore (registerFileWatches,
Expand Down Expand Up @@ -84,8 +85,15 @@ descriptor plId = (defaultPluginDescriptor plId) { pluginNotificationHandlers =
-- what we do with them
let msg = show fileEvents
logDebug (ideLogger ide) $ "Watched file events: " <> Text.pack msg
modifyFileExists ide fileEvents
resetFileStore ide fileEvents
-- filter out files of interest, since we already know all about those
filesOfInterest <- getFilesOfInterest ide
let fileEvents' =
[ f | f@(FileEvent uri _) <- fileEvents
, Just fp <- [uriToFilePath uri]
, not $ HM.member (toNormalizedFilePath fp) filesOfInterest
]
modifyFileExists ide fileEvents'
resetFileStore ide fileEvents'
setSomethingModified ide [] msg

, mkPluginNotificationHandler LSP.SWorkspaceDidChangeWorkspaceFolders $
Expand Down

0 comments on commit b57b779

Please sign in to comment.