// @flow declare module 'vscode-jsonrpc/node' { import type {Socket} from 'net'; import type {Readable, Writable} from 'stream'; declare type MessageBufferEncoding = 'ascii' | 'utf-8'; declare type Logger = {| error: (message: string) => void, warn: (message: string) => void, info: (message: string) => void, log: (message: string) => void, |}; declare type Disposable = {| /** * Dispose this object. */ dispose(): void, |}; declare interface Event { /** * * @param listener The listener function will be call when the event happens. * @param thisArgs The 'this' which will be used when calling the event listener. * @param disposables An array to which a {{IDisposable}} will be added. The * @return */ ( listener: (e: T) => any, thisArgs?: any, disposables?: Disposable[], ): Disposable; } declare type PartialMessageInfo = {| +messageToken: number, +waitingTime: number, |}; declare type DataCallback = {| (data: Message): void, |}; declare interface Message { jsonrpc: string; } declare interface NotificationMessage extends Message { /** * The method to be invoked. */ method: string; /** * The notification's params. */ params?: [] | mixed; } declare export class MessageReader { /** Raised whenever an error occurs while reading a message. */ +onError: Event; /** An event raised when the end of the underlying transport has been reached. */ +onClose: Event; /** * An event that *may* be raised to inform the owner that only part of a message has been received. * A MessageReader implementation may choose to raise this event after a timeout elapses while waiting for more of a partially received message to be received. */ +onPartialMessage: Event; /** * Begins listening for incoming messages. To be called at most once. * @param callback A callback for receiving decoded messages. */ listen(callback: DataCallback): Disposable; /** Releases resources incurred from reading or raising events. Does NOT close the underlying transport, if any. */ dispose(): void; } declare export class MessageWriter { /** Raised whenever an error occurs while writing a message. */ +onError: Event<[Error, Message | void, number | void]>; /** An event raised when the underlying transport has closed and writing is no longer possible. */ +onClose: Event; /** * Sends a JSON-RPC message. * @param msg The JSON-RPC message to be sent. * @description Implementations should guarantee messages are transmitted in the same order that they are received by this method. */ write(msg: Message): Promise; end(): void; /** Releases resources incurred from writing or raising events. Does NOT close the underlying transport, if any. */ dispose(): void; } declare export function createServerPipeTransport( pipeName: string, encoding?: MessageBufferEncoding, ): [MessageReader, MessageWriter]; declare export function createMessageConnection( reader: MessageReader, writer: MessageWriter, logger?: Logger, ): MessageConnection; declare export function createMessageConnection( inputStream: Readable, outputStream: Writable, logger?: Logger, ): MessageConnection; declare interface CancellationToken { /** * Is `true` when the token has been cancelled, `false` otherwise. */ +isCancellationRequested: boolean; /** * An [event](#Event) which fires upon cancellation. */ +onCancellationRequested: Event; } declare export class ParameterStructures { /** * The parameter structure is automatically inferred on the number of parameters * and the parameter type in case of a single param. */ static +auto: ParameterStructures; /** * Forces `byPosition` parameter structure. This is useful if you have a single * parameter which has a literal type. */ static +byPosition: ParameterStructures; /** * Forces `byName` parameter structure. This is only useful when having a single * parameter. The library will report errors if used with a different number of * parameters. */ static +byName: ParameterStructures; static is(value: any): Boolean; toString(): string; } declare interface MessageSignature { +method: string; +numberOfParams: number; +parameterStructures: ParameterStructures; } declare class AbstractMessageSignature implements MessageSignature { +method: string; +numberOfParams: number; constructor(method: string, numberOfParams: number): this; get parameterStructures(): ParameterStructures; } // prettier-ignore declare export class RequestType0 extends AbstractMessageSignature { constructor(method: string): this; } // prettier-ignore declare export class RequestType extends AbstractMessageSignature { constructor(method: string, _parameterStructures?: ParameterStructures): this; get parameterStructures(): ParameterStructures; } // prettier-ignore declare export class RequestType1 extends AbstractMessageSignature { constructor(method: string, _parameterStructures?: ParameterStructures): this; get parameterStructures(): ParameterStructures; } // prettier-ignore declare export class RequestType2 extends AbstractMessageSignature { constructor(method: string): this; } // prettier-ignore declare export class NotificationType

