Skip to content

Commit 89015d3

Browse files
committed
Fix code actions after cradle edit experiment
1 parent 58dad3d commit 89015d3

File tree

1 file changed

+25
-17
lines changed

1 file changed

+25
-17
lines changed

ghcide/bench/lib/Experiments.hs

+25-17
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,11 @@ module Experiments
2323
) where
2424
import Control.Applicative.Combinators (skipManyTill)
2525
import Control.Exception.Safe (IOException, handleAny, try)
26+
import Control.Lens ((^.))
2627
import Control.Monad.Extra
2728
import Control.Monad.IO.Class
2829
import Data.Aeson (Value (Null), toJSON)
30+
import Data.Coerce (coerce)
2931
import Data.List
3032
import Data.Maybe
3133
import qualified Data.Text as T
@@ -41,6 +43,7 @@ import Language.LSP.Types hiding
4143
SemanticTokenRelative (length),
4244
SemanticTokensEdit (_start))
4345
import Language.LSP.Types.Capabilities
46+
import Language.LSP.Types.Lens (diagnostics, params, uri)
4447
import Numeric.Natural
4548
import Options.Applicative
4649
import System.Directory
@@ -152,21 +155,22 @@ experiments =
152155
benchWithSetup
153156
"code actions after cradle edit"
154157
( \docs -> do
155-
unless (any (isJust . identifierP) docs) $
156-
error "None of the example modules is suitable for this experiment"
157-
forM_ docs $ \DocumentPositions{..} ->
158-
forM_ identifierP $ \p -> changeDoc doc [charEdit p]
158+
forM_ docs $ \DocumentPositions{..} -> do
159+
forM identifierP $ \p -> do
160+
changeDoc doc [charEdit p]
161+
waitForProgressStart
162+
void waitForBuildQueue
159163
)
160164
( \docs -> do
161165
hieYamlUri <- getDocUri "hie.yaml"
162166
liftIO $ appendFile (fromJust $ uriToFilePath hieYamlUri) "##\n"
163167
sendNotification SWorkspaceDidChangeWatchedFiles $ DidChangeWatchedFilesParams $
164168
List [ FileEvent hieYamlUri FcChanged ]
165-
forM_ docs $ \DocumentPositions{..} -> do
166-
changeDoc doc [charEdit stringLiteralP]
167-
waitForProgressStart
169+
waitForProgressStart
170+
waitForProgressStart
171+
waitForProgressStart -- the Session logic restarts a second time
168172
waitForProgressDone
169-
not . null . catMaybes <$> forM docs (\DocumentPositions{..} -> do
173+
not . null . concat . catMaybes <$> forM docs (\DocumentPositions{..} -> do
170174
forM identifierP $ \p ->
171175
getCodeActions doc (Range p p))
172176
),
@@ -421,6 +425,17 @@ waitForProgressDone = loop
421425
done <- null <$> getIncompleteProgressSessions
422426
unless done loop
423427

428+
-- | Wait for the build queue to be empty
429+
waitForBuildQueue :: Session Seconds
430+
waitForBuildQueue = do
431+
let m = SCustomMethod "test"
432+
waitId <- sendRequest m (toJSON WaitForShakeQueue)
433+
(td, resp) <- duration $ skipManyTill anyMessage $ responseForId m waitId
434+
case resp of
435+
ResponseMessage{_result=Right Null} -> return td
436+
-- assume a ghcide binary lacking the WaitForShakeQueue method
437+
_ -> return 0
438+
424439
runBench ::
425440
(?config :: Config) =>
426441
(Session BenchRun -> IO BenchRun) ->
@@ -451,15 +466,8 @@ runBench runSess b = handleAny (\e -> print e >> return badRun)
451466
else do
452467
output (showDuration t)
453468
-- Wait for the delayed actions to finish
454-
let m = SCustomMethod "test"
455-
waitId <- sendRequest m (toJSON WaitForShakeQueue)
456-
(td, resp) <- duration $ skipManyTill anyMessage $ responseForId m waitId
457-
case resp of
458-
ResponseMessage{_result=Right Null} -> do
459-
loop (userWaits+t) (delayedWork+td) (n -1)
460-
_ ->
461-
-- Assume a ghcide build lacking the WaitForShakeQueue command
462-
loop (userWaits+t) delayedWork (n -1)
469+
td <- waitForBuildQueue
470+
loop (userWaits+t) (delayedWork+td) (n -1)
463471

464472
(runExperiment, result) <- duration $ loop 0 0 samples
465473
let success = isJust result

0 commit comments

Comments
 (0)