Skip to content

Commit a8a7c0a

Browse files
committed
Enhance testing progress reporting
- Introduce TestReporting style for progress reporting in IDE options.
1 parent 9b952c8 commit a8a7c0a

File tree

4 files changed

+74
-39
lines changed

4 files changed

+74
-39
lines changed

.github/workflows/test.yml

Lines changed: 32 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -114,18 +114,18 @@ jobs:
114114
- if: needs.pre_job.outputs.should_skip_ghcide != 'true' && matrix.test
115115
name: Test ghcide
116116
# run the tests without parallelism to avoid running out of memory
117-
run: cabal test ghcide-tests || cabal test ghcide-tests
117+
run: cabal test ghcide-tests
118118

119119
- if: matrix.test
120120
name: Test hls-plugin-api
121-
run: cabal test hls-plugin-api || cabal test hls-plugin-api
121+
run: cabal test hls-plugin-api
122122

123123
- if: matrix.test
124124
name: Test func-test suite
125125
env:
126126
HLS_TEST_EXE: hls
127127
HLS_WRAPPER_TEST_EXE: hls-wrapper
128-
run: cabal test func-test || cabal test func-test
128+
run: cabal test func-test
129129

130130
- if: matrix.test
131131
name: Test wrapper-test suite
@@ -136,124 +136,124 @@ jobs:
136136

137137
- if: matrix.test
138138
name: Test hls-refactor-plugin
139-
run: cabal test hls-refactor-plugin-tests || cabal test hls-refactor-plugin-tests
139+
run: cabal test hls-refactor-plugin-tests
140140

141141
# TODO enable when it supports 9.10
142142
- if: matrix.test && matrix.ghc != '9.10' && matrix.ghc != '9.12'
143143
name: Test hls-floskell-plugin
144-
run: cabal test hls-floskell-plugin-tests || cabal test hls-floskell-plugin-tests
144+
run: cabal test hls-floskell-plugin-tests
145145

146146
- if: matrix.test
147147
name: Test hls-class-plugin
148-
run: cabal test hls-class-plugin-tests || cabal test hls-class-plugin-tests
148+
run: cabal test hls-class-plugin-tests
149149

150150
- if: matrix.test
151151
name: Test hls-pragmas-plugin
152-
run: cabal test hls-pragmas-plugin-tests || cabal test hls-pragmas-plugin-tests
152+
run: cabal test hls-pragmas-plugin-tests
153153

154154
- if: matrix.test
155155
name: Test hls-eval-plugin
156-
run: cabal test hls-eval-plugin-tests || cabal test hls-eval-plugin-tests
156+
run: cabal test hls-eval-plugin-tests
157157

158158
# TODO enable when it supports 9.10
159159
- if: matrix.test && matrix.ghc != '9.10' && matrix.ghc != '9.12'
160160
name: Test hls-splice-plugin
161-
run: cabal test hls-splice-plugin-tests || cabal test hls-splice-plugin-tests
161+
run: cabal test hls-splice-plugin-tests
162162

163163
- if: matrix.test && matrix.ghc != '9.12'
164164
name: Test hls-stan-plugin
165-
run: cabal test hls-stan-plugin-tests || cabal test hls-stan-plugin-tests
165+
run: cabal test hls-stan-plugin-tests
166166

167167
- if: matrix.test
168168
name: Test hls-stylish-haskell-plugin
169-
run: cabal test hls-stylish-haskell-plugin-tests || cabal test hls-stylish-haskell-plugin-tests
169+
run: cabal test hls-stylish-haskell-plugin-tests
170170

171171
- if: matrix.test
172172
name: Test hls-ormolu-plugin
173-
run: cabal test hls-ormolu-plugin-tests || cabal test hls-ormolu-plugin-tests
173+
run: cabal test hls-ormolu-plugin-tests
174174

175175
- if: matrix.test
176176
name: Test hls-fourmolu-plugin
177-
run: cabal test hls-fourmolu-plugin-tests || cabal test hls-fourmolu-plugin-tests
177+
run: cabal test hls-fourmolu-plugin-tests
178178

179179
- if: matrix.test
180180
name: Test hls-explicit-imports-plugin test suite
181-
run: cabal test hls-explicit-imports-plugin-tests || cabal test hls-explicit-imports-plugin-tests
181+
run: cabal test hls-explicit-imports-plugin-tests
182182

183183
- if: matrix.test
184184
name: Test hls-call-hierarchy-plugin test suite
185-
run: cabal test hls-call-hierarchy-plugin-tests || cabal test hls-call-hierarchy-plugin-tests
185+
run: cabal test hls-call-hierarchy-plugin-tests
186186

187187
- if: matrix.test && matrix.os != 'windows-latest'
188188
name: Test hls-rename-plugin test suite
189-
run: cabal test hls-rename-plugin-tests || cabal test hls-rename-plugin-tests
189+
run: cabal test hls-rename-plugin-tests
190190

