@@ -23,24 +23,31 @@ import Control.Concurrent.STM (STM)
23
23
import Control.Concurrent.STM.Stats (TVar , atomically ,
24
24
atomicallyNamed , modifyTVar' ,
25
25
newTVarIO , readTVar , retry )
26
- import Control.Concurrent.Strict (modifyVar_ , newVar ,
27
- threadDelay )
26
+ import Control.Concurrent.Strict (modifyVar_ , newBarrier , newVar ,
27
+ signalBarrier , threadDelay ,
28
+ waitBarrier )
28
29
import Control.Monad.Extra hiding (loop )
29
30
import Control.Monad.IO.Class
30
31
import Control.Monad.Trans.Class (lift )
32
+ import qualified Data.Aeson as J
31
33
import Data.Functor (($>) )
32
34
import qualified Data.Text as T
35
+ import Data.Unique (hashUnique , newUnique )
33
36
import Development.IDE.GHC.Orphans ()
34
37
import Development.IDE.Types.Location
35
38
import Development.IDE.Types.Options
36
39
import qualified Focus
40
+ import Language.LSP.Protocol.Message
37
41
import Language.LSP.Protocol.Types
38
- import Language.LSP.Server (ProgressAmount (.. ),
42
+ import qualified Language.LSP.Protocol.Types as L
43
+ import Language.LSP.Server (MonadLsp , ProgressAmount (.. ),
39
44
ProgressCancellable (.. ),
45
+ sendNotification , sendRequest ,
40
46
withProgress )
41
47
import qualified Language.LSP.Server as LSP
42
48
import qualified StmContainers.Map as STM
43
49
import UnliftIO (Async , async , bracket , cancel )
50
+ import qualified UnliftIO.Exception as UE
44
51
45
52
data ProgressEvent
46
53
= ProgressNewStarted
@@ -168,7 +175,7 @@ progressReportingNoTrace todo done (Just lspEnv) title optProgressStyle = do
168
175
let _progressUpdate event = liftIO $ updateStateVar $ Event event
169
176
_progressStop = updateStateVar StopProgress
170
177
updateStateVar = modifyVar_ progressState . updateState (progressCounter lspEnv title optProgressStyle todo done)
171
- return ProgressReporting {.. }
178
+ return ProgressReporting {_progressUpdate, _progressStop }
172
179
173
180
-- | `progressReporting` initiates a new progress reporting session.
174
181
-- It necessitates the active tracking of progress using the `inProgress` function.
@@ -196,6 +203,25 @@ progressReporting (Just lspEnv) title optProgressStyle = do
196
203
197
204
f = recordProgress inProgress file
198
205
206
+ withProgressDummy ::
207
+ forall c m a .
208
+ MonadLsp c m =>
209
+ T. Text ->
210
+ Maybe ProgressToken ->
211
+ ProgressCancellable ->
212
+ ((ProgressAmount -> m () ) -> m a ) ->
213
+ m a
214
+ withProgressDummy title _ _ f = do
215
+ t <- L. ProgressToken . L. InR . T. pack . show . hashUnique <$> liftIO newUnique
216
+ r <- liftIO newBarrier
217
+ _ <- sendRequest SMethod_WindowWorkDoneProgressCreate (WorkDoneProgressCreateParams t) $
218
+ \ _ -> liftIO $ signalBarrier r ()
219
+ -- liftIO $ waitBarrier r
220
+ sendProgressReport t $ WorkDoneProgressBegin L. AString title Nothing Nothing Nothing
221
+ f (const $ return () ) `UE.finally` sendProgressReport t (WorkDoneProgressEnd L. AString Nothing )
222
+ where
223
+ sendProgressReport token report = sendNotification SMethod_Progress $ ProgressParams token $ J. toJSON report
224
+
199
225
-- Kill this to complete the progress session
200
226
progressCounter ::
201
227
LSP. LanguageContextEnv c ->
@@ -205,8 +231,12 @@ progressCounter ::
205
231
STM Int ->
206
232
IO ()
207
233
progressCounter lspEnv title optProgressStyle getTodo getDone =
208
- LSP. runLspT lspEnv $ withProgress title Nothing NotCancellable $ \ update -> loop update 0
234
+ LSP. runLspT lspEnv $ withProgressChoice title Nothing NotCancellable $ \ update -> loop update 0
209
235
where
236
+ withProgressChoice = case optProgressStyle of
237
+ TestReporting -> withProgressDummy
238
+ _ -> withProgress
239
+
210
240
loop _ _ | optProgressStyle == NoProgress = forever $ liftIO $ threadDelay maxBound
211
241
loop update prevPct = do
212
242
(todo, done, nextPct) <- liftIO $ atomically $ do
0 commit comments