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
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
8 changes: 7 additions & 1 deletion arduino-ide-extension/src/node/arduino-ide-backend-module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ import {
} from '../common/protocol/authentication-service';
import { ArduinoFirmwareUploaderImpl } from './arduino-firmware-uploader-impl';
import { PlotterBackendContribution } from './plotter/plotter-backend-contribution';
import { ArduinoLocalizationContribution } from './arduino-localization-contribution';
import { ArduinoLocalizationContribution } from './i18n/arduino-localization-contribution';
import { LocalizationContribution } from '@theia/core/lib/node/i18n/localization-contribution';
import { MonitorManagerProxyImpl } from './monitor-manager-proxy-impl';
import { MonitorManager, MonitorManagerName } from './monitor-manager';
Expand All @@ -102,6 +102,8 @@ import WebSocketProviderImpl from './web-socket/web-socket-provider-impl';
import { WebSocketProvider } from './web-socket/web-socket-provider';
import { ClangFormatter } from './clang-formatter';
import { FormatterPath } from '../common/protocol/formatter';
import { LocalizationBackendContribution } from './i18n/localization-backend-contribution';
import { LocalizationBackendContribution as TheiaLocalizationBackendContribution } from '@theia/core/lib/node/i18n/localization-backend-contribution';

export default new ContainerModule((bind, unbind, isBound, rebind) => {
bind(BackendApplication).toSelf().inSingletonScope();
Expand Down Expand Up @@ -395,4 +397,8 @@ export default new ContainerModule((bind, unbind, isBound, rebind) => {
bind(BackendApplicationContribution).toService(PlotterBackendContribution);
bind(ArduinoLocalizationContribution).toSelf().inSingletonScope();
bind(LocalizationContribution).toService(ArduinoLocalizationContribution);
bind(LocalizationBackendContribution).toSelf().inSingletonScope();
rebind(TheiaLocalizationBackendContribution).toService(
LocalizationBackendContribution
);
});
Original file line number Diff line number Diff line change
Expand Up @@ -11,142 +11,142 @@ export class ArduinoLocalizationContribution
async registerLocalizations(registry: LocalizationRegistry): Promise<void> {
registry.registerLocalizationFromRequire(
'af',
require('../../build/i18n/af.json')
require('../../../build/i18n/af.json')
);

registry.registerLocalizationFromRequire(
'en',
require('../../build/i18n/en.json')
require('../../../build/i18n/en.json')
);

registry.registerLocalizationFromRequire(
'fr',
require('../../build/i18n/fr.json')
require('../../../build/i18n/fr.json')
);

registry.registerLocalizationFromRequire(
'ko',
require('../../build/i18n/ko.json')
require('../../../build/i18n/ko.json')
);

registry.registerLocalizationFromRequire(
'pt-br',
require('../../build/i18n/pt.json')
require('../../../build/i18n/pt.json')
);

registry.registerLocalizationFromRequire(
'uk_UA',
require('../../build/i18n/uk_UA.json')
require('../../../build/i18n/uk_UA.json')
);

registry.registerLocalizationFromRequire(
'ar',
require('../../build/i18n/ar.json')
require('../../../build/i18n/ar.json')
);

registry.registerLocalizationFromRequire(
'es',
require('../../build/i18n/es.json')
require('../../../build/i18n/es.json')
);

registry.registerLocalizationFromRequire(
'he',
require('../../build/i18n/he.json')
require('../../../build/i18n/he.json')
);

registry.registerLocalizationFromRequire(
'my_MM',
require('../../build/i18n/my_MM.json')
require('../../../build/i18n/my_MM.json')
);

registry.registerLocalizationFromRequire(
'ro',
require('../../build/i18n/ro.json')
require('../../../build/i18n/ro.json')
);

registry.registerLocalizationFromRequire(
'zh-cn',
require('../../build/i18n/zh.json')
require('../../../build/i18n/zh.json')
);

registry.registerLocalizationFromRequire(
'bg',
require('../../build/i18n/bg.json')
require('../../../build/i18n/bg.json')
);

registry.registerLocalizationFromRequire(
'eu',
require('../../build/i18n/eu.json')
require('../../../build/i18n/eu.json')
);

registry.registerLocalizationFromRequire(
'hu',
require('../../build/i18n/hu.json')
require('../../../build/i18n/hu.json')
);

registry.registerLocalizationFromRequire(
'ne',
require('../../build/i18n/ne.json')
require('../../../build/i18n/ne.json')
);

registry.registerLocalizationFromRequire(
'ru',
require('../../build/i18n/ru.json')
require('../../../build/i18n/ru.json')
);

registry.registerLocalizationFromRequire(
'zh_TW',
require('../../build/i18n/zh_TW.json')
require('../../../build/i18n/zh_TW.json')
);

registry.registerLocalizationFromRequire(
'de',
require('../../build/i18n/de.json')
require('../../../build/i18n/de.json')
);

registry.registerLocalizationFromRequire(
'fa',
require('../../build/i18n/fa.json')
require('../../../build/i18n/fa.json')
);

registry.registerLocalizationFromRequire(
'it',
require('../../build/i18n/it.json')
require('../../../build/i18n/it.json')
);

registry.registerLocalizationFromRequire(
'nl',
require('../../build/i18n/nl.json')
require('../../../build/i18n/nl.json')
);

registry.registerLocalizationFromRequire(
'sv_SE',
require('../../build/i18n/sv_SE.json')
require('../../../build/i18n/sv_SE.json')
);

registry.registerLocalizationFromRequire(
'el',
require('../../build/i18n/el.json')
require('../../../build/i18n/el.json')
);

registry.registerLocalizationFromRequire(
'fil',
require('../../build/i18n/fil.json')
require('../../../build/i18n/fil.json')
);

registry.registerLocalizationFromRequire(
'ja',
require('../../build/i18n/ja.json')
require('../../../build/i18n/ja.json')
);

registry.registerLocalizationFromRequire(
'pl',
require('../../build/i18n/pl.json')
require('../../../build/i18n/pl.json')
);

registry.registerLocalizationFromRequire(
'tr',
require('../../build/i18n/tr.json')
require('../../../build/i18n/tr.json')
);
}
}
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(() => {
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.

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;
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.

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));
});
}
}