Skip to content

Commit

Permalink
[json] don't wait when a stopped language server is ready
Browse files Browse the repository at this point in the history
Timing of resolving `LanguageClient.onReady` promise is changed in never version of `vscode-languageclient`. It could lead to a situation that clients still use `onReady` of a language client before reconnection.

Signed-off-by: Anton Kosyakov <anton.kosyakov@typefox.io>
  • Loading branch information
akosyakov committed Sep 18, 2019
1 parent d800d05 commit df1e55a
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 20 deletions.
27 changes: 11 additions & 16 deletions packages/json/src/browser/json-client-contribution.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import {
DocumentSelector
} from '@theia/languages/lib/browser';
import { JSON_LANGUAGE_ID, JSON_LANGUAGE_NAME, JSONC_LANGUAGE_ID } from '../common';
import { ResourceProvider } from '@theia/core';
import { ResourceProvider, DisposableCollection } from '@theia/core';
import URI from '@theia/core/lib/common/uri';
import { JsonPreferences } from './json-preferences';
import { JsonSchemaStore } from '@theia/core/lib/browser/json-schema-store';
Expand All @@ -46,18 +46,9 @@ export class JsonClientContribution extends BaseLanguageClientContribution {
) {
super(workspace, languages, languageClientFactory);
this.initializeJsonSchemaAssociations();
preferences.onPreferenceChanged(e => {
if (e.preferenceName === 'json.schemas') {
this.updateSchemas();
}
});
jsonSchemaStore.onSchemasChanged(() => {
this.updateSchemas();
});
this.updateSchemas();
}

protected async updateSchemas(): Promise<void> {
protected updateSchemas(client: ILanguageClient): void {
const allConfigs = [...this.jsonSchemaStore.getJsonSchemaConfigurations()];
const config = this.preferences['json.schemas'];
if (config instanceof Array) {
Expand All @@ -74,8 +65,6 @@ export class JsonClientContribution extends BaseLanguageClientContribution {
}
}
}
const client = await this.languageClient;
await client.onReady();
client.sendNotification('json/schemaAssociations', registry);
}

Expand All @@ -94,16 +83,22 @@ export class JsonClientContribution extends BaseLanguageClientContribution {
return [this.id];
}

protected onReady(languageClient: ILanguageClient): void {
protected onReady(languageClient: ILanguageClient, toStop: DisposableCollection): void {
super.onReady(languageClient, toStop);
// handle content request
languageClient.onRequest('vscode/content', async (uriPath: string) => {
const uri = new URI(uriPath);
const resource = await this.resourceProvider(uri);
const text = await resource.readContents();
return text;
});
super.onReady(languageClient);
setTimeout(() => this.initializeJsonSchemaAssociations());
toStop.push(this.preferences.onPreferenceChanged(e => {
if (e.preferenceName === 'json.schemas') {
this.updateSchemas(languageClient);
}
}));
toStop.push(this.jsonSchemaStore.onSchemasChanged(() => this.updateSchemas(languageClient)));
this.updateSchemas(languageClient);
}

protected async initializeJsonSchemaAssociations(): Promise<void> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,8 +160,9 @@ export abstract class BaseLanguageClientContribution implements LanguageClientCo
}
})()));
toStop.push(messageConnection.onClose(() => this.forceRestart()));
this.onWillStart(this._languageClient!);
this._languageClient!.start();
// it should be called after `start` that `onReady` promise gets reinitialized
this.onWillStart(this._languageClient!, toStop);
}
}, { reconnecting: false });
} catch (e) {
Expand Down Expand Up @@ -189,11 +190,11 @@ export abstract class BaseLanguageClientContribution implements LanguageClientCo
this.activate();
}

protected onWillStart(languageClient: ILanguageClient): void {
languageClient.onReady().then(() => this.onReady(languageClient));
protected onWillStart(languageClient: ILanguageClient, toStop?: DisposableCollection): void {
languageClient.onReady().then(() => this.onReady(languageClient, toStop));
}

protected onReady(languageClient: ILanguageClient): void {
protected onReady(languageClient: ILanguageClient, toStop?: DisposableCollection): void {
this._languageClient = languageClient;
this.resolveReady(this._languageClient);
this.waitForReady();
Expand Down

0 comments on commit df1e55a

Please sign in to comment.