`withProgress Cancellable` doesn't seem to work?
- Dominant language
- Haskell
- Stars
- 423
- Forks
- 105
- PR merge metrics
- No merged PRs in 30d
Description
Hello,
I've just started using this package recently, so possibly I am using it incorrectly, or misunderstand something. The issue is that I can't seem to get `withProgress` to work correctly when an action is cancelled. To test it, I've made a server function like this:
```Haskell
onExecuteCommand :: LSP.ExecuteCommandParams -> M () -> M ()
onExecuteCommand _ps k =
Srv.withProgress "PROG" Srv.Cancellable (go 0)
where
go n advance =
if n < 100
then do
liftIO (threadDelay (1 * 10^(6::Int)))
_ <- advance (Srv.ProgressAmount (Just n)
(Just (Text.pack ("THING: " ++ show n))))
go (n+5) advance
else k
`catch` \(_ :: Srv.ProgressCancelledException) -> do
lspShow Info "Cancelled"
```
Basically the idea is that we sleep for a second a bunch of times to simulate work. This works great as long as you don't cancel the action. If the action is cancelled, the work seems to continue executing, and when it is finished I get this error:
```
LSP: no handler for: "window/workDoneProgress/cancel"
```
Looking at `lsp`'s source code, it looks like there is a built-in handler for this, which makes sense. However, this handler never seems to fire.
I wonder if the problem is that in the implementation of `withProgress`, we fork off the work with `async`, but then we `wait` for it straight away, so we are blocked and can't handle the `cancel` message from the client?
Thoughts?
Contributor guide
Research direction
Start by reading the withProgress implementation and the built-in handler for "window/workDoneProgress/cancel" in the lsp source. Reproduce the issue with the provided onExecuteCommand example, then trace whether waiting on the async work prevents cancellation handling. Done means cancellation stops the simulated work and avoids the no-handler error.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- haskell
- Domain
- devtools
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100