microsoft / language-server-protocol

Defines a common protocol for language servers.
https://microsoft.github.io/language-server-protocol/
Creative Commons Attribution 4.0 International
10.91k stars 764 forks source link

Can a client use `window/workDoneProgress/cancel` to cancel a progress token provided by the client? #1873

Closed michaelpj closed 6 months ago

michaelpj commented 6 months ago

The cancellation support via window/workDoneProgress/cancel is nice, but from the specification it seems like it's only available for server-initiated progress. It would be nice if they had feature parity, since otherwise it seems as though server-initiated progress is mostly just better?

rwols commented 6 months ago

Because client-initiated progress is tied to client requests, it seems to me that the client cancels the request and anything associated with it, such as progress, with $/cancelRequest.

Because server-initiated progress can start at any moment, not being tied to a request, clients need some way to cancel the background computation. Using window/workDoneProgress/cancel in this case.

michaelpj commented 6 months ago

So if we have the following sequence:

Is the client supposed to cancel the action with $/cancel? From the client perspective that seems more complicated, and I wouldn't be surprised if many of them just send a window/workDoneProgress/cancel.

From the server side it's not any harder to support window/workDoneProgress/cancel for all progress tokens, so I'll probably do that regardless. But it would be nice if the spec was clearer.

dbaeumer commented 6 months ago

@rowls thanks for the great explanation.

@michaelpj the only sentence we could add is to say that client side progress is to be canceled using $/cancel message since they are bound to a request in the first place.

window/workDoneProgress/cancel is a server to client message only. So clients should never sent them to the server.

dbaeumer commented 6 months ago

Added a clarifying sentence.

michaelpj commented 6 months ago

window/workDoneProgress/cancel is a server to client message only. So clients should never sent them to the server.

I think you mean the opposite? https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#window_workDoneProgress_cancel

I think the helpful sentence to add would be one to the section on window/workDoneProgress/cancel, something like: "A client should not send a window/workDoneProgress/cancel notification for a client-initiated progress token (instead it should use $/cancel to cancel the associated request). If a server receives such a notification it should ignore it and should not cancel the request."

Is that right?

dbaeumer commented 6 months ago

That is more or less the sentence I added:

Canceling work done progress is done by simply canceling the corresponding request.
dbaeumer commented 6 months ago

And you are correct. The window/workDoneProgress/cancel is a client to server message.

Client initiated progress is always bound to a request. It can't exist by itself.

michaelpj commented 6 months ago

Your sentence doesn't say