Skip to content

Commit 1e1e044

Browse files
committed
use AsyncParentKill exception to cancel session, minor imporvement to Step type.
1 parent 19ce7ff commit 1e1e044

File tree

4 files changed

+14
-16
lines changed

4 files changed

+14
-16
lines changed

ghcide/src/Development/IDE/Core/Shake.hs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,8 @@ import Development.IDE.GHC.Orphans ()
140140
import Development.IDE.Graph hiding (ShakeValue,
141141
action)
142142
import qualified Development.IDE.Graph as Shake
143-
import Development.IDE.Graph.Database (ShakeDatabase,
143+
import Development.IDE.Graph.Database (AsyncParentKill (..),
144+
ShakeDatabase,
144145
shakeGetBuildStep,
145146
shakeGetDatabaseKeys,
146147
shakeNewDatabase,
@@ -908,8 +909,11 @@ newSession recorder extras@ShakeExtras{..} vfsMod shakeDb acts reason = do
908909

909910
-- Cancelling is required to flush the Shake database when either
910911
-- the filesystem or the Ghc configuration have changed
912+
step <- shakeGetBuildStep shakeDb
911913
let cancelShakeSession :: IO ()
912-
cancelShakeSession = cancel workThread
914+
cancelShakeSession = do
915+
tid <- myThreadId
916+
cancelWith workThread $ AsyncParentKill tid step
913917

914918
pure (ShakeSession{..})
915919

ghcide/src/Development/IDE/Plugin/Test.hs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,7 @@ import Development.IDE.Graph.Database (ShakeDatabase,
3838
shakeGetBuildEdges,
3939
shakeGetBuildStep,
4040
shakeGetCleanKeys)
41-
import Development.IDE.Graph.Internal.Types (Result (resultBuilt, resultChanged, resultVisited),
42-
Step (Step))
41+
import Development.IDE.Graph.Internal.Types (Result (resultBuilt, resultChanged, resultVisited))
4342
import qualified Development.IDE.Graph.Internal.Types as Graph
4443
import Development.IDE.Types.Action
4544
import Development.IDE.Types.HscEnvEq (HscEnvEq (hscEnv))
@@ -145,7 +144,7 @@ getDatabaseKeys :: (Graph.Result -> Step)
145144
getDatabaseKeys field db = do
146145
keys <- shakeGetCleanKeys db
147146
step <- shakeGetBuildStep db
148-
return [ k | (k, res) <- keys, field res == Step step]
147+
return [ k | (k, res) <- keys, field res == step]
149148

150149
parseAction :: CI String -> NormalizedFilePath -> Action (Either Text Bool)
151150
parseAction "typecheck" fp = Right . isJust <$> use TypeCheck fp

hls-graph/src/Development/IDE/Graph/Database.hs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
module Development.IDE.Graph.Database(
2+
AsyncParentKill(..),
23
ShakeDatabase,
34
ShakeValue,
45
shakeNewDatabase,
@@ -8,8 +9,8 @@ module Development.IDE.Graph.Database(
89
shakeGetBuildStep,
910
shakeGetDatabaseKeys,
1011
shakeGetDirtySet,
11-
shakeGetCleanKeys
12-
,shakeGetBuildEdges) where
12+
shakeGetCleanKeys,
13+
shakeGetBuildEdges) where
1314
import Control.Concurrent.STM.Stats (readTVarIO)
1415
import Data.Dynamic
1516
import Data.Maybe
@@ -42,9 +43,9 @@ shakeGetDirtySet (ShakeDatabase _ _ db) =
4243
Development.IDE.Graph.Internal.Database.getDirtySet db
4344

4445
-- | Returns the build number
45-
shakeGetBuildStep :: ShakeDatabase -> IO Int
46+
shakeGetBuildStep :: ShakeDatabase -> IO Step
4647
shakeGetBuildStep (ShakeDatabase _ _ db) = do
47-
Step s <- readTVarIO $ databaseStep db
48+
s <- readTVarIO $ databaseStep db
4849
return s
4950

5051
-- Only valid if we never pull on the results, which we don't

hls-graph/src/Development/IDE/Graph/Internal/Types.hs

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -88,13 +88,7 @@ getDatabase = Action $ asks actionDatabase
8888
data ShakeDatabase = ShakeDatabase !Int [Action ()] Database
8989

9090
newtype Step = Step Int
91-
deriving newtype (Eq,Ord,Hashable,Show)
92-
93-
94-
getShakeStep :: MonadIO m => ShakeDatabase -> m Step
95-
getShakeStep (ShakeDatabase _ _ db) = do
96-
s <- readTVarIO $ databaseStep db
97-
return s
91+
deriving newtype (Eq,Ord,Hashable,Show,Num,Enum,Real,Integral)
9892

9993
---------------------------------------------------------------------
10094
-- Keys

0 commit comments

Comments
 (0)