Skip to content

Add streaming support #182

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 7 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions protocol.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ General
* :leftwards_arrow_with_hook: [shutdown](#shutdown)
* :arrow_right: [exit](#exit)
* :arrow_right: [$/cancelRequest](#cancelRequest)
* :arrow_left: [$/partialResult](#partialResult)

Window

Expand Down Expand Up @@ -238,6 +239,38 @@ interface CancelParams {

A request that got canceled still needs to return from the server and send a response back. It can not be left open / hanging. This is in line with the JSON RPC protocol that requires that every request sends a response back. In addition it allows for returning partial results on cancel.

#### <a name="partialResult"></a> Streaming Support

When a language server or client is able to provide partial information before having the final result,
it can send `$/partialResult` notifications to return parts of the result.
Support for this method is indicated by the `streaming` capability in both `ClientCapabilities` and `ServerCapabilities`.

_Notification_:
* method: '$/partialResult'
* params: `PartialResultParams` defined as follows:
```typescript
interface PartialResultParams {
/**
* The request id to provide parts of the result for
*/
id: number | string;

/**
* A JSON Patch that represents updates to the partial result as specified in RFC6902
* https://tools.ietf.org/html/rfc6902
*/
patch: JSONPatch;
}
```

The receiver can listen for partial result notifications with the request ID and use the provided JSON patches to build up a result.
The result is _not_ required to conform to the result interface while still being built.
For example, a language server might first return an array of several `SymbolInformation`s with just the name and kind set and then fill out the locations with patches.
The result is indicated as complete by the final response to the request.
If a server sent at least one partial result notification for a request, the client has to ignore the result of the final response (e.g. it can be `null`).
The same applies for requests sent from the server to the client (see `ServerCapabilities`).
A result built by applying all patches sent through `$/partialResult` should eventually yield in the exact same result as a non-streamed response result.

## Language Server Protocol

The language server protocol defines a set of JSON-RPC request, response and notification messages which are exchanged using the above base protocol. This section starts describing the basic JSON structures used in the protocol. The document uses TypeScript interfaces to describe these. Based on the basic JSON structures, the actual requests with their responses and the notifications are described.
Expand Down Expand Up @@ -869,6 +902,11 @@ export interface TextDocumentClientCapabilities {

```typescript
interface ClientCapabilities {
/**
* The client supports receiving the result solely through $/partialResult notifications for requests from the client to the server.
*/
streaming?: boolean;

/**
* Workspace specific client capabilities.
*/
Expand Down Expand Up @@ -1055,6 +1093,10 @@ export interface TextDocumentSyncOptions {
}

interface ServerCapabilities {
/**
* The server supports receiving results solely through $/partialResult notifications for requests from the server to the client.
*/
streaming?: boolean;
/**
* Defines how text documents are synced. Is either a detailed structure defining each notification or
* for backwards compatibility the TextDocumentSyncKind number.
Expand Down