@@ -11,33 +11,40 @@ module Development.IDE.Plugin.Test
1111 , blockCommandId
1212 ) where
1313
14- import Control.Concurrent (threadDelay )
15- import Control.Concurrent.Extra (readVar )
14+ import Control.Concurrent (threadDelay )
15+ import Control.Concurrent.Extra (readVar )
1616import Control.Monad
1717import Control.Monad.IO.Class
1818import Control.Monad.STM
1919import Data.Aeson
2020import Data.Aeson.Types
2121import 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 )
2525import 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 )
2828import Development.IDE.Core.RuleTypes
2929import Development.IDE.Core.Service
3030import Development.IDE.Core.Shake
3131import 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
3441import 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 )
3946import Ide.Types
40- import qualified Language.LSP.Server as LSP
47+ import qualified Language.LSP.Server as LSP
4148import Language.LSP.Types
4249import System.Time.Extra
4350
@@ -48,7 +55,10 @@ data TestRequest
4855 | GetShakeSessionQueueCount -- ^ :: Number
4956 | WaitForShakeQueue -- ^ Block until the Shake queue is empty. Returns Null
5057 | WaitForIdeRule String Uri -- ^ :: WaitForIdeRuleResult
51- | GetLastBuildKeys -- ^ :: [String]
58+ | GetBuildKeysVisited -- ^ :: [(String]
59+ | GetBuildKeysBuilt -- ^ :: [(String]
60+ | GetBuildKeysChanged -- ^ :: [(String]
61+ | GetBuildEdgesCount -- ^ :: Int
5262 | GarbageCollectDirtyKeys CheckParents Age -- ^ :: [String] (list of keys collected)
5363 | GetStoredKeys -- ^ :: [String] (list of keys in store)
5464 | GetFilesOfInterest -- ^ :: [FilePath]
@@ -98,9 +108,18 @@ testRequestHandler s (WaitForIdeRule k file) = liftIO $ do
98108 success <- runAction (" WaitForIdeRule " <> k <> " " <> show file) s $ parseAction (fromString k) nfp
99109 let res = WaitForIdeRuleResult <$> success
100110 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
103113 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
104123testRequestHandler s (GarbageCollectDirtyKeys parents age) = do
105124 res <- liftIO $ runAction " garbage collect dirty" s $ garbageCollectDirtyKeysOlderThan age parents
106125 return $ Right $ toJSON $ map show res
@@ -111,6 +130,14 @@ testRequestHandler s GetFilesOfInterest = do
111130 ff <- liftIO $ getFilesOfInterest s
112131 return $ Right $ toJSON $ map fromNormalizedFilePath $ HM. keys ff
113132
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+
114141mkResponseError :: Text -> ResponseError
115142mkResponseError msg = ResponseError InvalidRequest msg Nothing
116143
0 commit comments