Skip to content

Commit e23f7c6

Browse files
committed
schedule a GC on file close
1 parent e185bbc commit e23f7c6

File tree

6 files changed

+34
-30
lines changed

6 files changed

+34
-30
lines changed

Diff for: ghcide/src/Development/IDE/Core/FileStore.hs

+3-3
Original file line numberDiff line numberDiff line change
@@ -256,9 +256,9 @@ setFileModified state saved nfp = do
256256
ideOptions <- getIdeOptionsIO $ shakeExtras state
257257
doCheckParents <- optCheckParents ideOptions
258258
let checkParents = case doCheckParents of
259-
AlwaysCheck -> True
260-
CheckOnSaveAndClose -> saved
261-
_ -> False
259+
AlwaysCheck -> True
260+
CheckOnSave -> saved
261+
_ -> False
262262
VFSHandle{..} <- getIdeGlobalState state
263263
when (isJust setVirtualFileContents) $
264264
fail "setFileModified can't be called on this type of VFSHandle"

Diff for: ghcide/src/Development/IDE/Core/OfInterest.hs

+14-4
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ module Development.IDE.Core.OfInterest(
1515
setFilesOfInterest,
1616
kick, FileOfInterestStatus(..),
1717
OfInterestVar(..)
18-
) where
18+
,scheduleGarbageCollection) where
1919

2020
import Control.Concurrent.Strict
2121
import Control.Monad
@@ -42,6 +42,7 @@ instance IsIdeGlobal OfInterestVar
4242
ofInterestRules :: Rules ()
4343
ofInterestRules = do
4444
addIdeGlobal . OfInterestVar =<< liftIO (newVar HashMap.empty)
45+
addIdeGlobal . GarbageCollectVar =<< liftIO (newVar False)
4546
defineEarlyCutoff $ RuleNoDiagnostics $ \IsFileOfInterest f -> do
4647
alwaysRerun
4748
filesOfInterest <- getFilesOfInterestUntracked
@@ -55,6 +56,9 @@ ofInterestRules = do
5556
summarize (IsFOI (Modified False)) = BS.singleton 2
5657
summarize (IsFOI (Modified True)) = BS.singleton 3
5758

59+
------------------------------------------------------------
60+
newtype GarbageCollectVar = GarbageCollectVar (Var Bool)
61+
instance IsIdeGlobal GarbageCollectVar
5862

5963
------------------------------------------------------------
6064
-- Exposed API
@@ -94,6 +98,10 @@ deleteFileOfInterest state f = do
9498
recordDirtyKeys (shakeExtras state) IsFileOfInterest [f]
9599
logDebug (ideLogger state) $ "Set files of interest to: " <> T.pack (show files)
96100

101+
scheduleGarbageCollection :: IdeState -> IO ()
102+
scheduleGarbageCollection state = do
103+
GarbageCollectVar var <- getIdeGlobalState state
104+
writeVar var True
97105

98106
-- | Typecheck all the files of interest.
99107
-- Could be improved
@@ -111,6 +119,8 @@ kick = do
111119

112120
liftIO $ progressUpdate progress KickCompleted
113121

114-
-- if idle, perform garbage collection of dirty keys
115-
liftIO $ sleep 5
116-
void garbageCollectDirtyKeys
122+
GarbageCollectVar var <- getIdeGlobalAction
123+
garbageCollectionScheduled <- liftIO $ readVar var
124+
when garbageCollectionScheduled $ do
125+
void $ garbageCollectDirtyKeys
126+
liftIO $ writeVar var False

Diff for: ghcide/src/Development/IDE/Core/Shake.hs

+2-2
Original file line numberDiff line numberDiff line change
@@ -761,9 +761,9 @@ getHiddenDiagnostics IdeState{shakeExtras = ShakeExtras{hiddenDiagnostics}} = do
761761
-- * exports map
762762
garbageCollectDirtyKeys :: Action [Key]
763763
garbageCollectDirtyKeys = do
764-
IdeOptions{optCheckParents, optMaxDirtyAge} <- getIdeOptions
764+
IdeOptions{optCheckParents} <- getIdeOptions
765765
checkParents <- liftIO optCheckParents
766-
garbageCollectDirtyKeysOlderThan optMaxDirtyAge checkParents
766+
garbageCollectDirtyKeysOlderThan 1 checkParents
767767

768768
garbageCollectDirtyKeysOlderThan :: Int -> CheckParents -> Action [Key]
769769
garbageCollectDirtyKeysOlderThan maxAge checkParents = otTracedGarbageCollection "dirty GC" $ do

