@@ -12,8 +12,10 @@ import { workbenchConfigurationNodeBase } from 'vs/workbench/common/configuratio
12
12
import { IEditorResolverService , RegisteredEditorInfo , RegisteredEditorPriority } from 'vs/workbench/services/editor/common/editorResolverService' ;
13
13
import { IJSONSchemaMap } from 'vs/base/common/jsonSchema' ;
14
14
import { IExtensionService } from 'vs/workbench/services/extensions/common/extensions' ;
15
+ import { coalesce } from 'vs/base/common/arrays' ;
16
+ import { Event } from 'vs/base/common/event' ;
15
17
16
- export class DynamicEditorResolverConfigurations extends Disposable implements IWorkbenchContribution {
18
+ export class DynamicEditorConfigurations extends Disposable implements IWorkbenchContribution {
17
19
18
20
private static readonly AUTO_LOCK_DEFAULT_ENABLED = new Set < string > ( [ 'terminalEditor' ] ) ;
19
21
@@ -29,10 +31,11 @@ export class DynamicEditorResolverConfigurations extends Disposable implements I
29
31
}
30
32
] ;
31
33
32
- private configurationRegistry = Registry . as < IConfigurationRegistry > ( ConfigurationExtensions . Configuration ) ;
34
+ private readonly configurationRegistry = Registry . as < IConfigurationRegistry > ( ConfigurationExtensions . Configuration ) ;
35
+
33
36
private autoLockConfigurationNode : IConfigurationNode | undefined ;
34
37
private defaultBinaryEditorConfigurationNode : IConfigurationNode | undefined ;
35
- private editorAssociationsConfiguratioNnode : IConfigurationNode | undefined ;
38
+ private editorAssociationsConfigurationNode : IConfigurationNode | undefined ;
36
39
37
40
constructor (
38
41
@IEditorResolverService private readonly editorResolverService : IEditorResolverService ,
@@ -42,40 +45,40 @@ export class DynamicEditorResolverConfigurations extends Disposable implements I
42
45
43
46
// Editor configurations are getting updated very aggressively
44
47
// (atleast 20 times) while the extensions are getting registered.
45
- // As such push out the dynamic editor auto lock configuration
46
- // until after extensions registered.
48
+ // As such push out the dynamic configuration until after extensions
49
+ // are registered.
47
50
( async ( ) => {
48
51
await extensionService . whenInstalledExtensionsRegistered ( ) ;
49
52
50
- this . updateConfiguration ( ) ;
53
+ this . updateDynamicEditorConfigurations ( ) ;
51
54
this . registerListeners ( ) ;
52
55
} ) ( ) ;
53
56
}
54
57
55
58
private registerListeners ( ) : void {
56
59
57
- // Registered editors
58
- this . _register ( this . editorResolverService . onDidChangeEditorRegistrations ( ( ) => this . updateConfiguration ( ) ) ) ;
60
+ // Registered editors (debounced to reduce perf overhead)
61
+ Event . debounce ( this . editorResolverService . onDidChangeEditorRegistrations , ( _ , e ) => e ) ( ( ) => this . updateDynamicEditorConfigurations ( ) ) ;
59
62
}
60
63
61
- private updateConfiguration ( ) : void {
62
- const lockableEditors = [ ...this . editorResolverService . getEditors ( ) , ...DynamicEditorResolverConfigurations . AUTO_LOCK_EXTRA_EDITORS ] ;
64
+ private updateDynamicEditorConfigurations ( ) : void {
65
+ const lockableEditors = [ ...this . editorResolverService . getEditors ( ) , ...DynamicEditorConfigurations . AUTO_LOCK_EXTRA_EDITORS ] ;
63
66
const binaryEditorCandidates = this . editorResolverService . getEditors ( ) . filter ( e => e . priority !== RegisteredEditorPriority . exclusive ) . map ( e => e . id ) ;
64
67
65
68
// Build config from registered editors
66
69
const autoLockGroupConfiguration : IJSONSchemaMap = Object . create ( null ) ;
67
70
for ( const editor of lockableEditors ) {
68
71
autoLockGroupConfiguration [ editor . id ] = {
69
72
type : 'boolean' ,
70
- default : DynamicEditorResolverConfigurations . AUTO_LOCK_DEFAULT_ENABLED . has ( editor . id ) ,
73
+ default : DynamicEditorConfigurations . AUTO_LOCK_DEFAULT_ENABLED . has ( editor . id ) ,
71
74
description : editor . label
72
75
} ;
73
76
}
74
77
75
78
// Build default config too
76
79
const defaultAutoLockGroupConfiguration = Object . create ( null ) ;
77
80
for ( const editor of lockableEditors ) {
78
- defaultAutoLockGroupConfiguration [ editor . id ] = DynamicEditorResolverConfigurations . AUTO_LOCK_DEFAULT_ENABLED . has ( editor . id ) ;
81
+ defaultAutoLockGroupConfiguration [ editor . id ] = DynamicEditorConfigurations . AUTO_LOCK_DEFAULT_ENABLED . has ( editor . id ) ;
79
82
}
80
83
81
84
// Register settng for auto locking groups
@@ -109,8 +112,8 @@ export class DynamicEditorResolverConfigurations extends Disposable implements I
109
112
} ;
110
113
111
114
// Registers setting for editorAssociations
112
- const oldEditorAssociationsConfigurationNode = this . editorAssociationsConfiguratioNnode ;
113
- this . editorAssociationsConfiguratioNnode = {
115
+ const oldEditorAssociationsConfigurationNode = this . editorAssociationsConfigurationNode ;
116
+ this . editorAssociationsConfigurationNode = {
114
117
...workbenchConfigurationNodeBase ,
115
118
properties : {
116
119
'workbench.editorAssociations' : {
@@ -126,8 +129,17 @@ export class DynamicEditorResolverConfigurations extends Disposable implements I
126
129
}
127
130
} ;
128
131
129
- this . configurationRegistry . updateConfigurations ( { add : [ this . autoLockConfigurationNode ] , remove : oldAutoLockConfigurationNode ? [ oldAutoLockConfigurationNode ] : [ ] } ) ;
130
- this . configurationRegistry . updateConfigurations ( { add : [ this . defaultBinaryEditorConfigurationNode ] , remove : oldDefaultBinaryEditorConfigurationNode ? [ oldDefaultBinaryEditorConfigurationNode ] : [ ] } ) ;
131
- this . configurationRegistry . updateConfigurations ( { add : [ this . editorAssociationsConfiguratioNnode ] , remove : oldEditorAssociationsConfigurationNode ? [ oldEditorAssociationsConfigurationNode ] : [ ] } ) ;
132
+ this . configurationRegistry . updateConfigurations ( {
133
+ add : [
134
+ this . autoLockConfigurationNode ,
135
+ this . defaultBinaryEditorConfigurationNode ,
136
+ this . editorAssociationsConfigurationNode
137
+ ] ,
138
+ remove : coalesce ( [
139
+ oldAutoLockConfigurationNode ,
140
+ oldDefaultBinaryEditorConfigurationNode ,
141
+ oldEditorAssociationsConfigurationNode
142
+ ] )
143
+ } ) ;
132
144
}
133
145
}
0 commit comments