-
Notifications
You must be signed in to change notification settings - Fork 332
Open
Description
I just realized that there is a staleRequestSupport section in the client capabilities in LSP:
/**
* Client capability that signals how the client
* handles stale requests (e.g. a request
* for which the client will not process the response
* anymore since the information is outdated).
*
* @since 3.17.0
*/
staleRequestSupport?: {
/**
* The client will actively cancel the request.
*/
cancel: boolean;
/**
* The list of requests for which the client
* will retry the request if it receives a
* response with error code `ContentModified``
*/
retryOnContentModified: string[];
}VS Code sends the following options
"staleRequestSupport": {
"cancel": true,
"retryOnContentModified": [
"textDocument/semanticTokens/full",
"textDocument/semanticTokens/range",
"textDocument/semanticTokens/full/delta"
]
}I am still unsure how to interpret the retryOnContentModified section because the ContentModified error code is described as follows
/**
* The server detected that the content of a document got
* modified outside normal conditions. A server should
* NOT send this error code if it detects a content change
* in it unprocessed messages. The result even computed
* on an older state might still be useful for the client.
*
* If a client decides that a result is not of any use anymore
* the client should cancel the request.
*/
export const ContentModified: integer = -32801;which indicates that LSP servers should not cancel requests when they detect an edit to the document, contradicting the comment in staleRequestSupport IMO. The commit that introduced staleRequestSupport also isn’t very insightful: microsoft/language-server-protocol@8aec48a
Based on VS Code’s runtime behavior, I guess that it’s intended as follows:
staleRequestSupport.cancel: trueindicates that the LSP server can generally rely on the client cancelling stale requests and doesn’t need to do any implicit cancellationstaleRequestSupport.retryOnContentModifiedmeans that there is a list of requests that the client does not cancel. For these, it relies on the server replying withContentModifiedif it detects a content change, even though that contradicts the definition of theContentChangeerror code.
So, maybe the correct way of implementing implicit cancellation is:
- If the client does not set
staleRequestSupportin the client capabilities or ifstaleRequsetSupport.cancelisfalse, we should cancel requests on document edits (the behavior we currently get withcancelTextDocumentRequestsOnEditAndClose: true). I am not sure if the error code that we return here matters. - If
staleRequestSupport.cancelistruethen only document requests instaleRequestSupport.retryOnContentModifiedshould be implicitly cancelled on document edits, returning aContentModifiederror code. - I think it’s still valuable to have a
cancelTextDocumentRequestsOnEditAndCloseconfiguration setting to override the behavior to always cancel requests on edits, forcing the same behavior as ifstaleRequestSupportwas not set in the client capabilities. This configuration setting should default tofalse.
Metadata
Metadata
Assignees
Labels
No labels