@@ -23,9 +23,11 @@ module Experiments
23
23
) where
24
24
import Control.Applicative.Combinators (skipManyTill )
25
25
import Control.Exception.Safe (IOException , handleAny , try )
26
+ import Control.Lens ((^.) )
26
27
import Control.Monad.Extra
27
28
import Control.Monad.IO.Class
28
29
import Data.Aeson (Value (Null ), toJSON )
30
+ import Data.Coerce (coerce )
29
31
import Data.List
30
32
import Data.Maybe
31
33
import qualified Data.Text as T
@@ -41,6 +43,7 @@ import Language.LSP.Types hiding
41
43
SemanticTokenRelative (length ),
42
44
SemanticTokensEdit (_start ))
43
45
import Language.LSP.Types.Capabilities
46
+ import Language.LSP.Types.Lens (diagnostics , params , uri )
44
47
import Numeric.Natural
45
48
import Options.Applicative
46
49
import System.Directory
@@ -152,21 +155,22 @@ experiments =
152
155
benchWithSetup
153
156
" code actions after cradle edit"
154
157
( \ 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
159
163
)
160
164
( \ docs -> do
161
165
hieYamlUri <- getDocUri " hie.yaml"
162
166
liftIO $ appendFile (fromJust $ uriToFilePath hieYamlUri) " ##\n "
163
167
sendNotification SWorkspaceDidChangeWatchedFiles $ DidChangeWatchedFilesParams $
164
168
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
168
172
waitForProgressDone
169
- not . null . catMaybes <$> forM docs (\ DocumentPositions {.. } -> do
173
+ not . null . concat . catMaybes <$> forM docs (\ DocumentPositions {.. } -> do
170
174
forM identifierP $ \ p ->
171
175
getCodeActions doc (Range p p))
172
176
),
@@ -421,6 +425,17 @@ waitForProgressDone = loop
421
425
done <- null <$> getIncompleteProgressSessions
422
426
unless done loop
423
427
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
+
424
439
runBench ::
425
440
(? config :: Config ) =>
426
441
(Session BenchRun -> IO BenchRun ) ->
@@ -451,15 +466,8 @@ runBench runSess b = handleAny (\e -> print e >> return badRun)
451
466
else do
452
467
output (showDuration t)
453
468
-- 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 )
463
471
464
472
(runExperiment, result) <- duration $ loop 0 0 samples
465
473
let success = isJust result
0 commit comments