Skip to content

Commit f4ce73f

Browse files
pepeiborrawz1000
authored andcommitted
Send begin progress message synchronously
Currently the Begin progress message is sent asynchronously, so it can happen that it's never sent if the async is cancelled immediately because a new kick has started. This causes trouble in tests and benchmarks which make assumptions about progress updates. To address this, we send the Begin progress message synchronously, and only then do the rest of the progress reporting stuff (including waiting for the response) asynchronously
1 parent c9ed045 commit f4ce73f

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

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

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -63,10 +63,10 @@ data State
6363
-- | State transitions used in 'delayedProgressReporting'
6464
data Transition = Event ProgressEvent | StopProgress
6565

66-
updateState :: IO () -> Transition -> State -> IO State
66+
updateState :: IO (Async ()) -> Transition -> State -> IO State
6767
updateState _ _ Stopped = pure Stopped
68-
updateState start (Event KickStarted) NotStarted = Running <$> async start
69-
updateState start (Event KickStarted) (Running a) = cancel a >> Running <$> async start
68+
updateState start (Event KickStarted) NotStarted = Running <$> start
69+
updateState start (Event KickStarted) (Running a) = cancel a >> Running <$> start
7070
updateState _ (Event KickCompleted) (Running a) = cancel a $> NotStarted
7171
updateState _ (Event KickCompleted) st = pure st
7272
updateState _ StopProgress (Running a) = cancel a $> Stopped
@@ -110,12 +110,13 @@ delayedProgressReporting
110110
-> Maybe (LSP.LanguageContextEnv c)
111111
-> ProgressReportingStyle
112112
-> IO ProgressReporting
113-
delayedProgressReporting before after lspEnv optProgressStyle = do
113+
delayedProgressReporting before after Nothing optProgressStyle = noProgressReporting
114+
delayedProgressReporting before after (Just lspEnv) optProgressStyle = do
114115
inProgressState <- newInProgress
115116
progressState <- newVar NotStarted
116117
let progressUpdate event = updateStateVar $ Event event
117118
progressStop = updateStateVar StopProgress
118-
updateStateVar = modifyVar_ progressState . updateState (mRunLspT lspEnv $ lspShakeProgress inProgressState)
119+
updateStateVar = modifyVar_ progressState . updateState (lspShakeProgress inProgressState)
119120

120121
inProgress = updateStateForFile inProgressState
121122
return ProgressReporting{..}
@@ -127,11 +128,11 @@ delayedProgressReporting before after lspEnv optProgressStyle = do
127128
u <- ProgressTextToken . T.pack . show . hashUnique <$> liftIO newUnique
128129

129130
b <- liftIO newBarrier
130-
void $ LSP.sendRequest LSP.SWindowWorkDoneProgressCreate
131+
void $ LSP.runLspT lspEnv $ LSP.sendRequest LSP.SWindowWorkDoneProgressCreate
131132
LSP.WorkDoneProgressCreateParams { _token = u } $ liftIO . signalBarrier b
132-
ready <- liftIO $ waitBarrier b
133-
134-
for_ ready $ const $ bracket_ (start u) (stop u) (loop u 0)
133+
liftIO $ async $ do
134+
ready <- waitBarrier b
135+
LSP.runLspT lspEnv $ for_ ready $ const $ bracket_ (start u) (stop u) (loop u 0)
135136
where
136137
start id = LSP.sendNotification LSP.SProgress $
137138
LSP.ProgressParams

0 commit comments

Comments
 (0)