Diff for: ghcide/src/Development/IDE/LSP/Notifications.hs

+12-17
Original file line numberDiff line numberDiff line change
@@ -14,30 +14,25 @@ module Development.IDE.LSP.Notifications
1414
import Language.LSP.Types
1515
import qualified Language.LSP.Types as LSP
1616

17-
import Development.IDE.Core.IdeConfiguration
18-
import Development.IDE.Core.Service
19-
import Development.IDE.Core.Shake
20-
import Development.IDE.Types.Location
21-
import Development.IDE.Types.Logger
22-
import Development.IDE.Types.Options
23-
2417
import Control.Monad.Extra
25-
import qualified Data.HashSet as S
26-
import qualified Data.Text as Text
27-
2818
import Control.Monad.IO.Class
2919
import qualified Data.HashMap.Strict as HM
20+
import qualified Data.HashSet as S
21+
import qualified Data.Text as Text
3022
import Development.IDE.Core.FileExists (modifyFileExists,
3123
watchedGlobs)
3224
import Development.IDE.Core.FileStore (registerFileWatches,
3325
resetFileStore,
3426
setFileModified,
35-
setSomethingModified,
36-
typecheckParents)
27+
setSomethingModified)
28+
import Development.IDE.Core.IdeConfiguration
3729
import Development.IDE.Core.OfInterest
3830
import Development.IDE.Core.RuleTypes (GetClientSettings (..))
31+
import Development.IDE.Core.Service
32+
import Development.IDE.Core.Shake
33+
import Development.IDE.Types.Location
34+
import Development.IDE.Types.Logger
3935
import Development.IDE.Types.Shake (toKey)
40-
import Ide.Plugin.Config (CheckParents (CheckOnClose))
4136
import Ide.Types
4237

4338
whenUriFile :: Uri -> (NormalizedFilePath -> IO ()) -> IO ()
@@ -74,10 +69,10 @@ descriptor plId = (defaultPluginDescriptor plId) { pluginNotificationHandlers =
7469
\ide _ (DidCloseTextDocumentParams TextDocumentIdentifier{_uri}) -> liftIO $ do
7570
whenUriFile _uri $ \file -> do
7671
deleteFileOfInterest ide file
77-
-- Refresh all the files that depended on this
78-
checkParents <- optCheckParents =<< getIdeOptionsIO (shakeExtras ide)
79-
when (checkParents >= CheckOnClose) $ typecheckParents ide file
80-
logDebug (ideLogger ide) $ "Closed text document: " <> getUri _uri
72+
let msg = "Closed text document: " <> getUri _uri
73+
scheduleGarbageCollection ide
74+
setSomethingModified ide [] $ Text.unpack msg
75+
logDebug (ideLogger ide) msg
8176

8277
, mkPluginNotificationHandler LSP.SWorkspaceDidChangeWatchedFiles $
8378
\ide _ (DidChangeWatchedFilesParams (List fileEvents)) -> liftIO $ do

Diff for: ghcide/src/Development/IDE/Types/Options.hs

+1-1
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ defaultIdeOptions session = IdeOptions
139139
,optDefer = IdeDefer True
140140
,optTesting = IdeTesting False
141141
,optCheckProject = pure True
142-
,optCheckParents = pure CheckOnSaveAndClose
142+
,optCheckParents = pure CheckOnSave
143143
,optHaddockParse = HaddockParse
144144
,optModifyDynFlags = mempty
145145
,optSkipProgress = defaultSkipProgress

Diff for: hls-plugin-api/src/Ide/Plugin/Config.hs

+2-3
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,7 @@ data CheckParents
3737
-- Note that ordering of constructors is meaningful and must be monotonically
3838
-- increasing in the scenarios where parents are checked
3939
= NeverCheck
40-
| CheckOnClose
41-
| CheckOnSaveAndClose
40+
| CheckOnSave
4241
| AlwaysCheck
4342
deriving stock (Eq, Ord, Show, Generic)
4443
deriving anyclass (FromJSON, ToJSON)
@@ -61,7 +60,7 @@ data Config =
6160

6261
instance Default Config where
6362
def = Config
64-
{ checkParents = CheckOnSaveAndClose
63+
{ checkParents = CheckOnSave
6564
, checkProject = True
6665
, hlintOn = True
6766
, diagnosticsOnChange = True

0 commit comments

Comments
 (0)