@eclipse-glsp/protocol
Advanced tools
Comparing version 2.1.0-next.300 to 2.1.0-next.301
@@ -18,2 +18,4 @@ import { Disposable, Message, MessageConnection } from 'vscode-jsonrpc'; | ||
get onServerInitialized(): Event<InitializeResult>; | ||
protected onActionMessageNotificationEmitter: Emitter<ActionMessage<import("../../action-protocol").Action>>; | ||
protected get onActionMessageNotification(): Event<ActionMessage>; | ||
constructor(options: JsonrpcGLSPClient.Options); | ||
@@ -20,0 +22,0 @@ shutdownServer(): void; |
@@ -33,4 +33,8 @@ "use strict"; | ||
} | ||
get onActionMessageNotification() { | ||
return this.onActionMessageNotificationEmitter.event; | ||
} | ||
constructor(options) { | ||
this.onServerInitializedEmitter = new event_1.Emitter(); | ||
this.onActionMessageNotificationEmitter = new event_1.Emitter(); | ||
Object.assign(this, options); | ||
@@ -59,3 +63,3 @@ this.state = glsp_client_1.ClientState.Initial; | ||
onActionMessage(handler, clientId) { | ||
return this.checkedConnection.onNotification(glsp_jsonrpc_client_1.JsonrpcGLSPClient.ActionMessageNotification, msg => { | ||
return this.onActionMessageNotification(msg => { | ||
if (!clientId || msg.clientId === clientId) { | ||
@@ -104,2 +108,3 @@ handler(msg); | ||
this.onStop = undefined; | ||
this.onActionMessageNotificationEmitter.dispose(); | ||
this.connectionPromise = undefined; | ||
@@ -119,2 +124,3 @@ this.resolvedConnection = undefined; | ||
connection.onClose(() => this.handleConnectionClosed()); | ||
connection.onNotification(glsp_jsonrpc_client_1.JsonrpcGLSPClient.ActionMessageNotification, msg => this.onActionMessageNotificationEmitter.fire(msg)); | ||
return connection; | ||
@@ -121,0 +127,0 @@ } |
@@ -23,2 +23,3 @@ "use strict"; | ||
const array_util_1 = require("../../utils/array-util"); | ||
const event_1 = require("../../utils/event"); | ||
const test_util_1 = require("../../utils/test-util"); | ||
@@ -66,9 +67,18 @@ const glsp_client_1 = require("../glsp-client"); | ||
} | ||
class TestJsonRpcClient extends base_jsonrpc_glsp_client_1.BaseJsonrpcGLSPClient { | ||
constructor() { | ||
super(...arguments); | ||
this.onActionMessageNotificationEmitter = new event_1.Emitter({ | ||
onFirstListenerAdd: () => (this.firstListenerAdded = true), | ||
onLastListenerRemove: () => (this.lastListenerRemoved = true) | ||
}); | ||
} | ||
} | ||
describe('Base JSON-RPC GLSP Client', () => { | ||
const sandbox = sinon.createSandbox(); | ||
const connection = sandbox.stub(new StubMessageConnection()); | ||
let client = new base_jsonrpc_glsp_client_1.BaseJsonrpcGLSPClient({ id: 'test', connectionProvider: connection }); | ||
let client = new TestJsonRpcClient({ id: 'test', connectionProvider: connection }); | ||
async function resetClient(setRunning = true) { | ||
sandbox.reset(); | ||
client = new base_jsonrpc_glsp_client_1.BaseJsonrpcGLSPClient({ id: 'test', connectionProvider: connection }); | ||
client = new TestJsonRpcClient({ id: 'test', connectionProvider: connection }); | ||
if (setRunning) { | ||
@@ -211,12 +221,20 @@ return client.start(); | ||
const handler = sandbox.spy((_message) => { }); | ||
it('should fail if client is not running', async () => { | ||
it('should be registered to message emitter if client is not running', async () => { | ||
await resetClient(false); | ||
await (0, test_util_1.expectToThrowAsync)(() => client.onActionMessage(handler)); | ||
(0, chai_1.expect)(connection.onNotification.called).to.be.false; | ||
client.onActionMessage(handler); | ||
(0, chai_1.expect)(client.firstListenerAdded).to.be.true; | ||
}); | ||
it('should invoked the corresponding connection method', async () => { | ||
it('should be registered to message emitter if client is running', async () => { | ||
await resetClient(); | ||
client.onActionMessage(handler, 'someId'); | ||
(0, chai_1.expect)(connection.onNotification.withArgs(glsp_jsonrpc_client_1.JsonrpcGLSPClient.ActionMessageNotification).calledOnce).to.be.true; | ||
(0, chai_1.expect)(client.firstListenerAdded).to.be.true; | ||
}); | ||
it('should unregister lister if dispose is invoked', () => { | ||
resetClient(false); | ||
const clientId = 'clientId'; | ||
const toDispose = client.onActionMessage(handler, clientId); | ||
(0, chai_1.expect)(client.firstListenerAdded).to.be.true; | ||
toDispose.dispose(); | ||
(0, chai_1.expect)(client.lastListenerRemoved).to.be.true; | ||
}); | ||
}); | ||
@@ -223,0 +241,0 @@ describe('Connection events', () => { |
{ | ||
"name": "@eclipse-glsp/protocol", | ||
"version": "2.1.0-next.300+2247067", | ||
"version": "2.1.0-next.301+384cb84", | ||
"description": "The protocol definition for client-server communication in GLSP", | ||
@@ -62,3 +62,3 @@ "keywords": [ | ||
}, | ||
"gitHead": "2247067bfa9f60cfc74992d4831f6293f99b9f39" | ||
"gitHead": "384cb84624f57690508667165d682c68aa151231" | ||
} |
@@ -22,2 +22,3 @@ /******************************************************************************** | ||
import { remove } from '../../utils/array-util'; | ||
import { Emitter } from '../../utils/event'; | ||
import { expectToThrowAsync } from '../../utils/test-util'; | ||
@@ -72,9 +73,19 @@ import { ClientState } from '../glsp-client'; | ||
class TestJsonRpcClient extends BaseJsonrpcGLSPClient { | ||
protected override onActionMessageNotificationEmitter = new Emitter<ActionMessage>({ | ||
onFirstListenerAdd: () => (this.firstListenerAdded = true), | ||
onLastListenerRemove: () => (this.lastListenerRemoved = true) | ||
}); | ||
firstListenerAdded: boolean; | ||
lastListenerRemoved: boolean; | ||
} | ||
describe('Base JSON-RPC GLSP Client', () => { | ||
const sandbox = sinon.createSandbox(); | ||
const connection = sandbox.stub<StubMessageConnection>(new StubMessageConnection()); | ||
let client = new BaseJsonrpcGLSPClient({ id: 'test', connectionProvider: connection }); | ||
let client = new TestJsonRpcClient({ id: 'test', connectionProvider: connection }); | ||
async function resetClient(setRunning = true): Promise<void> { | ||
sandbox.reset(); | ||
client = new BaseJsonrpcGLSPClient({ id: 'test', connectionProvider: connection }); | ||
client = new TestJsonRpcClient({ id: 'test', connectionProvider: connection }); | ||
if (setRunning) { | ||
@@ -226,13 +237,21 @@ return client.start(); | ||
it('should fail if client is not running', async () => { | ||
it('should be registered to message emitter if client is not running', async () => { | ||
await resetClient(false); | ||
await expectToThrowAsync(() => client.onActionMessage(handler)); | ||
expect(connection.onNotification.called).to.be.false; | ||
client.onActionMessage(handler); | ||
expect(client.firstListenerAdded).to.be.true; | ||
}); | ||
it('should invoked the corresponding connection method', async () => { | ||
it('should be registered to message emitter if client is running', async () => { | ||
await resetClient(); | ||
client.onActionMessage(handler, 'someId'); | ||
expect(connection.onNotification.withArgs(JsonrpcGLSPClient.ActionMessageNotification).calledOnce).to.be.true; | ||
expect(client.firstListenerAdded).to.be.true; | ||
}); | ||
it('should unregister lister if dispose is invoked', () => { | ||
resetClient(false); | ||
const clientId = 'clientId'; | ||
const toDispose = client.onActionMessage(handler, clientId); | ||
expect(client.firstListenerAdded).to.be.true; | ||
toDispose.dispose(); | ||
expect(client.lastListenerRemoved).to.be.true; | ||
}); | ||
}); | ||
@@ -239,0 +258,0 @@ |
@@ -39,2 +39,7 @@ /******************************************************************************** | ||
protected onActionMessageNotificationEmitter = new Emitter<ActionMessage>(); | ||
protected get onActionMessageNotification(): Event<ActionMessage> { | ||
return this.onActionMessageNotificationEmitter.event; | ||
} | ||
constructor(options: JsonrpcGLSPClient.Options) { | ||
@@ -70,3 +75,3 @@ Object.assign(this, options); | ||
onActionMessage(handler: ActionMessageHandler, clientId?: string): Disposable { | ||
return this.checkedConnection.onNotification(JsonrpcGLSPClient.ActionMessageNotification, msg => { | ||
return this.onActionMessageNotification(msg => { | ||
if (!clientId || msg.clientId === clientId) { | ||
@@ -118,2 +123,3 @@ handler(msg); | ||
this.onStop = undefined; | ||
this.onActionMessageNotificationEmitter.dispose(); | ||
this.connectionPromise = undefined; | ||
@@ -135,2 +141,3 @@ this.resolvedConnection = undefined; | ||
connection.onClose(() => this.handleConnectionClosed()); | ||
connection.onNotification(JsonrpcGLSPClient.ActionMessageNotification, msg => this.onActionMessageNotificationEmitter.fire(msg)); | ||
return connection; | ||
@@ -137,0 +144,0 @@ } |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Manifest confusion
Supply chain riskThis package has inconsistent metadata. This could be malicious or caused by an error when publishing the package.
Found 1 instance in 1 package
Unidentified License
License(Experimental) Something that seems like a license was found, but its contents could not be matched with a known license.
Found 6 instances in 1 package
Manifest confusion
Supply chain riskThis package has inconsistent metadata. This could be malicious or caused by an error when publishing the package.
Found 1 instance in 1 package
Unidentified License
License(Experimental) Something that seems like a license was found, but its contents could not be matched with a known license.
Found 6 instances in 1 package
1250334
19174