191191
# TODO enable when it supports 9.10
192192
- if: matrix.test && matrix.ghc != '9.10'
193193
name: Test hls-hlint-plugin test suite
194-
run: cabal test hls-hlint-plugin-tests || cabal test hls-hlint-plugin-tests
194+
run: cabal test hls-hlint-plugin-tests
195195

196196
- if: matrix.test
197197
name: Test hls-module-name-plugin test suite
198-
run: cabal test hls-module-name-plugin-tests || cabal test hls-module-name-plugin-tests
198+
run: cabal test hls-module-name-plugin-tests
199199

200200
- if: matrix.test
201201
name: Test hls-alternate-number-format-plugin test suite
202-
run: cabal test hls-alternate-number-format-plugin-tests || cabal test hls-alternate-number-format-plugin-tests
202+
run: cabal test hls-alternate-number-format-plugin-tests
203203

204204
- if: matrix.test
205205
name: Test hls-qualify-imported-names-plugin test suite
206-
run: cabal test hls-qualify-imported-names-plugin-tests || cabal test hls-qualify-imported-names-plugin-tests
206+
run: cabal test hls-qualify-imported-names-plugin-tests
207207

208208
- if: matrix.test
209209
name: Test hls-code-range-plugin test suite
210-
run: cabal test hls-code-range-plugin-tests || cabal test hls-code-range-plugin-tests
210+
run: cabal test hls-code-range-plugin-tests
211211

212212
- if: matrix.test
213213
name: Test hls-change-type-signature test suite
214-
run: cabal test hls-change-type-signature-plugin-tests || cabal test hls-change-type-signature-plugin-tests
214+
run: cabal test hls-change-type-signature-plugin-tests
215215

216216
- if: matrix.test
217217
name: Test hls-gadt-plugin test suit
218-
run: cabal test hls-gadt-plugin-tests || cabal test hls-gadt-plugin-tests
218+
run: cabal test hls-gadt-plugin-tests
219219

220220
- if: matrix.test
221221
name: Test hls-explicit-fixity-plugin test suite
222-
run: cabal test hls-explicit-fixity-plugin-tests || cabal test hls-explicit-fixity-plugin-tests
222+
run: cabal test hls-explicit-fixity-plugin-tests
223223

224224
- if: matrix.test
225225
name: Test hls-explicit-record-fields-plugin test suite
226-
run: cabal test hls-explicit-record-fields-plugin-tests || cabal test hls-explicit-record-fields-plugin-tests
226+
run: cabal test hls-explicit-record-fields-plugin-tests
227227

228228
# versions need to be limited since the tests depend on cabal-fmt which only builds with ghc <9.10
229229
- if: matrix.test && matrix.ghc != '9.10' && matrix.ghc != '9.12'
230230
name: Test hls-cabal-fmt-plugin test suite
231-
run: cabal test hls-cabal-fmt-plugin-tests --flag=isolateCabalfmtTests || cabal test hls-cabal-fmt-plugin-tests --flag=isolateCabalfmtTests
231+
run: cabal test hls-cabal-fmt-plugin-tests --flag=isolateCabalfmtTests
232232

233233
- if: matrix.test && matrix.ghc != '9.12'
234234
name: Test hls-cabal-gild-plugin test suite
235-
run: cabal test hls-cabal-gild-plugin-tests --flag=isolateCabalGildTests || cabal test hls-cabal-gild-plugin-tests --flag=isolateCabalGildTests
235+
run: cabal test hls-cabal-gild-plugin-tests --flag=isolateCabalGildTests
236236

237237
- if: matrix.test
238238
name: Test hls-cabal-plugin test suite
239-
run: cabal test hls-cabal-plugin-tests || cabal test hls-cabal-plugin-tests
239+
run: cabal test hls-cabal-plugin-tests
240240

241241
# TODO enable when it supports 9.10
242242
- if: matrix.test && matrix.ghc != '9.10' && matrix.ghc != '9.12'
243243
name: Test hls-retrie-plugin test suite
244-
run: cabal test hls-retrie-plugin-tests || cabal test hls-retrie-plugin-tests
244+
run: cabal test hls-retrie-plugin-tests
245245

246246
- if: matrix.test
247247
name: Test hls-overloaded-record-dot-plugin test suite
248-
run: cabal test hls-overloaded-record-dot-plugin-tests || cabal test hls-overloaded-record-dot-plugin-tests
248+
run: cabal test hls-overloaded-record-dot-plugin-tests
249249

250250
- if: matrix.test
251251
name: Test hls-semantic-tokens-plugin test suite
252-
run: cabal test hls-semantic-tokens-plugin-tests || cabal test hls-semantic-tokens-plugin-tests
252+
run: cabal test hls-semantic-tokens-plugin-tests
253253

