Giter Club home page Giter Club logo

Comments (6)

dbaeumer avatar dbaeumer commented on August 18, 2024 1

@felixfbecker: you can now find a more detailed doc here https://github.com/Microsoft/vscode-languageserver-protocol. It is documented in a request / response form like REST APIs are documented. Let me know if this helps. One thing I would like to add there as well is some sequence diagrams for typically request / response flows.

from vscode-languageserver-node.

dbaeumer avatar dbaeumer commented on August 18, 2024

@felixfbecker working on a documentation in mark down.

What also helps a lot is the following file: https://github.com/Microsoft/vscode-languageserver-node/blob/master/server/src/protocol.ts

It is basically the protocol in terms of TS interfaces.

from vscode-languageserver-node.

dbaeumer avatar dbaeumer commented on August 18, 2024

@felixfbecker let me know if you need any short term support. I am happy to answers questions.

from vscode-languageserver-node.

dbaeumer avatar dbaeumer commented on August 18, 2024

@felixfbecker: besides the server protocol you need to know the base json-rpc protocol. The definition looks like this:

Base Protocol

The base protocol consists of a header and a content part (comparable to http). The header and content part are separated by a '\r\n'.

Header Part

The header part consist of header fields. Header fields are separated from each other by '\r\n'. The last header field needs to be terminated with '\r\n' as well. Currently the following header fields are supported:

Header File Name Value Type Description
Content-Length number The length of the content part
Content-Type string The mime typ of the content part. Defaults to application/vscode-jsonrpc; charset=utf8

The header part is encoded using the 'ascii' encoding. This includes the '\r\n' separating the header and content part.

Content Part

Contains the actual content of the message. The content part of a message uses JSON-RPC to describe requests, responses and notifications. The content part is encoded using the charset provided in the Content-Type field. It defaults to 'utf8' which is the only currently supported encoding.

Example:

Content-Length: ...\r\n
\r\n
{
    "jsonrpc": "2.0",
    "id": 1,
    "method": "textDocument/didOpen", 
    "params": {
        ...
    }
}

Base Protocol JSON structures

The following TypeScript definitions describe the JSON-RPC protocol as implemented by VSCode:

Abstract Message

A general message as defined by JSON-RPC. The language server protocol always uses "2.0" as the jsonrpc version.

interface Message {
    jsonrpc: string;
}

RequestMessage

A request message to decribe a request between the client and the server. Every processed request must send a response back to the sender of the request.

interface RequestMessage extends Message {

    /**
     * The request id.
     */
    id: number | string;

    /**
     * The method to be invoked.
     */
    method: string;

    /**
     * The method's params.
     */
    params?: any
}

Response Message

Response Message send as a result of a request.

interface ResponseMessage extends Message {
    /**
     * The request id.
     */
    id: number | string;

    /**
     * The result of a request. This can be omitted in
     * the case of an error.
     */
    result?: any;

    /**
     * The error object in case a request fails.
     */
    error?: ResponseError<any>;
}

interface ResponseError<D> {
    /**
     * A number indicating the error type that occured.
     */
    code: number;

    /**
     * A string providing a short decription of the error.
     */
    message: string;

    /**
     * A Primitive or Structured value that contains additional
     * information about the error. Can be omitted.
     */
    data?: D;
}

export namespace ErrorCodes {
    export const ParseError: number = -32700;
    export const InvalidRequest: number = -32600;
    export const MethodNotFound: number = -32601;
    export const InvalidParams: number = -32602;
    export const InternalError: number = -32603;
    export const serverErrorStart: number = -32099
    export const serverErrorEnd: number = -32000;
}

Notification Message

A notification message. A processed notification message must not send a response back. They work like events.

interface NotificationMessage extends Message {
    /**
     * The method to be invoked.
     */
    method: string;

    /**
     * The notification's params.
     */
    params?: any
}

The corresponding TS file defining it is here: https://github.com/Microsoft/vscode-languageserver-node/blob/master/jsonrpc/src/messages.ts

Hope that gets you started.

from vscode-languageserver-node.

felixfbecker avatar felixfbecker commented on August 18, 2024

@dbaeumer Thank you for your detailed description of the protocol. Maybe you can give me an example how would a typical sequence look like for a language server, for example for IntelliSense, or getting notified when a file changed? And what exactly is "the method to be invoked"?

from vscode-languageserver-node.

dbaeumer avatar dbaeumer commented on August 18, 2024

Closing this since the documentation is tracked in https://github.com/Microsoft/vscode-languageserver-protocol

from vscode-languageserver-node.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.