Skip to content

Commit 555da87

Browse files
Akos Kittakittaakos
Akos Kitta
authored andcommitted
Editor manager should be singleton.
Added some logging when filtering the layout data. Signed-off-by: Akos Kitta <a.kitta@arduino.cc>
1 parent df8658e commit 555da87

File tree

3 files changed

+27
-1
lines changed

3 files changed

+27
-1
lines changed

arduino-ide-extension/src/browser/arduino-ide-frontend-module.ts

+2
Original file line numberDiff line numberDiff line change
@@ -541,6 +541,8 @@ export default new ContainerModule((bind, unbind, isBound, rebind) => {
541541
bind(SearchInWorkspaceWidget).toSelf();
542542
rebind(TheiaSearchInWorkspaceWidget).toService(SearchInWorkspaceWidget);
543543

544+
// Disabled reference counter in the editor manager to avoid opening the same editor (with different opener options) multiple times.
545+
bind(EditorManager).toSelf().inSingletonScope();
544546
rebind(TheiaEditorManager).to(EditorManager);
545547

546548
// replace search icon

arduino-ide-extension/src/browser/theia/core/shell-layout-restorer.ts

+23-1
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,16 @@
1-
import { injectable } from '@theia/core/shared/inversify';
1+
import { inject, injectable } from '@theia/core/shared/inversify';
22
import { FrontendApplication } from '@theia/core/lib/browser/frontend-application';
33
import { ShellLayoutRestorer as TheiaShellLayoutRestorer } from '@theia/core/lib/browser/shell/shell-layout-restorer';
4+
import { EditorManager } from '@theia/editor/lib/browser';
45

56
@injectable()
67
export class ShellLayoutRestorer extends TheiaShellLayoutRestorer {
8+
// The editor manager is unused in the layout restorer.
9+
// We inject the editor manager to achieve better logging when filtering duplicate editor tabs.
10+
// Feel free to remove it in later IDE2 releases if the duplicate editor tab issues do not occur anymore.
11+
@inject(EditorManager)
12+
private readonly editorManager: EditorManager;
13+
714
// Workaround for https://github.com/eclipse-theia/theia/issues/6579.
815
async storeLayoutAsync(app: FrontendApplication): Promise<void> {
916
if (this.shouldStoreLayout) {
@@ -35,21 +42,36 @@ export class ShellLayoutRestorer extends TheiaShellLayoutRestorer {
3542

3643
const layoutData = await this.inflate(serializedLayoutData);
3744
// workaround to remove duplicated tabs
45+
console.log(
46+
'>>> Filtering persisted layout data to eliminate duplicate editor tabs...'
47+
);
3848
const filesUri: string[] = [];
3949
if ((layoutData as any)?.mainPanel?.main?.widgets) {
4050
(layoutData as any).mainPanel.main.widgets = (
4151
layoutData as any
4252
).mainPanel.main.widgets.filter((widget: any) => {
4353
const uri = widget.getResourceUri().toString();
4454
if (filesUri.includes(uri)) {
55+
console.log(`[SKIP]: Already visited editor URI: '${uri}'.`);
4556
return false;
4657
}
58+
console.log(`[OK]: Visited editor URI: '${uri}'.`);
4759
filesUri.push(uri);
4860
return true;
4961
});
5062
}
63+
console.log('<<< Filtered the layout data before restoration.');
5164

5265
await app.shell.setLayoutData(layoutData);
66+
const allOpenedEditors = this.editorManager.all;
67+
// If any editor was visited during the layout data filtering,
68+
// but the editor manager does not know about opened editors, then
69+
// the IDE2 will show duplicate editors.
70+
if (filesUri.length && !allOpenedEditors.length) {
71+
console.warn(
72+
'Inconsistency detected between the editor manager and the restored layout data. Editors were detected to be open in the layout data from the previous session, but the editor manager does not know about the opened editor.'
73+
);
74+
}
5375
this.logger.info('<<< The layout has been successfully restored.');
5476
return true;
5577
}

arduino-ide-extension/src/browser/theia/editor/editor-manager.ts

+2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1+
import { injectable } from '@theia/core/shared/inversify';
12
import { EditorManager as TheiaEditorManager } from '@theia/editor/lib/browser/editor-manager';
23

4+
@injectable()
35
export class EditorManager extends TheiaEditorManager {
46
protected override getOrCreateCounterForUri(): number {
57
return 0;

0 commit comments

Comments
 (0)