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

Handle pref display without plugins #9403

Conversation

colin-grant-work
Copy link
Contributor

What it does

A bug was discovered by a user of the Yo Theia Extension Generator in which the preference widget was not displaying preferences unless an extension with plugin support was included in the dependencies.

The basic problem was that the PreferenceTreeGenerator was waiting for an event from the PreferenceSchemaProvider before initializing its tree.

@postConstruct()
protected init(): void {
this.schemaProvider.onDidPreferenceSchemaChanged(() => this.handleChangedSchema());
}

That event is only fired when plugins call the setSchema method:

setSchema(schema: PreferenceSchema): Disposable {
const changes = this.doSetSchema(schema);
if (!changes.length) {
return Disposable.NULL;
}
this.fireDidPreferenceSchemaChanged();
this.emitPreferencesChangedEvent(changes);
return Disposable.create(() => {
const inverseChanges = this.doUnsetSchema(changes);
if (!inverseChanges.length) {
return;
}
this.fireDidPreferenceSchemaChanged();
this.emitPreferencesChangedEvent(inverseChanges);
});
}

Internal preference contributions only call doSetSchema, which does not fire any events. I believe this behavior is correct: the schema hasn't changed, but only been initialized.

this.preferenceContributions.getContributions().forEach(contrib => {
this.doSetSchema(contrib.schema);
});

This PR modifies the behavior of the PreferenceTreeGenerator to generate a tree when the PreferenceSchemaProvider is ready (after all internal preference contributions have been processed) without waiting for an onSchemaChanged event.

How to test

  1. Modify the electron or browser package.json to have only these Theia packages as dependencies:
  "dependencies": {
    "@theia/core": "1.12.0",
    "@theia/editor": "1.12.0",
    "@theia/electron": "1.12.0",
    "@theia/filesystem": "1.12.0",
    "@theia/markers": "1.12.0",
    "@theia/messages": "1.12.0",
    "@theia/monaco": "1.12.0",
    "@theia/navigator": "1.12.0",
    "@theia/preferences": "1.12.0",
    "@theia/process": "1.12.0",
    "@theia/terminal": "1.12.0",
    "@theia/workspace": "1.12.0",
  },
  1. Build and start the application, and open the preferences view (ctrl + ,)
  2. Observe that the preferences are populated.

image

Review checklist

Reminder for reviewers

Signed-off-by: Colin Grant [email protected]

@vince-fugnitto vince-fugnitto added bug bugs found in the application preferences issues related to preferences labels Apr 26, 2021
Copy link
Member

@vince-fugnitto vince-fugnitto left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I confirmed that the pull-request fixes the issue 👍

@colin-grant-work colin-grant-work merged commit b83b9b2 into eclipse-theia:master Apr 28, 2021
@vince-fugnitto vince-fugnitto added this to the 1.13.0 milestone Apr 29, 2021
@jwebstar
Copy link

I'm seeing this behaviour again in 1.15. When I generate a new extension with theia extension generator preferences are listed. But if I change the package.json theia dependencies from 'latest' to 'next' there are no preferences listed in the browser or Electron. Adding the dependency "@theia/external-terminal": "next", to Electron brings back the preferences in Electron.

@colin-grant-work
Copy link
Contributor Author

@jwebstar, thanks for bringing this to my attention. I had a couple of lines of work running in parallel, and it's possible that a later merge ended up missing this fix. I'll check into it.

@colin-grant-work colin-grant-work deleted the bugfix/handle-no-schema-events branch June 14, 2021 17:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug bugs found in the application preferences issues related to preferences
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants