From ec45a3a56cdb8f3a931e9cbd3dc2a3142d13f8a5 Mon Sep 17 00:00:00 2001 From: Martin Aeschlimann Date: Mon, 28 Nov 2016 10:57:10 +0100 Subject: [PATCH] [json] wait for onReady before using client --- extensions/json/client/src/jsonMain.ts | 35 +++++++++++++------------- 1 file changed, 18 insertions(+), 17 deletions(-) diff --git a/extensions/json/client/src/jsonMain.ts b/extensions/json/client/src/jsonMain.ts index 7dc61a32e1c..a00cc5ca01f 100644 --- a/extensions/json/client/src/jsonMain.ts +++ b/extensions/json/client/src/jsonMain.ts @@ -68,25 +68,26 @@ export function activate(context: ExtensionContext) { // Create the language client and start the client. let client = new LanguageClient('json', localize('jsonserver.name', 'JSON Language Server'), serverOptions, clientOptions); - client.onTelemetry(e => { - if (telemetryReporter) { - telemetryReporter.sendTelemetryEvent(e.key, e.data); - } - }); - - // handle content request - client.onRequest(VSCodeContentRequest.type, (uriPath: string) => { - let uri = Uri.parse(uriPath); - return workspace.openTextDocument(uri).then(doc => { - return doc.getText(); - }, error => { - return Promise.reject(error); - }); - }); - let disposable = client.start(); + client.onReady().then(() => { + client.onTelemetry(e => { + if (telemetryReporter) { + telemetryReporter.sendTelemetryEvent(e.key, e.data); + } + }); - client.sendNotification(SchemaAssociationNotification.type, getSchemaAssociation(context)); + // handle content request + client.onRequest(VSCodeContentRequest.type, (uriPath: string) => { + let uri = Uri.parse(uriPath); + return workspace.openTextDocument(uri).then(doc => { + return doc.getText(); + }, error => { + return Promise.reject(error); + }); + }); + + client.sendNotification(SchemaAssociationNotification.type, getSchemaAssociation(context)); + }); // Push the disposable to the context's subscriptions so that the // client can be deactivated on extension deactivation