Skip to content

withProgress Cancellable doesn't seem to work? #538

Open
@yav

Description

@yav

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:

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    v3Next really big release

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions