@@ -9,7 +9,7 @@ import { IJSONSchema } from 'vs/base/common/jsonSchema';
99import { Registry } from 'vs/platform/registry/common/platform' ;
1010import * as types from 'vs/base/common/types' ;
1111import { IJSONContributionRegistry , Extensions as JSONExtensions } from 'vs/platform/jsonschemas/common/jsonContributionRegistry' ;
12- import { ExtensionIdentifier } from 'vs/platform/extensions/ common/extensions ' ;
12+ import { IStringDictionary } from 'vs/base/ common/collections ' ;
1313
1414export const Extensions = {
1515 Configuration : 'base.contributions.configuration'
@@ -35,12 +35,12 @@ export interface IConfigurationRegistry {
3535 /**
3636 * Register multiple default configurations to the registry.
3737 */
38- registerDefaultConfigurations ( defaultConfigurations : IDefaultConfigurationExtension [ ] ) : void ;
38+ registerDefaultConfigurations ( defaultConfigurations : IStringDictionary < any > [ ] ) : void ;
3939
4040 /**
4141 * Deregister multiple default configurations from the registry.
4242 */
43- deregisterDefaultConfigurations ( defaultConfigurations : IDefaultConfigurationExtension [ ] ) : void ;
43+ deregisterDefaultConfigurations ( defaultConfigurations : IStringDictionary < any > [ ] ) : void ;
4444
4545 /**
4646 * Signal that the schema of a configuration setting has changes. It is currently only supported to change enumeration values.
@@ -131,12 +131,6 @@ export interface IConfigurationNode {
131131 extensionInfo ?: IConfigurationExtensionInfo ;
132132}
133133
134- export interface IDefaultConfigurationExtension {
135- id : ExtensionIdentifier ;
136- name : string ;
137- defaults : { [ key : string ] : { } } ;
138- }
139-
140134type SettingProperties = { [ key : string ] : any } ;
141135
142136export const allSettings : { properties : SettingProperties , patternProperties : SettingProperties } = { properties : { } , patternProperties : { } } ;
@@ -152,7 +146,8 @@ const contributionRegistry = Registry.as<IJSONContributionRegistry>(JSONExtensio
152146
153147class ConfigurationRegistry implements IConfigurationRegistry {
154148
155- private readonly defaultOverridesConfigurationNode : IConfigurationNode ;
149+ private readonly defaultValues : IStringDictionary < any > ;
150+ private readonly defaultLanguageConfigurationOverridesNode : IConfigurationNode ;
156151 private readonly configurationContributors : IConfigurationNode [ ] ;
157152 private readonly configurationProperties : { [ qualifiedKey : string ] : IJSONSchema } ;
158153 private readonly excludedConfigurationProperties : { [ qualifiedKey : string ] : IJSONSchema } ;
@@ -166,12 +161,13 @@ class ConfigurationRegistry implements IConfigurationRegistry {
166161 readonly onDidUpdateConfiguration : Event < string [ ] > = this . _onDidUpdateConfiguration . event ;
167162
168163 constructor ( ) {
169- this . defaultOverridesConfigurationNode = {
164+ this . defaultValues = { } ;
165+ this . defaultLanguageConfigurationOverridesNode = {
170166 id : 'defaultOverrides' ,
171- title : nls . localize ( 'defaultConfigurations .title' , "Default Configuration Overrides" ) ,
167+ title : nls . localize ( 'defaultLanguageConfigurationOverrides .title' , "Default Language Configuration Overrides" ) ,
172168 properties : { }
173169 } ;
174- this . configurationContributors = [ this . defaultOverridesConfigurationNode ] ;
170+ this . configurationContributors = [ this . defaultLanguageConfigurationOverridesNode ] ;
175171 this . resourceLanguageSettingsSchema = { properties : { } , patternProperties : { } , additionalProperties : false , errorMessage : 'Unknown editor configuration setting' , allowTrailingCommas : true , allowComments : true } ;
176172 this . configurationProperties = { } ;
177173 this . excludedConfigurationProperties = { } ;
@@ -202,29 +198,8 @@ class ConfigurationRegistry implements IConfigurationRegistry {
202198 if ( configuration . properties ) {
203199 for ( const key in configuration . properties ) {
204200 properties . push ( key ) ;
205-
206201 delete this . configurationProperties [ key ] ;
207-
208- // Delete from schema
209- delete allSettings . properties [ key ] ;
210- switch ( configuration . properties [ key ] . scope ) {
211- case ConfigurationScope . APPLICATION :
212- delete applicationSettings . properties [ key ] ;
213- break ;
214- case ConfigurationScope . MACHINE :
215- delete machineSettings . properties [ key ] ;
216- break ;
217- case ConfigurationScope . MACHINE_OVERRIDABLE :
218- delete machineOverridableSettings . properties [ key ] ;
219- break ;
220- case ConfigurationScope . WINDOW :
221- delete windowSettings . properties [ key ] ;
222- break ;
223- case ConfigurationScope . RESOURCE :
224- case ConfigurationScope . LANGUAGE_OVERRIDABLE :
225- delete resourceSettings . properties [ key ] ;
226- break ;
227- }
202+ this . removeFromSchema ( key , configuration . properties [ key ] ) ;
228203 }
229204 }
230205 if ( configuration . allOf ) {
@@ -244,41 +219,60 @@ class ConfigurationRegistry implements IConfigurationRegistry {
244219 this . _onDidUpdateConfiguration . fire ( properties ) ;
245220 }
246221
247- public registerDefaultConfigurations ( defaultConfigurations : IDefaultConfigurationExtension [ ] ) : void {
222+ public registerDefaultConfigurations ( defaultConfigurations : IStringDictionary < any > [ ] ) : void {
248223 const properties : string [ ] = [ ] ;
224+ const overrideIdentifiers : string [ ] = [ ] ;
249225
250226 for ( const defaultConfiguration of defaultConfigurations ) {
251- for ( const key in defaultConfiguration . defaults ) {
252- const defaultValue = defaultConfiguration . defaults [ key ] ;
253- if ( OVERRIDE_PROPERTY_PATTERN . test ( key ) && typeof defaultValue === 'object' ) {
254- const propertySchema : IConfigurationPropertySchema = {
227+ for ( const key in defaultConfiguration ) {
228+ properties . push ( key ) ;
229+ this . defaultValues [ key ] = defaultConfiguration [ key ] ;
230+
231+ if ( OVERRIDE_PROPERTY_PATTERN . test ( key ) ) {
232+ const property : IConfigurationPropertySchema = {
255233 type : 'object' ,
256- default : defaultValue ,
257- description : nls . localize ( 'overrideSettings .description' , "Configure editor settings to be overridden for {0} language." , key ) ,
234+ default : this . defaultValues [ key ] ,
235+ description : nls . localize ( 'defaultLanguageConfiguration .description' , "Configure settings to be overridden for {0} language." , key ) ,
258236 $ref : resourceLanguageSettingsSchemaId
259237 } ;
260- allSettings . properties [ key ] = propertySchema ;
261- this . defaultOverridesConfigurationNode . properties ! [ key ] = propertySchema ;
262- this . configurationProperties [ key ] = propertySchema ;
263- properties . push ( key ) ;
238+ overrideIdentifiers . push ( overrideIdentifierFromKey ( key ) ) ;
239+ this . configurationProperties [ key ] = property ;
240+ this . defaultLanguageConfigurationOverridesNode . properties ! [ key ] = property ;
241+ } else {
242+ const property = this . configurationProperties [ key ] ;
243+ if ( property ) {
244+ this . updatePropertyDefaultValue ( key , property ) ;
245+ this . updateSchema ( key , property ) ;
246+ }
264247 }
265248 }
266249 }
267250
251+ this . registerOverrideIdentifiers ( overrideIdentifiers ) ;
268252 this . _onDidSchemaChange . fire ( ) ;
269253 this . _onDidUpdateConfiguration . fire ( properties ) ;
270254 }
271255
272- public deregisterDefaultConfigurations ( defaultConfigurations : IDefaultConfigurationExtension [ ] ) : void {
256+ public deregisterDefaultConfigurations ( defaultConfigurations : IStringDictionary < any > [ ] ) : void {
273257 const properties : string [ ] = [ ] ;
274258 for ( const defaultConfiguration of defaultConfigurations ) {
275- for ( const key in defaultConfiguration . defaults ) {
259+ for ( const key in defaultConfiguration ) {
276260 properties . push ( key ) ;
277- delete allSettings . properties [ key ] ;
278- delete this . defaultOverridesConfigurationNode . properties ! [ key ] ;
279- delete this . configurationProperties [ key ] ;
261+ delete this . defaultValues [ key ] ;
262+ if ( OVERRIDE_PROPERTY_PATTERN . test ( key ) ) {
263+ delete this . configurationProperties [ key ] ;
264+ delete this . defaultLanguageConfigurationOverridesNode . properties ! [ key ] ;
265+ } else {
266+ const property = this . configurationProperties [ key ] ;
267+ if ( property ) {
268+ this . updatePropertyDefaultValue ( key , property ) ;
269+ this . updateSchema ( key , property ) ;
270+ }
271+ }
280272 }
281273 }
274+
275+ this . updateOverridePropertyPatternKey ( ) ;
282276 this . _onDidSchemaChange . fire ( ) ;
283277 this . _onDidUpdateConfiguration . fire ( properties ) ;
284278 }
@@ -291,7 +285,6 @@ class ConfigurationRegistry implements IConfigurationRegistry {
291285 for ( const overrideIdentifier of overrideIdentifiers ) {
292286 this . overrideIdentifiers . add ( overrideIdentifier ) ;
293287 }
294-
295288 this . updateOverridePropertyPatternKey ( ) ;
296289 }
297290
@@ -305,12 +298,13 @@ class ConfigurationRegistry implements IConfigurationRegistry {
305298 delete properties [ key ] ;
306299 continue ;
307300 }
308- // fill in default values
309- let property = properties [ key ] ;
310- let defaultValue = property . default ;
311- if ( types . isUndefined ( defaultValue ) ) {
312- property . default = getDefaultValue ( property . type ) ;
313- }
301+
302+ const property = properties [ key ] ;
303+
304+ // update default value
305+ this . updatePropertyDefaultValue ( key , property ) ;
306+
307+ // update scope
314308 if ( OVERRIDE_PROPERTY_PATTERN . test ( key ) ) {
315309 property . scope = undefined ; // No scope for overridable properties `[${identifier}]`
316310 } else {
@@ -361,28 +355,7 @@ class ConfigurationRegistry implements IConfigurationRegistry {
361355 let properties = configuration . properties ;
362356 if ( properties ) {
363357 for ( const key in properties ) {
364- allSettings . properties [ key ] = properties [ key ] ;
365- switch ( properties [ key ] . scope ) {
366- case ConfigurationScope . APPLICATION :
367- applicationSettings . properties [ key ] = properties [ key ] ;
368- break ;
369- case ConfigurationScope . MACHINE :
370- machineSettings . properties [ key ] = properties [ key ] ;
371- break ;
372- case ConfigurationScope . MACHINE_OVERRIDABLE :
373- machineOverridableSettings . properties [ key ] = properties [ key ] ;
374- break ;
375- case ConfigurationScope . WINDOW :
376- windowSettings . properties [ key ] = properties [ key ] ;
377- break ;
378- case ConfigurationScope . RESOURCE :
379- resourceSettings . properties [ key ] = properties [ key ] ;
380- break ;
381- case ConfigurationScope . LANGUAGE_OVERRIDABLE :
382- resourceSettings . properties [ key ] = properties [ key ] ;
383- this . resourceLanguageSettingsSchema . properties ! [ key ] = properties [ key ] ;
384- break ;
385- }
358+ this . updateSchema ( key , properties [ key ] ) ;
386359 }
387360 }
388361 let subNodes = configuration . allOf ;
@@ -393,6 +366,53 @@ class ConfigurationRegistry implements IConfigurationRegistry {
393366 register ( configuration ) ;
394367 }
395368
369+ private updateSchema ( key : string , property : IConfigurationPropertySchema ) : void {
370+ allSettings . properties [ key ] = property ;
371+ switch ( property . scope ) {
372+ case ConfigurationScope . APPLICATION :
373+ applicationSettings . properties [ key ] = property ;
374+ break ;
375+ case ConfigurationScope . MACHINE :
376+ machineSettings . properties [ key ] = property ;
377+ break ;
378+ case ConfigurationScope . MACHINE_OVERRIDABLE :
379+ machineOverridableSettings . properties [ key ] = property ;
380+ break ;
381+ case ConfigurationScope . WINDOW :
382+ windowSettings . properties [ key ] = property ;
383+ break ;
384+ case ConfigurationScope . RESOURCE :
385+ resourceSettings . properties [ key ] = property ;
386+ break ;
387+ case ConfigurationScope . LANGUAGE_OVERRIDABLE :
388+ resourceSettings . properties [ key ] = property ;
389+ this . resourceLanguageSettingsSchema . properties ! [ key ] = property ;
390+ break ;
391+ }
392+ }
393+
394+ private removeFromSchema ( key : string , property : IConfigurationPropertySchema ) : void {
395+ delete allSettings . properties [ key ] ;
396+ switch ( property . scope ) {
397+ case ConfigurationScope . APPLICATION :
398+ delete applicationSettings . properties [ key ] ;
399+ break ;
400+ case ConfigurationScope . MACHINE :
401+ delete machineSettings . properties [ key ] ;
402+ break ;
403+ case ConfigurationScope . MACHINE_OVERRIDABLE :
404+ delete machineOverridableSettings . properties [ key ] ;
405+ break ;
406+ case ConfigurationScope . WINDOW :
407+ delete windowSettings . properties [ key ] ;
408+ break ;
409+ case ConfigurationScope . RESOURCE :
410+ case ConfigurationScope . LANGUAGE_OVERRIDABLE :
411+ delete resourceSettings . properties [ key ] ;
412+ break ;
413+ }
414+ }
415+
396416 private updateOverridePropertyPatternKey ( ) : void {
397417 for ( const overrideIdentifier of this . overrideIdentifiers . values ( ) ) {
398418 const overrideIdentifierProperty = `[${ overrideIdentifier } ]` ;
@@ -401,8 +421,8 @@ class ConfigurationRegistry implements IConfigurationRegistry {
401421 description : nls . localize ( 'overrideSettings.defaultDescription' , "Configure editor settings to be overridden for a language." ) ,
402422 errorMessage : nls . localize ( 'overrideSettings.errorMessage' , "This setting does not support per-language configuration." ) ,
403423 $ref : resourceLanguageSettingsSchemaId ,
404- default : this . defaultOverridesConfigurationNode . properties ! [ overrideIdentifierProperty ] ?. default
405424 } ;
425+ this . updatePropertyDefaultValue ( overrideIdentifierProperty , resourceLanguagePropertiesSchema ) ;
406426 allSettings . properties [ overrideIdentifierProperty ] = resourceLanguagePropertiesSchema ;
407427 applicationSettings . properties [ overrideIdentifierProperty ] = resourceLanguagePropertiesSchema ;
408428 machineSettings . properties [ overrideIdentifierProperty ] = resourceLanguagePropertiesSchema ;
@@ -412,11 +432,26 @@ class ConfigurationRegistry implements IConfigurationRegistry {
412432 }
413433 this . _onDidSchemaChange . fire ( ) ;
414434 }
435+
436+ private updatePropertyDefaultValue ( key : string , property : IConfigurationPropertySchema ) : void {
437+ let defaultValue = this . defaultValues [ key ] ;
438+ if ( types . isUndefined ( defaultValue ) ) {
439+ defaultValue = property . default ;
440+ }
441+ if ( types . isUndefined ( defaultValue ) ) {
442+ defaultValue = getDefaultValue ( property . type ) ;
443+ }
444+ property . default = defaultValue ;
445+ }
415446}
416447
417448const OVERRIDE_PROPERTY = '\\[.*\\]$' ;
418449export const OVERRIDE_PROPERTY_PATTERN = new RegExp ( OVERRIDE_PROPERTY ) ;
419450
451+ export function overrideIdentifierFromKey ( key : string ) : string {
452+ return key . substring ( 1 , key . length - 1 ) ;
453+ }
454+
420455export function getDefaultValue ( type : string | string [ ] | undefined ) : any {
421456 const t = Array . isArray ( type ) ? ( < string [ ] > type ) [ 0 ] : < string > type ;
422457 switch ( t ) {
0 commit comments