-
-
Notifications
You must be signed in to change notification settings - Fork 399
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
Conversation
There was a problem hiding this 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
4ddf0a0
to
6a767ea
Compare
Thanks for testing it @kittaakos. I've just updated a PR with a new fix, now it should work. |
There was a problem hiding this 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; |
There was a problem hiding this comment.
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>(); |
There was a problem hiding this comment.
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(); |
There was a problem hiding this comment.
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(() => { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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')
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
6a767ea
to
c7ed2a2
Compare
c7ed2a2
to
7ef1f02
Compare
this.pluginDeployer.onDidDeploy(() => { | ||
this.initialized.resolve(); | ||
}); | ||
super.initialize(); |
There was a problem hiding this comment.
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.
7ef1f02
to
f613397
Compare
There was a problem hiding this 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 💪
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice one @AlbyIanna
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, butthis.localizationProvider.getAvailableLanguages()
doesn't return all the available languages. This happens becausegetAvailableLanguages()
returns all the registered localizations withlanguagePack
set totrue
(unless we callgetAvailableLanguages(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 totrue
). I say some languages because some others work as expected. I strongly believe this is happening because of a race condition happening becausegetAvailableLanguages
is called before the language packs are finished loading.EDIT:
The root cause of this appears to be that
PluginDeployer
completes the execution ofdeployPlugins
after the express backend tries to restore the current languagehttps://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