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 current IDE language on start-up #1261

Merged
merged 1 commit into from
Jul 29, 2022
Merged

Fix current IDE language on start-up #1261

merged 1 commit into from
Jul 29, 2022

Conversation

AlbyIanna
Copy link
Contributor

@AlbyIanna AlbyIanna commented Jul 27, 2022

Motivation

IDE2 might forget the selected language

I noticed the root of the problem is here:

https://github.com/eclipse-theia/theia/blob/f4327c2f0c0f47f960a302590a51698879357841/packages/core/src/node/i18n/localization-backend-contribution.ts#L38-L39

req.params.locale is always restored correctly, but this.localizationProvider.getAvailableLanguages() doesn't return all the available languages. This happens because getAvailableLanguages() returns all the registered localizations with languagePack set to true (unless we call getAvailableLanguages(true), in that case, it would always return all the languages):

https://github.com/eclipse-theia/theia/blob/f4327c2f0c0f47f960a302590a51698879357841/packages/core/src/node/i18n/localization-provider.ts#L50

The weird thing is that this happens also with some languages registered with a language pack (so they'll eventually have languagePack set to true). I say some languages because some others work as expected. I strongly believe this is happening because of a race condition happening because getAvailableLanguages is called before the language packs are finished loading.

EDIT:
The root cause of this appears to be that PluginDeployer completes the execution of deployPlugins after the express backend tries to restore the current language

https://github.com/eclipse-theia/theia/blob/26649452aeac342f7551b8cae502740799085772/packages/plugin-ext/src/main/node/plugin-deployer-impl.ts#L269

The solution I've found is to wait for this event to emit

Change description

Re-implemented the restoration of the language in localization-backend-contribution.ts

Wait for the plugins to complete the deploy before restoring the current language:
https://github.com/arduino/arduino-ide/pull/1261/files#diff-19d891f1ffb8ce2979b6bee0d166700e20a6b965d1be5f72b3e331d0442eba35R16-R18

Other information

This PR is a workaround for a Theia issue.
I opened an issue in the Theia repo here: eclipse-theia/theia#11471
As soon as Theia fixes it, we can remove this code and the rebinding.

I've also opened a PR on Theia here: eclipse-theia/theia#11472

Fixes #1219

Reviewer checklist

  • PR addresses a single concern.
  • The PR has no duplicates (please search among the Pull Requests before creating one)
  • PR title and description are properly filled.
  • Docs have been added / updated (for bug fixes / features)

Copy link
Contributor

@kittaakos kittaakos left a comment

Choose a reason for hiding this comment

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

It does not work for me. I tried the steps from #1219.

language_fix_verification.mp4

@AlbyIanna AlbyIanna force-pushed the fix-current-language branch from 4ddf0a0 to 6a767ea Compare July 28, 2022 14:22
@AlbyIanna AlbyIanna changed the title Fix IDE current language on restart Fix current IDE language on start-up Jul 28, 2022
@AlbyIanna
Copy link
Contributor Author

Thanks for testing it @kittaakos. I've just updated a PR with a new fix, now it should work.

@AlbyIanna AlbyIanna requested a review from kittaakos July 28, 2022 15:33
Copy link
Contributor

@kittaakos kittaakos left a comment

Choose a reason for hiding this comment

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

Besides a few remarks, it's looking great. Please react to them, and I will do the review afterward with the final changeset. Thank you!

@injectable()
export class LocalizationBackendContribution extends TheiaLocalizationBackendContribution {
@inject(PluginDeployer)
protected readonly pluginDeployer: PluginDeployerImpl;
Copy link
Contributor

Choose a reason for hiding this comment

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

can be private.

@inject(PluginDeployer)
protected readonly pluginDeployer: PluginDeployerImpl;

private initialized = new Deferred<void>();
Copy link
Contributor

Choose a reason for hiding this comment

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

should be readonly

this.pluginDeployer.onDidDeploy(() => {
this.initialized.resolve();
});
await this.localizationRegistry.initialize();
Copy link
Contributor

Choose a reason for hiding this comment

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

Why not calling super.initialize(). The default Theia behavior is what IDE2 wants to use besides the listener.

private initialized = new Deferred<void>();

override async initialize(): Promise<void> {
this.pluginDeployer.onDidDeploy(() => {
Copy link
Contributor

Choose a reason for hiding this comment

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

It's an OK solution for now, but the deferred promise will never resolve if the plugins are deployed by the time this initialize function is called.

Copy link
Contributor

Choose a reason for hiding this comment

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

@kittaakos is that a likely scenario? (getting to this initialize post deploy)

Copy link
Contributor

Choose a reason for hiding this comment

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

No, I do not think so.

Based on the method names (initialize and start), I do not think it will cause an issue at runtime, but I did not thoroughly check the Theia code.

Copy link
Contributor

Choose a reason for hiding this comment

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

@AlbyIanna lets keep note of this, maybe we'll get a hint here anyway.

Waiting for the deploy of the language plugins is neecessary to avoid checking the available
languages before they're finished to be loaded: https://github.com/eclipse-theia/theia/issues/11471
*/
await this.initialized.promise;
Copy link
Contributor

Choose a reason for hiding this comment

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

Just wondering, did you check if it slows down the IDE2 startup? The frontend must wait for this, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm not sure how to calculate this.

With the current build, I can see these two log lines:

root INFO [2c0ce3a6-ca5a-4f40-b831-533e06823a9f] Load contributions of 16 plugins: 86.5 ms [Finished 4.873 s after frontend start]
root INFO [2c0ce3a6-ca5a-4f40-b831-533e06823a9f] Start of 16 plugins: 575.4 ms [Finished 5.460 s after frontend start]

Then, in this case, I think the frontend is slowed down by 86.5 ms + 574.4 ms = 660.9 ms

Am I correct?

Copy link
Contributor

Choose a reason for hiding this comment

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

const start = performance.now();
await this.initialized.promise;
console.log('took: ' + (performance.now() - start) + ' ms')

Copy link
Contributor Author

Choose a reason for hiding this comment

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

root INFO took: 405.16497199982405 ms

Quite significant. I suppose this delay will increase as we keep adding new language packs.

Copy link
Contributor

@davegarthsimpson davegarthsimpson Jul 29, 2022

Choose a reason for hiding this comment

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

This should be done fairly quickly without impacting the load time on Electron

from: here

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've pushed the code to log the performance so that we see how the time grows as we keep adding new language packs.

@AlbyIanna AlbyIanna force-pushed the fix-current-language branch from 6a767ea to c7ed2a2 Compare July 29, 2022 07:37
@AlbyIanna AlbyIanna requested a review from kittaakos July 29, 2022 08:29
@AlbyIanna AlbyIanna force-pushed the fix-current-language branch from c7ed2a2 to 7ef1f02 Compare July 29, 2022 08:30
this.pluginDeployer.onDidDeploy(() => {
this.initialized.resolve();
});
super.initialize();
Copy link
Contributor

@kittaakos kittaakos Jul 29, 2022

Choose a reason for hiding this comment

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

This is a bug. You either must return with super.initialize() or await for it.

@AlbyIanna AlbyIanna requested a review from kittaakos July 29, 2022 09:48
@AlbyIanna AlbyIanna force-pushed the fix-current-language branch from 7ef1f02 to f613397 Compare July 29, 2022 10:13
Copy link
Contributor

@kittaakos kittaakos left a comment

Choose a reason for hiding this comment

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

This is working great ✅

Thank you so much for tracking down the bug upstream, opening an issue, and proposing fix for the Theia community. Excellent effort 💪

Copy link
Contributor

@davegarthsimpson davegarthsimpson left a comment

Choose a reason for hiding this comment

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

Nice one @AlbyIanna

@AlbyIanna AlbyIanna merged commit 124738d into main Jul 29, 2022
@AlbyIanna AlbyIanna deleted the fix-current-language branch July 29, 2022 13:08
@per1234 per1234 added topic: code Related to content of the project itself type: imperfection Perceived defect in any part of project labels Jul 30, 2022
@kittaakos kittaakos mentioned this pull request Nov 11, 2022
4 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
topic: code Related to content of the project itself type: imperfection Perceived defect in any part of project
Projects
None yet
Development

Successfully merging this pull request may close these issues.

IDE might forget the selected language
4 participants