@@ -22,6 +22,8 @@ import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry';
22
22
import { registerSingleton } from 'vs/platform/instantiation/common/extensions' ;
23
23
import { IStorageService , StorageScope , StorageTarget } from 'vs/platform/storage/common/storage' ;
24
24
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' ;
25
27
26
28
interface IContributedEditorInput extends IEditorInput {
27
29
viewType ?: string ;
@@ -56,7 +58,9 @@ export class EditorOverrideService extends Disposable implements IEditorOverride
56
58
@INotificationService private readonly notificationService : INotificationService ,
57
59
@ITelemetryService private readonly telemetryService : ITelemetryService ,
58
60
@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 ,
60
64
) {
61
65
super ( ) ;
62
66
// Read in the cache on statup
@@ -75,8 +79,10 @@ export class EditorOverrideService extends Disposable implements IEditorOverride
75
79
} ) ;
76
80
77
81
// When the setting changes we want to ensure that it is properly converted
78
- this . _register ( this . configurationService . onDidChangeConfiguration ( ( ) => {
79
- this . convertOldAssociationFormat ( ) ;
82
+ this . _register ( this . configurationService . onDidChangeConfiguration ( ( e ) => {
83
+ if ( e . affectsConfiguration ( editorsAssociationsSettingId ) ) {
84
+ this . convertOldAssociationFormat ( ) ;
85
+ }
80
86
} ) ) ;
81
87
}
82
88
@@ -177,23 +183,42 @@ export class EditorOverrideService extends Disposable implements IEditorOverride
177
183
}
178
184
179
185
private convertOldAssociationFormat ( ) : void {
180
- const rawAssociations = this . configurationService . getValue < EditorAssociations | { [ fileNamePattern : string ] : string } > ( editorsAssociationsSettingId ) || [ ] ;
181
- // If it's not an array, then it's the new format
182
- if ( ! Array . isArray ( rawAssociations ) ) {
183
- return ;
184
- }
185
- let newSettingObject = Object . create ( null ) ;
186
- // Make the correctly formatted object from the array and then set that object
187
- for ( const association of rawAssociations ) {
188
- if ( association . filenamePattern ) {
189
- newSettingObject [ association . filenamePattern ] = association . viewType ;
186
+ this . hostService . hadLastFocus ( ) . then ( hadLastFocus => {
187
+ if ( ! hadLastFocus ) {
188
+ return ;
190
189
}
191
- }
192
- this . configurationService . updateValue ( editorsAssociationsSettingId , newSettingObject ) ;
190
+ const rawAssociations = this . configurationService . getValue < EditorAssociations | { [ fileNamePattern : string ] : string } > ( editorsAssociationsSettingId ) || { } ;
191
+ // If it's not an array, then it's the new format
192
+ if ( ! Array . isArray ( rawAssociations ) ) {
193
+ return ;
194
+ }
195
+ let newSettingObject = Object . create ( null ) ;
196
+ // Make the correctly formatted object from the array and then set that object
197
+ for ( const association of rawAssociations ) {
198
+ if ( association . filenamePattern ) {
199
+ newSettingObject [ association . filenamePattern ] = association . viewType ;
200
+ }
201
+ }
202
+ this . logService . info ( `Migrating ${ editorsAssociationsSettingId } ` ) ;
203
+ this . configurationService . updateValue ( editorsAssociationsSettingId , newSettingObject ) ;
204
+ } ) ;
193
205
}
194
206
195
207
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
+
197
222
let associations = [ ] ;
198
223
for ( const [ key , value ] of Object . entries ( rawAssociations ) ) {
199
224
const association : EditorAssociation = {
0 commit comments