254254
- if: matrix.test
255255
name: Test hls-notes-plugin test suite
256-
run: cabal test hls-notes-plugin-tests || cabal test hls-notes-plugin-tests
256+
run: cabal test hls-notes-plugin-tests
257257

258258
# The plugin tutorial is only compatible with 9.6 and 9.8.
259259
# No particular reason, just to avoid excessive CPP.

ghcide/src/Development/IDE/Core/ProgressReporting.hs

Lines changed: 35 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,24 +23,31 @@ import Control.Concurrent.STM (STM)
2323
import Control.Concurrent.STM.Stats (TVar, atomically,
2424
atomicallyNamed, modifyTVar',
2525
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)
2829
import Control.Monad.Extra hiding (loop)
2930
import Control.Monad.IO.Class
3031
import Control.Monad.Trans.Class (lift)
32+
import qualified Data.Aeson as J
3133
import Data.Functor (($>))
3234
import qualified Data.Text as T
35+
import Data.Unique (hashUnique, newUnique)
3336
import Development.IDE.GHC.Orphans ()
3437
import Development.IDE.Types.Location
3538
import Development.IDE.Types.Options
3639
import qualified Focus
40+
import Language.LSP.Protocol.Message
3741
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 (..),
3944
ProgressCancellable (..),
45+
sendNotification, sendRequest,
4046
withProgress)
4147
import qualified Language.LSP.Server as LSP
4248
import qualified StmContainers.Map as STM
4349
import UnliftIO (Async, async, bracket, cancel)
50+
import qualified UnliftIO.Exception as UE
4451

4552
data ProgressEvent
4653
= ProgressNewStarted
@@ -168,7 +175,7 @@ progressReportingNoTrace todo done (Just lspEnv) title optProgressStyle = do
168175
let _progressUpdate event = liftIO $ updateStateVar $ Event event
169176
_progressStop = updateStateVar StopProgress
170177
updateStateVar = modifyVar_ progressState . updateState (progressCounter lspEnv title optProgressStyle todo done)
171-
return ProgressReporting {..}
178+
return ProgressReporting {_progressUpdate, _progressStop}
172179

173180
-- | `progressReporting` initiates a new progress reporting session.
174181
-- It necessitates the active tracking of progress using the `inProgress` function.
@@ -196,6 +203,25 @@ progressReporting (Just lspEnv) title optProgressStyle = do
196203

197204
f = recordProgress inProgress file
198205

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+
199225
-- Kill this to complete the progress session
200226
progressCounter ::
201227
LSP.LanguageContextEnv c ->
@@ -205,8 +231,12 @@ progressCounter ::
205231
STM Int ->
206232
IO ()
207233
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
209235
where
236+
withProgressChoice = case optProgressStyle of
237+
TestReporting -> withProgressDummy
238+
_ -> withProgress
239+
210240
loop _ _ | optProgressStyle == NoProgress = forever $ liftIO $ threadDelay maxBound
211241
loop update prevPct = do
212242
(todo, done, nextPct) <- liftIO $ atomically $ do

ghcide/src/Development/IDE/Main.hs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,9 @@ import Development.IDE.Types.Location (NormalizedUri,
7777
toNormalizedFilePath')
7878
import Development.IDE.Types.Monitoring (Monitoring)
7979
import Development.IDE.Types.Options (IdeGhcSession,
80-
IdeOptions (optCheckParents, optCheckProject, optReportProgress, optRunSubset),
80+
IdeOptions (..),
8181
IdeTesting (IdeTesting),
82+
ProgressReportingStyle (TestReporting),
8283
clientSupportsProgress,
8384
defaultIdeOptions,
8485
optModifyDynFlags,
@@ -276,7 +277,10 @@ testing recorder projectRoot plugins =
276277
let
277278
defOptions = argsIdeOptions config sessionLoader
278279
in
279-
defOptions{ optTesting = IdeTesting True }
280+
defOptions{
281+
optTesting = IdeTesting True
282+
, optProgressStyle = TestReporting
283+
}
280284
lspOptions = argsLspOptions { LSP.optProgressStartDelay = 0, LSP.optProgressUpdateDelay = 0 }
281285
in
282286
arguments

ghcide/src/Development/IDE/Types/Options.hs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ newtype IdeOTMemoryProfiling = IdeOTMemoryProfiling Bool
107107
data ProgressReportingStyle
108108
= Percentage -- ^ Report using the LSP @_percentage@ field
109109
| Explicit -- ^ Report using explicit 123/456 text
110+
| TestReporting -- ^ Special mode for testing, reports only start/stop
110111
| NoProgress -- ^ Do not report any percentage
111112
deriving Eq
112113

0 commit comments

Comments
 (0)