@@ -11,33 +11,40 @@ module Development.IDE.Plugin.Test
11
11
, blockCommandId
12
12
) where
13
13
14
- import Control.Concurrent (threadDelay )
15
- import Control.Concurrent.Extra (readVar )
14
+ import Control.Concurrent (threadDelay )
15
+ import Control.Concurrent.Extra (readVar )
16
16
import Control.Monad
17
17
import Control.Monad.IO.Class
18
18
import Control.Monad.STM
19
19
import Data.Aeson
20
20
import Data.Aeson.Types
21
21
import Data.Bifunctor
22
- import Data.CaseInsensitive (CI , original )
23
- import qualified Data.HashMap.Strict as HM
24
- import Data.Maybe (isJust )
22
+ import Data.CaseInsensitive (CI , original )
23
+ import qualified Data.HashMap.Strict as HM
24
+ import Data.Maybe (isJust )
25
25
import Data.String
26
- import Data.Text (Text , pack )
27
- import Development.IDE.Core.OfInterest (getFilesOfInterest )
26
+ import Data.Text (Text , pack )
27
+ import Development.IDE.Core.OfInterest (getFilesOfInterest )
28
28
import Development.IDE.Core.RuleTypes
29
29
import Development.IDE.Core.Service
30
30
import Development.IDE.Core.Shake
31
31
import Development.IDE.GHC.Compat
32
- import Development.IDE.Graph (Action )
33
- import Development.IDE.Graph.Database (shakeLastBuildKeys )
32
+ import Development.IDE.Graph (Action )
33
+ import qualified Development.IDE.Graph as Graph
34
+ import Development.IDE.Graph.Database (ShakeDatabase ,
35
+ shakeGetBuildEdges ,
36
+ shakeGetBuildStep ,
37
+ shakeGetCleanKeys )
38
+ import Development.IDE.Graph.Internal.Types (Result (resultBuilt , resultChanged , resultVisited ),
39
+ Step (Step ))
40
+ import qualified Development.IDE.Graph.Internal.Types as Graph
34
41
import Development.IDE.Types.Action
35
- import Development.IDE.Types.HscEnvEq (HscEnvEq (hscEnv ))
36
- import Development.IDE.Types.Location (fromUri )
37
- import GHC.Generics (Generic )
38
- import Ide.Plugin.Config (CheckParents )
42
+ import Development.IDE.Types.HscEnvEq (HscEnvEq (hscEnv ))
43
+ import Development.IDE.Types.Location (fromUri )
44
+ import GHC.Generics (Generic )
45
+ import Ide.Plugin.Config (CheckParents )
39
46
import Ide.Types
40
- import qualified Language.LSP.Server as LSP
47
+ import qualified Language.LSP.Server as LSP
41
48
import Language.LSP.Types
42
49
import System.Time.Extra
43
50
@@ -48,7 +55,10 @@ data TestRequest
48
55
| GetShakeSessionQueueCount -- ^ :: Number
49
56
| WaitForShakeQueue -- ^ Block until the Shake queue is empty. Returns Null
50
57
| WaitForIdeRule String Uri -- ^ :: WaitForIdeRuleResult
51
- | GetLastBuildKeys -- ^ :: [String]
58
+ | GetBuildKeysVisited -- ^ :: [(String]
59
+ | GetBuildKeysBuilt -- ^ :: [(String]
60
+ | GetBuildKeysChanged -- ^ :: [(String]
61
+ | GetBuildEdgesCount -- ^ :: Int
52
62
| GarbageCollectDirtyKeys CheckParents Age -- ^ :: [String] (list of keys collected)
53
63
| GetStoredKeys -- ^ :: [String] (list of keys in store)
54
64
| GetFilesOfInterest -- ^ :: [FilePath]
@@ -98,9 +108,18 @@ testRequestHandler s (WaitForIdeRule k file) = liftIO $ do
98
108
success <- runAction (" WaitForIdeRule " <> k <> " " <> show file) s $ parseAction (fromString k) nfp
99
109
let res = WaitForIdeRuleResult <$> success
100
110
return $ bimap mkResponseError toJSON res
101
- testRequestHandler s GetLastBuildKeys = liftIO $ do
102
- keys <- shakeLastBuildKeys $ shakeDb s
111
+ testRequestHandler s GetBuildKeysBuilt = liftIO $ do
112
+ keys <- getDatabaseKeys resultBuilt $ shakeDb s
103
113
return $ Right $ toJSON $ map show keys
114
+ testRequestHandler s GetBuildKeysChanged = liftIO $ do
115
+ keys <- getDatabaseKeys resultChanged $ shakeDb s
116
+ return $ Right $ toJSON $ map show keys
117
+ testRequestHandler s GetBuildKeysVisited = liftIO $ do
118
+ keys <- getDatabaseKeys resultVisited $ shakeDb s
119
+ return $ Right $ toJSON $ map show keys
120
+ testRequestHandler s GetBuildEdgesCount = liftIO $ do
121
+ count <- shakeGetBuildEdges $ shakeDb s
122
+ return $ Right $ toJSON count
104
123
testRequestHandler s (GarbageCollectDirtyKeys parents age) = do
105
124
res <- liftIO $ runAction " garbage collect dirty" s $ garbageCollectDirtyKeysOlderThan age parents
106
125
return $ Right $ toJSON $ map show res
@@ -111,6 +130,14 @@ testRequestHandler s GetFilesOfInterest = do
111
130
ff <- liftIO $ getFilesOfInterest s
112
131
return $ Right $ toJSON $ map fromNormalizedFilePath $ HM. keys ff
113
132
133
+ getDatabaseKeys :: (Graph. Result -> Step )
134
+ -> ShakeDatabase
135
+ -> IO [Graph. Key ]
136
+ getDatabaseKeys field db = do
137
+ keys <- shakeGetCleanKeys db
138
+ step <- shakeGetBuildStep db
139
+ return [ k | (k, res) <- keys, field res == Step step]
140
+
114
141
mkResponseError :: Text -> ResponseError
115
142
mkResponseError msg = ResponseError InvalidRequest msg Nothing
116
143
0 commit comments