@gluonjs/language-server


@gluonjs/language-server / packages/language-server/src / JsonRpcResponse

Interface: JsonRpcResponse

Properties

error?

readonly optional error?: object

code

readonly code: number

message

readonly message: string


id?

readonly optional id?: string | number


jsonrpc

readonly jsonrpc: "2.0"


method?

readonly optional method?: string


params?

readonly optional params?: unknown


result?

readonly optional result?: unknown

Example

Handle an ID-correlated result/error or a server notification returned through the JSON-RPC 2.0 transport:

ts
import { GluonProtocolServer, type JsonRpcRequest, type JsonRpcResponse } from '@gluonjs/language-server';

const server = new GluonProtocolServer();
const initialize = { jsonrpc: '2.0', id: 1, method: 'initialize', params: {} } satisfies JsonRpcRequest;
const responses: readonly JsonRpcResponse[] = server.handle(initialize);
const open = {
  jsonrpc: '2.0',
  method: 'textDocument/didOpen',
  params: { textDocument: { uri: 'file:///src/app.ts', text: `import { html } from '@gluonjs/core'; const view = html\`<img>text</img>\`;` } },
} satisfies JsonRpcRequest;
const notifications = server.handle(open);
console.log(responses[0]?.result, notifications[0]?.method, notifications[0]?.params);