@@ -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,13 +58,20 @@ 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
63
67
this . cache = new Set < string > ( JSON . parse ( this . storageService . get ( EditorOverrideService . overrideCacheStorageID , StorageScope . GLOBAL , JSON . stringify ( [ ] ) ) ) ) ;
64
68
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
+ } ) ;
66
75
67
76
this . _register ( this . storageService . onWillSaveState ( ( ) => {
68
77
// 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
75
84
} ) ;
76
85
77
86
// 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
+ }
80
91
} ) ) ;
81
92
}
82
93
@@ -177,7 +188,7 @@ export class EditorOverrideService extends Disposable implements IEditorOverride
177
188
}
178
189
179
190
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 ) || { } ;
181
192
// If it's not an array, then it's the new format
182
193
if ( ! Array . isArray ( rawAssociations ) ) {
183
194
return ;
@@ -189,11 +200,25 @@ export class EditorOverrideService extends Disposable implements IEditorOverride
189
200
newSettingObject [ association . filenamePattern ] = association . viewType ;
190
201
}
191
202
}
203
+ this . logService . info ( `Migrating ${ editorsAssociationsSettingId } ` ) ;
192
204
this . configurationService . updateValue ( editorsAssociationsSettingId , newSettingObject ) ;
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