@@ -8,6 +8,7 @@ module Main where
8
8
import Colog.Core
9
9
import Colog.Core qualified as L
10
10
import Control.Applicative.Combinators
11
+ import Control.Concurrent.Extra (newBarrier , waitBarrier , signalBarrier )
11
12
import Control.Exception
12
13
import Control.Lens hiding (Iso , List )
13
14
import Control.Monad
@@ -25,6 +26,7 @@ import System.Process
25
26
import Test.Hspec
26
27
import UnliftIO
27
28
import UnliftIO.Concurrent
29
+ import Debug.Trace
28
30
29
31
runSessionWithServer ::
30
32
LogAction IO (WithSeverity LspServerLog ) ->
@@ -53,7 +55,10 @@ spec = do
53
55
let logger = L. cmap show L. logStringStderr
54
56
describe " server-initiated progress reporting" $ do
55
57
it " sends updates" $ do
56
- startBarrier <- newEmptyMVar
58
+ startBarrier <- newBarrier
59
+ b1 <- newBarrier
60
+ b2 <- newBarrier
61
+ b3 <- newBarrier
57
62
58
63
let definition =
59
64
ServerDefinition
@@ -71,10 +76,13 @@ spec = do
71
76
handlers =
72
77
requestHandler (SMethod_CustomMethod (Proxy @ " something" )) $ \ _req resp -> void $ forkIO $ do
73
78
withProgress " Doing something" Nothing NotCancellable $ \ updater -> do
74
- takeMVar startBarrier
79
+ liftIO $ waitBarrier startBarrier
75
80
updater $ ProgressAmount (Just 25 ) (Just " step1" )
81
+ liftIO $ waitBarrier b1
76
82
updater $ ProgressAmount (Just 50 ) (Just " step2" )
83
+ liftIO $ waitBarrier b2
77
84
updater $ ProgressAmount (Just 75 ) (Just " step3" )
85
+ liftIO $ waitBarrier b3
78
86
79
87
runSessionWithServer logger definition Test. defaultConfig Test. fullCaps " ." $ do
80
88
Test. sendRequest (SMethod_CustomMethod (Proxy @ " something" )) J. Null
@@ -86,25 +94,28 @@ spec = do
86
94
guard $ has (L. params . L. value . _workDoneProgressBegin) x
87
95
88
96
-- allow the hander to send us updates
89
- putMVar startBarrier ()
97
+ liftIO $ signalBarrier startBarrier ()
90
98
91
99
do
92
100
u <- Test. message SMethod_Progress
93
101
liftIO $ do
94
102
u ^? L. params . L. value . _workDoneProgressReport . L. message `shouldBe` Just (Just " step1" )
95
103
u ^? L. params . L. value . _workDoneProgressReport . L. percentage `shouldBe` Just (Just 25 )
104
+ liftIO $ signalBarrier b1 ()
96
105
97
106
do
98
107
u <- Test. message SMethod_Progress
99
108
liftIO $ do
100
109
u ^? L. params . L. value . _workDoneProgressReport . L. message `shouldBe` Just (Just " step2" )
101
110
u ^? L. params . L. value . _workDoneProgressReport . L. percentage `shouldBe` Just (Just 50 )
111
+ liftIO $ signalBarrier b2 ()
102
112
103
113
do
104
114
u <- Test. message SMethod_Progress
105
115
liftIO $ do
106
116
u ^? L. params . L. value . _workDoneProgressReport . L. message `shouldBe` Just (Just " step3" )
107
117
u ^? L. params . L. value . _workDoneProgressReport . L. percentage `shouldBe` Just (Just 75 )
118
+ liftIO $ signalBarrier b3 ()
108
119
109
120
-- Then make sure we get a $/progress end notification
110
121
skipManyTill Test. anyMessage $ do
@@ -196,6 +207,11 @@ spec = do
196
207
197
208
describe " client-initiated progress reporting" $ do
198
209
it " sends updates" $ do
210
+ startBarrier <- newBarrier
211
+ b1 <- newBarrier
212
+ b2 <- newBarrier
213
+ b3 <- newBarrier
214
+
199
215
let definition =
200
216
ServerDefinition
201
217
{ parseConfig = const $ const $ Right ()
@@ -212,9 +228,13 @@ spec = do
212
228
handlers =
213
229
requestHandler SMethod_TextDocumentCodeLens $ \ req resp -> void $ forkIO $ do
214
230
withProgress " Doing something" (req ^. L. params . L. workDoneToken) NotCancellable $ \ updater -> do
231
+ liftIO $ waitBarrier startBarrier
215
232
updater $ ProgressAmount (Just 25 ) (Just " step1" )
233
+ liftIO $ waitBarrier b1
216
234
updater $ ProgressAmount (Just 50 ) (Just " step2" )
235
+ liftIO $ waitBarrier b2
217
236
updater $ ProgressAmount (Just 75 ) (Just " step3" )
237
+ liftIO $ waitBarrier b3
218
238
219
239
runSessionWithServer logger definition Test. defaultConfig Test. fullCaps " ." $ do
220
240
Test. sendRequest SMethod_TextDocumentCodeLens (CodeLensParams (Just $ ProgressToken $ InR " hello" ) Nothing (TextDocumentIdentifier $ Uri " ." ))
@@ -224,23 +244,28 @@ spec = do
224
244
x <- Test. message SMethod_Progress
225
245
guard $ has (L. params . L. value . _workDoneProgressBegin) x
226
246
247
+ liftIO $ signalBarrier startBarrier ()
248
+
227
249
do
228
250
u <- Test. message SMethod_Progress
229
251
liftIO $ do
230
252
u ^? L. params . L. value . _workDoneProgressReport . L. message `shouldBe` Just (Just " step1" )
231
253
u ^? L. params . L. value . _workDoneProgressReport . L. percentage `shouldBe` Just (Just 25 )
254
+ liftIO $ signalBarrier b1 ()
232
255
233
256
do
234
257
u <- Test. message SMethod_Progress
235
258
liftIO $ do
236
259
u ^? L. params . L. value . _workDoneProgressReport . L. message `shouldBe` Just (Just " step2" )
237
260
u ^? L. params . L. value . _workDoneProgressReport . L. percentage `shouldBe` Just (Just 50 )
261
+ liftIO $ signalBarrier b2 ()
238
262
239
263
do
240
264
u <- Test. message SMethod_Progress
241
265
liftIO $ do
242
266
u ^? L. params . L. value . _workDoneProgressReport . L. message `shouldBe` Just (Just " step3" )
243
267
u ^? L. params . L. value . _workDoneProgressReport . L. percentage `shouldBe` Just (Just 75 )
268
+ liftIO $ signalBarrier b3 ()
244
269
245
270
-- Then make sure we get a $/progress end notification
246
271
skipManyTill Test. anyMessage $ do
0 commit comments