vscode-jsonrpc
Advanced tools
Comparing version 8.2.1-next.1 to 9.0.0-next.1
@@ -12,4 +12,4 @@ /// <reference path="../../typings/thenable.d.ts" /> | ||
import { ContentTypeEncoderOptions, ContentEncoder, ContentTypeEncoder, ContentTypeDecoderOptions, ContentDecoder, ContentTypeDecoder } from './encoding'; | ||
import { Logger, ConnectionStrategy, ConnectionOptions, MessageConnection, NullLogger, createMessageConnection, ProgressToken, ProgressType, HandlerResult, StarRequestHandler, GenericRequestHandler, RequestHandler0, RequestHandler, RequestHandler1, RequestHandler2, RequestHandler3, RequestHandler4, RequestHandler5, RequestHandler6, RequestHandler7, RequestHandler8, RequestHandler9, StarNotificationHandler, GenericNotificationHandler, NotificationHandler0, NotificationHandler, NotificationHandler1, NotificationHandler2, NotificationHandler3, NotificationHandler4, NotificationHandler5, NotificationHandler6, NotificationHandler7, NotificationHandler8, NotificationHandler9, Trace, TraceValues, TraceFormat, TraceOptions, SetTraceParams, SetTraceNotification, LogTraceParams, LogTraceNotification, Tracer, ConnectionErrors, ConnectionError, CancellationId, CancellationReceiverStrategy, CancellationSenderStrategy, CancellationStrategy, MessageStrategy } from './connection'; | ||
import { Logger, ConnectionStrategy, ConnectionOptions, MessageConnection, NullLogger, createMessageConnection, ProgressToken, ProgressType, HandlerResult, StarRequestHandler, GenericRequestHandler, RequestHandler0, RequestHandler, RequestHandler1, RequestHandler2, RequestHandler3, RequestHandler4, RequestHandler5, RequestHandler6, RequestHandler7, RequestHandler8, RequestHandler9, StarNotificationHandler, GenericNotificationHandler, NotificationHandler0, NotificationHandler, NotificationHandler1, NotificationHandler2, NotificationHandler3, NotificationHandler4, NotificationHandler5, NotificationHandler6, NotificationHandler7, NotificationHandler8, NotificationHandler9, Trace, TraceValue, TraceFormat, TraceOptions, SetTraceParams, SetTraceNotification, LogTraceParams, LogTraceNotification, Tracer, ConnectionErrors, ConnectionError, CancellationId, CancellationReceiverStrategy, CancellationSenderStrategy, CancellationStrategy, MessageStrategy, TraceValues } from './connection'; | ||
import RAL from './ral'; | ||
export { RAL, Message, MessageSignature, RequestMessage, RequestType, RequestType0, RequestType1, RequestType2, RequestType3, RequestType4, RequestType5, RequestType6, RequestType7, RequestType8, RequestType9, ResponseError, ErrorCodes, NotificationMessage, NotificationType, NotificationType0, NotificationType1, NotificationType2, NotificationType3, NotificationType4, NotificationType5, NotificationType6, NotificationType7, NotificationType8, NotificationType9, ResponseMessage, ParameterStructures, _EM, LinkedMap, Touch, LRUCache, Disposable, Event, Emitter, AbstractCancellationTokenSource, CancellationTokenSource, CancellationToken, SharedArraySenderStrategy, SharedArrayReceiverStrategy, MessageReader, AbstractMessageReader, ReadableStreamMessageReader, DataCallback, MessageReaderOptions, PartialMessageInfo, MessageWriter, AbstractMessageWriter, WriteableStreamMessageWriter, MessageWriterOptions, AbstractMessageBuffer, ContentTypeEncoderOptions, ContentEncoder, ContentTypeEncoder, ContentTypeDecoderOptions, ContentDecoder, ContentTypeDecoder, Logger, ConnectionStrategy, ConnectionOptions, MessageConnection, NullLogger, createMessageConnection, ProgressToken, ProgressType, HandlerResult, StarRequestHandler, GenericRequestHandler, RequestHandler0, RequestHandler, RequestHandler1, RequestHandler2, RequestHandler3, RequestHandler4, RequestHandler5, RequestHandler6, RequestHandler7, RequestHandler8, RequestHandler9, StarNotificationHandler, GenericNotificationHandler, NotificationHandler0, NotificationHandler, NotificationHandler1, NotificationHandler2, NotificationHandler3, NotificationHandler4, NotificationHandler5, NotificationHandler6, NotificationHandler7, NotificationHandler8, NotificationHandler9, Trace, TraceValues, TraceFormat, TraceOptions, SetTraceParams, SetTraceNotification, LogTraceParams, LogTraceNotification, Tracer, ConnectionErrors, ConnectionError, CancellationId, CancellationReceiverStrategy, CancellationSenderStrategy, CancellationStrategy, MessageStrategy }; | ||
export { RAL, Message, MessageSignature, RequestMessage, RequestType, RequestType0, RequestType1, RequestType2, RequestType3, RequestType4, RequestType5, RequestType6, RequestType7, RequestType8, RequestType9, ResponseError, ErrorCodes, NotificationMessage, NotificationType, NotificationType0, NotificationType1, NotificationType2, NotificationType3, NotificationType4, NotificationType5, NotificationType6, NotificationType7, NotificationType8, NotificationType9, ResponseMessage, ParameterStructures, _EM, LinkedMap, Touch, LRUCache, Disposable, Event, Emitter, AbstractCancellationTokenSource, CancellationTokenSource, CancellationToken, SharedArraySenderStrategy, SharedArrayReceiverStrategy, MessageReader, AbstractMessageReader, ReadableStreamMessageReader, DataCallback, MessageReaderOptions, PartialMessageInfo, MessageWriter, AbstractMessageWriter, WriteableStreamMessageWriter, MessageWriterOptions, AbstractMessageBuffer, ContentTypeEncoderOptions, ContentEncoder, ContentTypeEncoder, ContentTypeDecoderOptions, ContentDecoder, ContentTypeDecoder, Logger, ConnectionStrategy, ConnectionOptions, MessageConnection, NullLogger, createMessageConnection, ProgressToken, ProgressType, HandlerResult, StarRequestHandler, GenericRequestHandler, RequestHandler0, RequestHandler, RequestHandler1, RequestHandler2, RequestHandler3, RequestHandler4, RequestHandler5, RequestHandler6, RequestHandler7, RequestHandler8, RequestHandler9, StarNotificationHandler, GenericNotificationHandler, NotificationHandler0, NotificationHandler, NotificationHandler1, NotificationHandler2, NotificationHandler3, NotificationHandler4, NotificationHandler5, NotificationHandler6, NotificationHandler7, NotificationHandler8, NotificationHandler9, Trace, TraceValue, TraceValues, TraceFormat, TraceOptions, SetTraceParams, SetTraceNotification, LogTraceParams, LogTraceNotification, Tracer, ConnectionErrors, ConnectionError, CancellationId, CancellationReceiverStrategy, CancellationSenderStrategy, CancellationStrategy, MessageStrategy }; |
@@ -9,3 +9,3 @@ "use strict"; | ||
exports.ProgressType = exports.ProgressToken = exports.createMessageConnection = exports.NullLogger = exports.ConnectionOptions = exports.ConnectionStrategy = exports.AbstractMessageBuffer = exports.WriteableStreamMessageWriter = exports.AbstractMessageWriter = exports.MessageWriter = exports.ReadableStreamMessageReader = exports.AbstractMessageReader = exports.MessageReader = exports.SharedArrayReceiverStrategy = exports.SharedArraySenderStrategy = exports.CancellationToken = exports.CancellationTokenSource = exports.Emitter = exports.Event = exports.Disposable = exports.LRUCache = exports.Touch = exports.LinkedMap = exports.ParameterStructures = exports.NotificationType9 = exports.NotificationType8 = exports.NotificationType7 = exports.NotificationType6 = exports.NotificationType5 = exports.NotificationType4 = exports.NotificationType3 = exports.NotificationType2 = exports.NotificationType1 = exports.NotificationType0 = exports.NotificationType = exports.ErrorCodes = exports.ResponseError = exports.RequestType9 = exports.RequestType8 = exports.RequestType7 = exports.RequestType6 = exports.RequestType5 = exports.RequestType4 = exports.RequestType3 = exports.RequestType2 = exports.RequestType1 = exports.RequestType0 = exports.RequestType = exports.Message = exports.RAL = void 0; | ||
exports.MessageStrategy = exports.CancellationStrategy = exports.CancellationSenderStrategy = exports.CancellationReceiverStrategy = exports.ConnectionError = exports.ConnectionErrors = exports.LogTraceNotification = exports.SetTraceNotification = exports.TraceFormat = exports.TraceValues = exports.Trace = void 0; | ||
exports.MessageStrategy = exports.CancellationStrategy = exports.CancellationSenderStrategy = exports.CancellationReceiverStrategy = exports.ConnectionError = exports.ConnectionErrors = exports.LogTraceNotification = exports.SetTraceNotification = exports.TraceFormat = exports.TraceValues = exports.TraceValue = exports.Trace = void 0; | ||
const messages_1 = require("./messages"); | ||
@@ -71,3 +71,3 @@ Object.defineProperty(exports, "Message", { enumerable: true, get: function () { return messages_1.Message; } }); | ||
Object.defineProperty(exports, "Trace", { enumerable: true, get: function () { return connection_1.Trace; } }); | ||
Object.defineProperty(exports, "TraceValues", { enumerable: true, get: function () { return connection_1.TraceValues; } }); | ||
Object.defineProperty(exports, "TraceValue", { enumerable: true, get: function () { return connection_1.TraceValue; } }); | ||
Object.defineProperty(exports, "TraceFormat", { enumerable: true, get: function () { return connection_1.TraceFormat; } }); | ||
@@ -82,3 +82,4 @@ Object.defineProperty(exports, "SetTraceNotification", { enumerable: true, get: function () { return connection_1.SetTraceNotification; } }); | ||
Object.defineProperty(exports, "MessageStrategy", { enumerable: true, get: function () { return connection_1.MessageStrategy; } }); | ||
Object.defineProperty(exports, "TraceValues", { enumerable: true, get: function () { return connection_1.TraceValues; } }); | ||
const ral_1 = require("./ral"); | ||
exports.RAL = ral_1.default; |
@@ -70,40 +70,41 @@ import { Message, RequestMessage, RequestType, RequestType0, RequestType1, RequestType2, RequestType3, RequestType4, RequestType5, RequestType6, RequestType7, RequestType8, RequestType9, ResponseMessage, ResponseError, NotificationMessage, NotificationType, NotificationType0, NotificationType1, NotificationType2, NotificationType3, NotificationType4, NotificationType5, NotificationType6, NotificationType7, NotificationType8, NotificationType9, _EM, ParameterStructures } from './messages'; | ||
} | ||
export type NotificationResult = void | Promise<void>; | ||
export interface StarNotificationHandler { | ||
(method: string, params: any[] | object | undefined): void; | ||
(method: string, params: any[] | object | undefined): NotificationResult; | ||
} | ||
export interface GenericNotificationHandler { | ||
(...params: any[]): void; | ||
(...params: any[]): NotificationResult; | ||
} | ||
export interface NotificationHandler0 { | ||
(): void; | ||
(): NotificationResult; | ||
} | ||
export interface NotificationHandler<P> { | ||
(params: P): void; | ||
(params: P): NotificationResult; | ||
} | ||
export interface NotificationHandler1<P1> { | ||
(p1: P1): void; | ||
(p1: P1): NotificationResult; | ||
} | ||
export interface NotificationHandler2<P1, P2> { | ||
(p1: P1, p2: P2): void; | ||
(p1: P1, p2: P2): NotificationResult; | ||
} | ||
export interface NotificationHandler3<P1, P2, P3> { | ||
(p1: P1, p2: P2, p3: P3): void; | ||
(p1: P1, p2: P2, p3: P3): NotificationResult; | ||
} | ||
export interface NotificationHandler4<P1, P2, P3, P4> { | ||
(p1: P1, p2: P2, p3: P3, p4: P4): void; | ||
(p1: P1, p2: P2, p3: P3, p4: P4): NotificationResult; | ||
} | ||
export interface NotificationHandler5<P1, P2, P3, P4, P5> { | ||
(p1: P1, p2: P2, p3: P3, p4: P4, p5: P5): void; | ||
(p1: P1, p2: P2, p3: P3, p4: P4, p5: P5): NotificationResult; | ||
} | ||
export interface NotificationHandler6<P1, P2, P3, P4, P5, P6> { | ||
(p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6): void; | ||
(p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6): NotificationResult; | ||
} | ||
export interface NotificationHandler7<P1, P2, P3, P4, P5, P6, P7> { | ||
(p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6, p7: P7): void; | ||
(p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6, p7: P7): NotificationResult; | ||
} | ||
export interface NotificationHandler8<P1, P2, P3, P4, P5, P6, P7, P8> { | ||
(p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6, p7: P7, p8: P8): void; | ||
(p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6, p7: P7, p8: P8): NotificationResult; | ||
} | ||
export interface NotificationHandler9<P1, P2, P3, P4, P5, P6, P7, P8, P9> { | ||
(p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6, p7: P7, p8: P8, p9: P9): void; | ||
(p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6, p7: P7, p8: P8, p9: P9): NotificationResult; | ||
} | ||
@@ -123,3 +124,3 @@ export interface Logger { | ||
} | ||
export declare namespace TraceValues { | ||
export declare namespace TraceValue { | ||
/** | ||
@@ -142,6 +143,11 @@ * Turn tracing off. | ||
} | ||
export type TraceValues = 'off' | 'messages' | 'compact' | 'verbose'; | ||
export type TraceValue = 'off' | 'messages' | 'compact' | 'verbose'; | ||
/** | ||
* @deprecated Use TraceValue instead | ||
*/ | ||
export declare const TraceValues: typeof TraceValue; | ||
export type TraceValues = TraceValue; | ||
export declare namespace Trace { | ||
function fromString(value: string): Trace; | ||
function toString(value: Trace): TraceValues; | ||
function toString(value: Trace): TraceValue; | ||
} | ||
@@ -160,3 +166,3 @@ export declare enum TraceFormat { | ||
export interface SetTraceParams { | ||
value: TraceValues; | ||
value: TraceValue; | ||
} | ||
@@ -234,7 +240,3 @@ export declare namespace SetTraceNotification { | ||
} | ||
/** | ||
* This will break with the next major version and will become | ||
* export type CancellationReceiverStrategy = IdCancellationReceiverStrategy | RequestCancellationReceiverStrategy; | ||
*/ | ||
export type CancellationReceiverStrategy = IdCancellationReceiverStrategy; | ||
export type CancellationReceiverStrategy = IdCancellationReceiverStrategy | RequestCancellationReceiverStrategy; | ||
export declare namespace CancellationReceiverStrategy { | ||
@@ -283,3 +285,3 @@ const Message: CancellationReceiverStrategy; | ||
export interface MessageStrategy { | ||
handleMessage(message: Message, next: (message: Message) => void): void; | ||
handleMessage(message: Message, next: (message: Message) => NotificationResult): NotificationResult; | ||
} | ||
@@ -289,2 +291,6 @@ export declare namespace MessageStrategy { | ||
} | ||
/** | ||
* Connection options. A valid connection option must have at least a | ||
* `CancellationStrategy` or a `MessageStrategy` or a `ConnectionStrategy`. | ||
*/ | ||
export interface ConnectionOptions { | ||
@@ -294,2 +300,3 @@ cancellationStrategy?: CancellationStrategy; | ||
messageStrategy?: MessageStrategy; | ||
maxParallelism?: number; | ||
} | ||
@@ -296,0 +303,0 @@ export declare namespace ConnectionOptions { |
@@ -7,3 +7,3 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.createMessageConnection = exports.ConnectionOptions = exports.MessageStrategy = exports.CancellationStrategy = exports.CancellationSenderStrategy = exports.CancellationReceiverStrategy = exports.RequestCancellationReceiverStrategy = exports.IdCancellationReceiverStrategy = exports.ConnectionStrategy = exports.ConnectionError = exports.ConnectionErrors = exports.LogTraceNotification = exports.SetTraceNotification = exports.TraceFormat = exports.TraceValues = exports.Trace = exports.NullLogger = exports.ProgressType = exports.ProgressToken = void 0; | ||
exports.createMessageConnection = exports.ConnectionOptions = exports.MessageStrategy = exports.CancellationStrategy = exports.CancellationSenderStrategy = exports.CancellationReceiverStrategy = exports.RequestCancellationReceiverStrategy = exports.IdCancellationReceiverStrategy = exports.ConnectionStrategy = exports.ConnectionError = exports.ConnectionErrors = exports.LogTraceNotification = exports.SetTraceNotification = exports.TraceFormat = exports.TraceValues = exports.TraceValue = exports.Trace = exports.NullLogger = exports.ProgressType = exports.ProgressToken = void 0; | ||
const ral_1 = require("./ral"); | ||
@@ -55,21 +55,25 @@ const Is = require("./is"); | ||
})(Trace || (exports.Trace = Trace = {})); | ||
var TraceValues; | ||
(function (TraceValues) { | ||
var TraceValue; | ||
(function (TraceValue) { | ||
/** | ||
* Turn tracing off. | ||
*/ | ||
TraceValues.Off = 'off'; | ||
TraceValue.Off = 'off'; | ||
/** | ||
* Trace messages only. | ||
*/ | ||
TraceValues.Messages = 'messages'; | ||
TraceValue.Messages = 'messages'; | ||
/** | ||
* Compact message tracing. | ||
*/ | ||
TraceValues.Compact = 'compact'; | ||
TraceValue.Compact = 'compact'; | ||
/** | ||
* Verbose message tracing. | ||
*/ | ||
TraceValues.Verbose = 'verbose'; | ||
})(TraceValues || (exports.TraceValues = TraceValues = {})); | ||
TraceValue.Verbose = 'verbose'; | ||
})(TraceValue || (exports.TraceValue = TraceValue = {})); | ||
/** | ||
* @deprecated Use TraceValue instead | ||
*/ | ||
exports.TraceValues = TraceValue; | ||
(function (Trace) { | ||
@@ -236,3 +240,4 @@ function fromString(value) { | ||
const candidate = value; | ||
return candidate && (CancellationStrategy.is(candidate.cancellationStrategy) || ConnectionStrategy.is(candidate.connectionStrategy) || MessageStrategy.is(candidate.messageStrategy)); | ||
return candidate | ||
&& (CancellationStrategy.is(candidate.cancellationStrategy) || ConnectionStrategy.is(candidate.connectionStrategy) || MessageStrategy.is(candidate.messageStrategy) || Is.number(candidate.maxParallelism)); | ||
} | ||
@@ -254,2 +259,4 @@ ConnectionOptions.is = is; | ||
const version = '2.0'; | ||
const maxParallelism = options?.maxParallelism ?? -1; | ||
let inFlight = 0; | ||
let starRequestHandler = undefined; | ||
@@ -275,30 +282,2 @@ const requestHandlers = new Map(); | ||
const cancellationStrategy = (options && options.cancellationStrategy) ? options.cancellationStrategy : CancellationStrategy.Message; | ||
function createRequestQueueKey(id) { | ||
if (id === null) { | ||
throw new Error(`Can't send requests with id null since the response can't be correlated.`); | ||
} | ||
return 'req-' + id.toString(); | ||
} | ||
function createResponseQueueKey(id) { | ||
if (id === null) { | ||
return 'res-unknown-' + (++unknownResponseSequenceNumber).toString(); | ||
} | ||
else { | ||
return 'res-' + id.toString(); | ||
} | ||
} | ||
function createNotificationQueueKey() { | ||
return 'not-' + (++notificationSequenceNumber).toString(); | ||
} | ||
function addMessageToQueue(queue, message) { | ||
if (messages_1.Message.isRequest(message)) { | ||
queue.set(createRequestQueueKey(message.id), message); | ||
} | ||
else if (messages_1.Message.isResponse(message)) { | ||
queue.set(createResponseQueueKey(message.id), message); | ||
} | ||
else { | ||
queue.set(createNotificationQueueKey(), message); | ||
} | ||
} | ||
function cancelUndispatched(_message) { | ||
@@ -333,2 +312,30 @@ return undefined; | ||
messageWriter.onError(writeErrorHandler); | ||
function createRequestQueueKey(id) { | ||
if (id === null) { | ||
throw new Error(`Can't send requests with id null since the response can't be correlated.`); | ||
} | ||
return 'req-' + id.toString(); | ||
} | ||
function createResponseQueueKey(id) { | ||
if (id === null) { | ||
return 'res-unknown-' + (++unknownResponseSequenceNumber).toString(); | ||
} | ||
else { | ||
return 'res-' + id.toString(); | ||
} | ||
} | ||
function createNotificationQueueKey() { | ||
return 'not-' + (++notificationSequenceNumber).toString(); | ||
} | ||
function addMessageToQueue(queue, message) { | ||
if (messages_1.Message.isRequest(message)) { | ||
queue.set(createRequestQueueKey(message.id), message); | ||
} | ||
else if (messages_1.Message.isResponse(message)) { | ||
queue.set(createResponseQueueKey(message.id), message); | ||
} | ||
else { | ||
queue.set(createNotificationQueueKey(), message); | ||
} | ||
} | ||
function triggerMessageQueue() { | ||
@@ -338,39 +345,58 @@ if (timer || messageQueue.size === 0) { | ||
} | ||
timer = (0, ral_1.default)().timer.setImmediate(() => { | ||
if (maxParallelism !== -1 && inFlight >= maxParallelism) { | ||
return; | ||
} | ||
timer = (0, ral_1.default)().timer.setImmediate(async () => { | ||
timer = undefined; | ||
processMessageQueue(); | ||
if (messageQueue.size === 0) { | ||
return; | ||
} | ||
if (maxParallelism !== -1 && inFlight >= maxParallelism) { | ||
return; | ||
} | ||
const message = messageQueue.shift(); | ||
let result; | ||
try { | ||
inFlight++; | ||
const messageStrategy = options?.messageStrategy; | ||
if (MessageStrategy.is(messageStrategy)) { | ||
result = messageStrategy.handleMessage(message, handleMessage); | ||
} | ||
else { | ||
result = handleMessage(message); | ||
} | ||
} | ||
catch (error) { | ||
logger.error(`Processing message queue failed: ${error.toString()}`); | ||
} | ||
finally { | ||
if (result instanceof Promise) { | ||
result.then(() => { | ||
inFlight--; | ||
triggerMessageQueue(); | ||
}).catch((error) => { | ||
logger.error(`Processing message queue failed: ${error.toString()}`); | ||
}); | ||
} | ||
else { | ||
inFlight--; | ||
} | ||
triggerMessageQueue(); | ||
} | ||
}); | ||
} | ||
function handleMessage(message) { | ||
async function handleMessage(message) { | ||
if (messages_1.Message.isRequest(message)) { | ||
handleRequest(message); | ||
return handleRequest(message); | ||
} | ||
else if (messages_1.Message.isNotification(message)) { | ||
handleNotification(message); | ||
return handleNotification(message); | ||
} | ||
else if (messages_1.Message.isResponse(message)) { | ||
handleResponse(message); | ||
return handleResponse(message); | ||
} | ||
else { | ||
handleInvalidMessage(message); | ||
return handleInvalidMessage(message); | ||
} | ||
} | ||
function processMessageQueue() { | ||
if (messageQueue.size === 0) { | ||
return; | ||
} | ||
const message = messageQueue.shift(); | ||
try { | ||
const messageStrategy = options?.messageStrategy; | ||
if (MessageStrategy.is(messageStrategy)) { | ||
messageStrategy.handleMessage(message, handleMessage); | ||
} | ||
else { | ||
handleMessage(message); | ||
} | ||
} | ||
finally { | ||
triggerMessageQueue(); | ||
} | ||
} | ||
const callback = (message) => { | ||
@@ -415,7 +441,7 @@ try { | ||
}; | ||
function handleRequest(requestMessage) { | ||
async function handleRequest(requestMessage) { | ||
if (isDisposed()) { | ||
// we return here silently since we fired an event when the | ||
// connection got disposed. | ||
return; | ||
return Promise.resolve(); | ||
} | ||
@@ -434,3 +460,3 @@ function reply(resultOrError, method, startTime) { | ||
traceSendingResponse(message, method, startTime); | ||
messageWriter.write(message).catch(() => logger.error(`Sending response failed.`)); | ||
return messageWriter.write(message); | ||
} | ||
@@ -444,18 +470,4 @@ function replyError(error, method, startTime) { | ||
traceSendingResponse(message, method, startTime); | ||
messageWriter.write(message).catch(() => logger.error(`Sending response failed.`)); | ||
return messageWriter.write(message); | ||
} | ||
function replySuccess(result, method, startTime) { | ||
// The JSON RPC defines that a response must either have a result or an error | ||
// So we can't treat undefined as a valid response result. | ||
if (result === undefined) { | ||
result = null; | ||
} | ||
const message = { | ||
jsonrpc: version, | ||
id: requestMessage.id, | ||
result: result | ||
}; | ||
traceSendingResponse(message, method, startTime); | ||
messageWriter.write(message).catch(() => logger.error(`Sending response failed.`)); | ||
} | ||
traceReceivedRequest(requestMessage); | ||
@@ -486,4 +498,3 @@ const element = requestHandlers.get(requestMessage.method); | ||
if (type !== undefined && type.numberOfParams !== 0) { | ||
replyError(new messages_1.ResponseError(messages_1.ErrorCodes.InvalidParams, `Request ${requestMessage.method} defines ${type.numberOfParams} params but received none.`), requestMessage.method, startTime); | ||
return; | ||
return replyError(new messages_1.ResponseError(messages_1.ErrorCodes.InvalidParams, `Request ${requestMessage.method} defines ${type.numberOfParams} params but received none.`), requestMessage.method, startTime); | ||
} | ||
@@ -494,4 +505,3 @@ handlerResult = requestHandler(cancellationSource.token); | ||
if (type !== undefined && type.parameterStructures === messages_1.ParameterStructures.byName) { | ||
replyError(new messages_1.ResponseError(messages_1.ErrorCodes.InvalidParams, `Request ${requestMessage.method} defines parameters by name but received parameters by position`), requestMessage.method, startTime); | ||
return; | ||
return replyError(new messages_1.ResponseError(messages_1.ErrorCodes.InvalidParams, `Request ${requestMessage.method} defines parameters by name but received parameters by position`), requestMessage.method, startTime); | ||
} | ||
@@ -502,4 +512,3 @@ handlerResult = requestHandler(...requestMessage.params, cancellationSource.token); | ||
if (type !== undefined && type.parameterStructures === messages_1.ParameterStructures.byPosition) { | ||
replyError(new messages_1.ResponseError(messages_1.ErrorCodes.InvalidParams, `Request ${requestMessage.method} defines parameters by position but received parameters by name`), requestMessage.method, startTime); | ||
return; | ||
return replyError(new messages_1.ResponseError(messages_1.ErrorCodes.InvalidParams, `Request ${requestMessage.method} defines parameters by position but received parameters by name`), requestMessage.method, startTime); | ||
} | ||
@@ -512,44 +521,22 @@ handlerResult = requestHandler(requestMessage.params, cancellationSource.token); | ||
} | ||
const promise = handlerResult; | ||
if (!handlerResult) { | ||
requestTokens.delete(tokenKey); | ||
replySuccess(handlerResult, requestMessage.method, startTime); | ||
} | ||
else if (promise.then) { | ||
promise.then((resultOrError) => { | ||
requestTokens.delete(tokenKey); | ||
reply(resultOrError, requestMessage.method, startTime); | ||
}, error => { | ||
requestTokens.delete(tokenKey); | ||
if (error instanceof messages_1.ResponseError) { | ||
replyError(error, requestMessage.method, startTime); | ||
} | ||
else if (error && Is.string(error.message)) { | ||
replyError(new messages_1.ResponseError(messages_1.ErrorCodes.InternalError, `Request ${requestMessage.method} failed with message: ${error.message}`), requestMessage.method, startTime); | ||
} | ||
else { | ||
replyError(new messages_1.ResponseError(messages_1.ErrorCodes.InternalError, `Request ${requestMessage.method} failed unexpectedly without providing any details.`), requestMessage.method, startTime); | ||
} | ||
}); | ||
} | ||
else { | ||
requestTokens.delete(tokenKey); | ||
reply(handlerResult, requestMessage.method, startTime); | ||
} | ||
const resultOrError = await handlerResult; | ||
await reply(resultOrError, requestMessage.method, startTime); | ||
} | ||
catch (error) { | ||
requestTokens.delete(tokenKey); | ||
if (error instanceof messages_1.ResponseError) { | ||
reply(error, requestMessage.method, startTime); | ||
await reply(error, requestMessage.method, startTime); | ||
} | ||
else if (error && Is.string(error.message)) { | ||
replyError(new messages_1.ResponseError(messages_1.ErrorCodes.InternalError, `Request ${requestMessage.method} failed with message: ${error.message}`), requestMessage.method, startTime); | ||
await replyError(new messages_1.ResponseError(messages_1.ErrorCodes.InternalError, `Request ${requestMessage.method} failed with message: ${error.message}`), requestMessage.method, startTime); | ||
} | ||
else { | ||
replyError(new messages_1.ResponseError(messages_1.ErrorCodes.InternalError, `Request ${requestMessage.method} failed unexpectedly without providing any details.`), requestMessage.method, startTime); | ||
await replyError(new messages_1.ResponseError(messages_1.ErrorCodes.InternalError, `Request ${requestMessage.method} failed unexpectedly without providing any details.`), requestMessage.method, startTime); | ||
} | ||
} | ||
finally { | ||
requestTokens.delete(tokenKey); | ||
} | ||
} | ||
else { | ||
replyError(new messages_1.ResponseError(messages_1.ErrorCodes.MethodNotFound, `Unhandled method ${requestMessage.method}`), requestMessage.method, startTime); | ||
await replyError(new messages_1.ResponseError(messages_1.ErrorCodes.MethodNotFound, `Unhandled method ${requestMessage.method}`), requestMessage.method, startTime); | ||
} | ||
@@ -560,3 +547,3 @@ } | ||
// See handle request. | ||
return; | ||
return Promise.resolve(); | ||
} | ||
@@ -599,4 +586,5 @@ if (responseMessage.id === null) { | ||
} | ||
return Promise.resolve(); | ||
} | ||
function handleNotification(message) { | ||
async function handleNotification(message) { | ||
if (isDisposed()) { | ||
@@ -631,3 +619,3 @@ // See handle request. | ||
} | ||
notificationHandler(); | ||
await notificationHandler(); | ||
} | ||
@@ -639,3 +627,3 @@ else if (Array.isArray(message.params)) { | ||
if (message.method === ProgressNotification.type.method && params.length === 2 && ProgressToken.is(params[0])) { | ||
notificationHandler({ token: params[0], value: params[1] }); | ||
await notificationHandler({ token: params[0], value: params[1] }); | ||
} | ||
@@ -651,3 +639,3 @@ else { | ||
} | ||
notificationHandler(...params); | ||
await notificationHandler(...params); | ||
} | ||
@@ -659,7 +647,7 @@ } | ||
} | ||
notificationHandler(message.params); | ||
await notificationHandler(message.params); | ||
} | ||
} | ||
else if (starNotificationHandler) { | ||
starNotificationHandler(message.method, message.params); | ||
await starNotificationHandler(message.method, message.params); | ||
} | ||
@@ -942,3 +930,3 @@ } | ||
} | ||
let paramEnd = args.length; | ||
const paramEnd = args.length; | ||
const numberOfParams = paramEnd - paramStart; | ||
@@ -1023,2 +1011,13 @@ switch (numberOfParams) { | ||
throwIfNotListening(); | ||
function sendCancellation(connection, id) { | ||
const p = cancellationStrategy.sender.sendCancellation(connection, id); | ||
if (p === undefined) { | ||
logger.log(`Received no promise from cancellation strategy when cancelling id ${id}`); | ||
} | ||
else { | ||
p.catch(() => { | ||
logger.log(`Sending cancellation messages for id ${id} failed.`); | ||
}); | ||
} | ||
} | ||
let method; | ||
@@ -1067,15 +1066,12 @@ let messageParams; | ||
let disposable; | ||
if (token) { | ||
disposable = token.onCancellationRequested(() => { | ||
const p = cancellationStrategy.sender.sendCancellation(connection, id); | ||
if (p === undefined) { | ||
logger.log(`Received no promise from cancellation strategy when cancelling id ${id}`); | ||
return Promise.resolve(); | ||
} | ||
else { | ||
return p.catch(() => { | ||
logger.log(`Sending cancellation messages for id ${id} failed`); | ||
}); | ||
} | ||
}); | ||
let tokenWasCancelled = false; | ||
if (token !== undefined) { | ||
if (token.isCancellationRequested) { | ||
tokenWasCancelled = true; | ||
} | ||
else { | ||
disposable = token.onCancellationRequested(() => { | ||
sendCancellation(connection, id); | ||
}); | ||
} | ||
} | ||
@@ -1092,2 +1088,3 @@ const requestMessage = { | ||
} | ||
// eslint-disable-next-line no-async-promise-executor | ||
return new Promise(async (resolve, reject) => { | ||
@@ -1108,2 +1105,5 @@ const resolveWithCleanup = (r) => { | ||
responsePromises.set(id, responsePromise); | ||
if (tokenWasCancelled) { | ||
sendCancellation(connection, id); | ||
} | ||
} | ||
@@ -1226,6 +1226,6 @@ catch (error) { | ||
}); | ||
connection.onNotification(ProgressNotification.type, (params) => { | ||
connection.onNotification(ProgressNotification.type, async (params) => { | ||
const handler = progressHandlers.get(params.token); | ||
if (handler) { | ||
handler(params.value); | ||
await handler(params.value); | ||
} | ||
@@ -1232,0 +1232,0 @@ else { |
@@ -36,3 +36,3 @@ "use strict"; | ||
offset = 0; | ||
column: while (offset < chunk.length) { | ||
while (offset < chunk.length) { | ||
const value = chunk[offset]; | ||
@@ -129,3 +129,3 @@ switch (value) { | ||
let resultOffset = 0; | ||
let chunkIndex = 0; | ||
const chunkIndex = 0; | ||
while (byteCount > 0) { | ||
@@ -132,0 +132,0 @@ const chunk = this._chunks[chunkIndex]; |
@@ -15,3 +15,3 @@ "use strict"; | ||
function is(value) { | ||
let candidate = value; | ||
const candidate = value; | ||
return candidate && Is.func(candidate.listen) && Is.func(candidate.dispose) && | ||
@@ -18,0 +18,0 @@ Is.func(candidate.onError) && Is.func(candidate.onClose) && Is.func(candidate.onPartialMessage); |
@@ -17,3 +17,3 @@ "use strict"; | ||
function is(value) { | ||
let candidate = value; | ||
const candidate = value; | ||
return candidate && Is.func(candidate.dispose) && Is.func(candidate.onClose) && | ||
@@ -20,0 +20,0 @@ Is.func(candidate.onError) && Is.func(candidate.write); |
@@ -36,3 +36,3 @@ "use strict"; | ||
this.process = process; | ||
let eventEmitter = this.process; | ||
const eventEmitter = this.process; | ||
eventEmitter.on('error', (error) => this.fireError(error)); | ||
@@ -183,3 +183,3 @@ eventEmitter.on('close', () => this.fireClose()); | ||
return new Promise((resolve, reject) => { | ||
let server = (0, net_1.createServer)((socket) => { | ||
const server = (0, net_1.createServer)((socket) => { | ||
server.close(); | ||
@@ -186,0 +186,0 @@ connectResolve([ |
{ | ||
"name": "vscode-jsonrpc", | ||
"description": "A json rpc implementation over streams", | ||
"version": "8.2.1-next.1", | ||
"version": "9.0.0-next.1", | ||
"author": "Microsoft Corporation", | ||
@@ -6,0 +6,0 @@ "license": "MIT", |
@@ -5,3 +5,3 @@ # VSCode JSON RPC | ||
[![NPM Downloads](https://img.shields.io/npm/dm/vscode-jsonrpc.svg)](https://npmjs.org/package/vscode-jsonrpc) | ||
[![Build Status](https://travis-ci.org/Microsoft/vscode-languageserver-node.svg?branch=master)](https://travis-ci.org/Microsoft/vscode-languageserver-node) | ||
[![Build Status](https://dev.azure.com/ms/vscode-languageserver-node/_apis/build/status/microsoft.vscode-languageserver-node?branchName=main)](https://dev.azure.com/ms/vscode-languageserver-node/_build/latest?definitionId=439&branchName=main) | ||
@@ -8,0 +8,0 @@ This npm module implements the base messaging protocol spoken between a VSCode language server and a VSCode language client. |
208680
4968