Skip to content

Commit d95f6de

Browse files
committed
- migrate only from active window
- respect old value while reading
1 parent 08bca48 commit d95f6de

File tree

1 file changed

+31
-6
lines changed

1 file changed

+31
-6
lines changed

src/vs/workbench/services/editor/browser/editorOverrideService.ts

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry';
2222
import { registerSingleton } from 'vs/platform/instantiation/common/extensions';
2323
import { IStorageService, StorageScope, StorageTarget } from 'vs/platform/storage/common/storage';
2424
import { IExtensionService } from 'vs/workbench/services/extensions/common/extensions';
25+
import { IHostService } from 'vs/workbench/services/host/browser/host';
26+
import { ILogService } from 'vs/platform/log/common/log';
2527

2628
interface IContributedEditorInput extends IEditorInput {
2729
viewType?: string;
@@ -56,13 +58,20 @@ export class EditorOverrideService extends Disposable implements IEditorOverride
5658
@INotificationService private readonly notificationService: INotificationService,
5759
@ITelemetryService private readonly telemetryService: ITelemetryService,
5860
@IStorageService private readonly storageService: IStorageService,
59-
@IExtensionService private readonly extensionService: IExtensionService
61+
@IExtensionService private readonly extensionService: IExtensionService,
62+
@IHostService private readonly hostService: IHostService,
63+
@ILogService private readonly logService: ILogService,
6064
) {
6165
super();
6266
// Read in the cache on statup
6367
this.cache = new Set<string>(JSON.parse(this.storageService.get(EditorOverrideService.overrideCacheStorageID, StorageScope.GLOBAL, JSON.stringify([]))));
6468
this.storageService.remove(EditorOverrideService.overrideCacheStorageID, StorageScope.GLOBAL);
65-
this.convertOldAssociationFormat();
69+
this.hostService.hadLastFocus().then(hadLastFocus => {
70+
if (!hadLastFocus) {
71+
return;
72+
}
73+
this.convertOldAssociationFormat();
74+
});
6675

6776
this._register(this.storageService.onWillSaveState(() => {
6877
// We want to store the glob patterns we would activate on, this allows us to know if we need to await the ext host on startup for opening a resource
@@ -75,8 +84,10 @@ export class EditorOverrideService extends Disposable implements IEditorOverride
7584
});
7685

7786
// When the setting changes we want to ensure that it is properly converted
78-
this._register(this.configurationService.onDidChangeConfiguration(() => {
79-
this.convertOldAssociationFormat();
87+
this._register(this.configurationService.onDidChangeConfiguration((e) => {
88+
if (e.affectsConfiguration(editorsAssociationsSettingId)) {
89+
this.convertOldAssociationFormat();
90+
}
8091
}));
8192
}
8293

@@ -177,7 +188,7 @@ export class EditorOverrideService extends Disposable implements IEditorOverride
177188
}
178189

179190
private convertOldAssociationFormat(): void {
180-
const rawAssociations = this.configurationService.getValue<EditorAssociations | { [fileNamePattern: string]: string }>(editorsAssociationsSettingId) || [];
191+
const rawAssociations = this.configurationService.getValue<EditorAssociations | { [fileNamePattern: string]: string }>(editorsAssociationsSettingId) || {};
181192
// If it's not an array, then it's the new format
182193
if (!Array.isArray(rawAssociations)) {
183194
return;
@@ -189,11 +200,25 @@ export class EditorOverrideService extends Disposable implements IEditorOverride
189200
newSettingObject[association.filenamePattern] = association.viewType;
190201
}
191202
}
203+
this.logService.info(`Migrating ${editorsAssociationsSettingId}`);
192204
this.configurationService.updateValue(editorsAssociationsSettingId, newSettingObject);
193205
}
194206

195207
private getAllUserAssociations(): EditorAssociations {
196-
const rawAssociations = this.configurationService.getValue<{ [fileNamePattern: string]: string }>(editorsAssociationsSettingId) || [];
208+
let rawAssociations = this.configurationService.getValue<EditorAssociations | { [fileNamePattern: string]: string }>(editorsAssociationsSettingId) || {};
209+
210+
// If it's an array then it is old format
211+
if (Array.isArray(rawAssociations)) {
212+
// Make the correctly formatted object
213+
const newValue = Object.create(null);
214+
for (const association of rawAssociations) {
215+
if (association.filenamePattern) {
216+
newValue[association.filenamePattern] = association.viewType;
217+
}
218+
}
219+
rawAssociations = newValue;
220+
}
221+
197222
let associations = [];
198223
for (const [key, value] of Object.entries(rawAssociations)) {
199224
const association: EditorAssociation = {

0 commit comments

Comments
 (0)