extends AbstractMessageSignature { constructor(method: string, _parameterStructures?: ParameterStructures): this; get parameterStructures(): ParameterStructures; } // prettier-ignore declare export class NotificationType0 extends AbstractMessageSignature { constructor(method: string): this; } // prettier-ignore declare export class NotificationType1 extends AbstractMessageSignature { constructor(method: string, _parameterStructures?: ParameterStructures): this; get parameterStructures(): ParameterStructures; } // prettier-ignore declare export class NotificationType2 extends AbstractMessageSignature { constructor(method: string): this; } declare interface ResponseErrorLiteral { /** * 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; } declare class ResponseError extends Error { +code: number; +data: D | void; constructor(code: number, message: string, data?: D): this; toJson(): ResponseErrorLiteral; } declare type HandlerResult = | R | ResponseError | Promise | Promise> | Promise>; declare interface RequestHandler0 { (token: CancellationToken): HandlerResult; } declare interface RequestHandler { (params: P, token: CancellationToken): HandlerResult; } declare interface RequestHandler1 { (p1: P1, token: CancellationToken): HandlerResult; } declare interface RequestHandler2 { (p1: P1, p2: P2, token: CancellationToken): HandlerResult; } declare interface GenericRequestHandler { (...params: any[]): HandlerResult; } // prettier-ignore declare interface StarRequestHandler { (method: string, params: any[] | mixed | void, token: CancellationToken): HandlerResult; } declare interface NotificationHandler0 { (): void; } declare interface NotificationHandler

{ (params: P): void; } declare interface NotificationHandler1 { (p1: P1): void; } declare interface NotificationHandler2 { (p1: P1, p2: P2): void; } declare interface StarNotificationHandler { (method: string, params: any[] | mixed | void): void; } declare interface GenericNotificationHandler { (...params: any[]): void; } declare export class ProgressType { /** * Clients must not use these properties. They are here to ensure correct typing. * in TypeScript */ constructor(): this; } declare type ProgressToken = number | string; declare interface ProgressParams { /** * The progress token provided by the client or server. */ token: ProgressToken; /** * The progress data. */ value: T; } // prettier-ignore declare export interface MessageConnection { sendRequest(type: RequestType0, token?: CancellationToken): Promise; sendRequest(type: RequestType, params: P, token?: CancellationToken): Promise; sendRequest(type: RequestType1, p1: P1, token?: CancellationToken): Promise; sendRequest(type: RequestType2, p1: P1, p2: P2, token?: CancellationToken): Promise; sendRequest(method: string, r0?: ParameterStructures | any, ...rest: any[]): Promise; onRequest(type: RequestType0, handler: RequestHandler0): Disposable; onRequest(type: RequestType, handler: RequestHandler): Disposable; onRequest(type: RequestType1, handler: RequestHandler1): Disposable; onRequest(type: RequestType2, handler: RequestHandler2): Disposable; onRequest(method: string, handler: GenericRequestHandler): Disposable; onRequest(handler: StarRequestHandler): Disposable; sendNotification(type: NotificationType0): void; sendNotification

(type: NotificationType

, params?: P): void; sendNotification(type: NotificationType1, p1: P1): void; sendNotification(type: NotificationType2, p1: P1, p2: P2): void; sendNotification(method: string, r0?: ParameterStructures | any, ...rest: any[]): void; onNotification(type: NotificationType0, handler: NotificationHandler0): Disposable; onNotification

(type: NotificationType

, handler: NotificationHandler

): Disposable; onNotification(type: NotificationType1, handler: NotificationHandler1): Disposable; onNotification(type: NotificationType2, handler: NotificationHandler2): Disposable; onNotification(method: string, handler: GenericNotificationHandler): Disposable; onNotification(handler: StarNotificationHandler): Disposable; onUnhandledNotification: Event; onProgress

(type: ProgressType

, token: string | number, handler: NotificationHandler

): Disposable; sendProgress

(type: ProgressType

, token: string | number, value: P): void; onUnhandledProgress: Event>; // trace(value: Trace, tracer: Tracer, sendNotification?: boolean): void; // trace(value: Trace, tracer: Tracer, traceOptions?: TraceOptions): void; onError: Event<[Error, Message | void, number | void]>; onClose: Event; listen(): void; end(): void; onDispose: Event; dispose(): void; inspect(): void; } declare export class SocketMessageReader extends /* ReadableStream */ MessageReader { constructor(socket: Socket, encoding?: MessageBufferEncoding): this; } declare export class SocketMessageWriter extends /* WriteableStream */ MessageWriter { constructor( socket: Socket, options?: MessageBufferEncoding /* | MessageWriterOptions */, ): this; dispose(): void; } }