Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix reconnection of native language servers #6205

Merged
merged 2 commits into from
Sep 18, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 2 additions & 8 deletions packages/cpp/src/browser/cpp-language-client-contribution.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,7 @@ export class CppLanguageClientContribution extends BaseLanguageClientContributio
@postConstruct()
protected init(): void {
this.cppBuildConfigurations.onActiveConfigChange2(() => this.onActiveBuildConfigChanged());
this.cppPreferences.onPreferenceChanged(e => {
if (this.running) {
this.restart();
}
});
this.cppPreferences.onPreferenceChanged(() => this.restart());
}

protected onReady(languageClient: ILanguageClient): void {
Expand Down Expand Up @@ -147,9 +143,7 @@ export class CppLanguageClientContribution extends BaseLanguageClientContributio
}

protected onActiveBuildConfigChanged(): void {
if (this.running) {
this.restart();
}
this.restart();
}

protected get documentSelector(): string[] {
Expand Down
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());
akosyakov marked this conversation as resolved.
Show resolved Hide resolved
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
17 changes: 11 additions & 6 deletions packages/languages/src/browser/language-client-contribution.ts
Original file line number Diff line number Diff line change
Expand Up @@ -159,15 +159,16 @@ export abstract class BaseLanguageClientContribution implements LanguageClientCo
} catch { /* no-op */ }
}
})()));
toStop.push(messageConnection.onClose(() => this.restart()));
this.onWillStart(this._languageClient!);
toStop.push(messageConnection.onClose(() => this.forceRestart()));
this._languageClient!.start();
// it should be called after `start` that `onReady` promise gets reinitialized
this.onWillStart(this._languageClient!, toStop);
}
}, { reconnecting: false });
} catch (e) {
console.error(e);
if (!toStop.disposed) {
this.restart();
this.forceRestart();
}
}
}
Expand All @@ -181,15 +182,19 @@ export abstract class BaseLanguageClientContribution implements LanguageClientCo
if (!this.running) {
return;
}
this.forceRestart();
}

protected forceRestart(): void {
this.deactivate();
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