-
-
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import * as express from 'express'; | ||
import { inject, injectable } from '@theia/core/shared/inversify'; | ||
import { LocalizationBackendContribution as TheiaLocalizationBackendContribution } from '@theia/core/lib/node/i18n/localization-backend-contribution'; | ||
import { PluginDeployer } from '@theia/plugin-ext/lib/common/plugin-protocol'; | ||
import { PluginDeployerImpl } from '@theia/plugin-ext/lib/main/node/plugin-deployer-impl'; | ||
import { Deferred } from '@theia/core/lib/common/promise-util'; | ||
|
||
@injectable() | ||
export class LocalizationBackendContribution extends TheiaLocalizationBackendContribution { | ||
@inject(PluginDeployer) | ||
private readonly pluginDeployer: PluginDeployerImpl; | ||
|
||
private readonly initialized = new Deferred<void>(); | ||
|
||
override async initialize(): Promise<void> { | ||
this.pluginDeployer.onDidDeploy(() => { | ||
this.initialized.resolve(); | ||
}); | ||
return super.initialize(); | ||
} | ||
|
||
override configure(app: express.Application): void { | ||
app.get('/i18n/:locale', async (req, res) => { | ||
let locale = req.params.locale; | ||
/* | ||
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 | ||
*/ | ||
const start = performance.now(); | ||
await this.initialized.promise; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 commentThe 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:
Then, in this case, I think the frontend is slowed down by Am I correct? There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 commentThe reason will be displayed to describe this comment to others. Learn more.
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 commentThe reason will be displayed to describe this comment to others. Learn more.
from: here There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
console.info( | ||
'Waiting for the deploy of the language plugins took: ' + | ||
(performance.now() - start) + | ||
' ms.' | ||
); | ||
locale = this.localizationProvider | ||
.getAvailableLanguages() | ||
.some((e) => e.languageId === locale) | ||
? locale | ||
: 'en'; | ||
this.localizationProvider.setCurrentLanguage(locale); | ||
res.send(this.localizationProvider.loadLocalization(locale)); | ||
}); | ||
} | ||
} |
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
andstart
), 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.