@@ -60,10 +60,11 @@ type ToConfigRefs<C extends object> = {
60
60
*
61
61
* @category lifecycle
62
62
*/
63
- export function defineConfigs < const C extends ConfigTypeOptions > ( section : string , configs : C , scope ?: Nullable < ConfigurationScope > ) : ToConfigRefs < ParseConfigTypeOptions < C > >
64
- export function defineConfigs < C extends object > ( section : string , configs : C , scope ?: Nullable < ConfigurationScope > ) : ToConfigRefs < C >
65
- export function defineConfigs ( section : string , configs : object , scope ?: Nullable < ConfigurationScope > ) {
66
- const workspaceConfig = workspace . getConfiguration ( section , scope )
63
+ export function defineConfigs < const C extends ConfigTypeOptions > ( section : Nullable < string > , configs : C , scope ?: Nullable < ConfigurationScope > ) : ToConfigRefs < ParseConfigTypeOptions < C > >
64
+ export function defineConfigs < C extends object > ( section : Nullable < string > , configs : C , scope ?: Nullable < ConfigurationScope > ) : ToConfigRefs < C >
65
+ export function defineConfigs ( section : Nullable < string > , configs : object , scope ?: Nullable < ConfigurationScope > ) {
66
+ const isTopLevel = ! section
67
+ const workspaceConfig = workspace . getConfiguration ( isTopLevel ? undefined : section , scope )
67
68
68
69
function createConfigRef < T > ( key : string , value : T ) : ConfigRef < T > {
69
70
const data = shallowRef ( value )
@@ -91,15 +92,25 @@ export function defineConfigs(section: string, configs: object, scope?: Nullable
91
92
)
92
93
93
94
onActivate ( ( ) => {
94
- useDisposable ( workspace . onDidChangeConfiguration ( ( e ) => {
95
- if ( ! e . affectsConfiguration ( section ) )
96
- return
97
- const newWorkspaceConfig = workspace . getConfiguration ( section )
98
- for ( const key in configs ) {
99
- if ( e . affectsConfiguration ( `${ section } .${ key } ` ) )
100
- configRefs [ key ] . set ( newWorkspaceConfig . get ( key ) as any )
101
- }
102
- } ) )
95
+ useDisposable ( workspace . onDidChangeConfiguration (
96
+ isTopLevel
97
+ ? ( e ) => {
98
+ const newWorkspaceConfig = workspace . getConfiguration ( )
99
+ for ( const key in configs ) {
100
+ if ( e . affectsConfiguration ( key ) )
101
+ configRefs [ key ] . set ( newWorkspaceConfig . get ( key ) as any )
102
+ }
103
+ }
104
+ : ( e ) => {
105
+ if ( ! e . affectsConfiguration ( section ) )
106
+ return
107
+ const newWorkspaceConfig = workspace . getConfiguration ( section )
108
+ for ( const key in configs ) {
109
+ if ( e . affectsConfiguration ( `${ section } .${ key } ` ) )
110
+ configRefs [ key ] . set ( newWorkspaceConfig . get ( key ) as any )
111
+ }
112
+ } ,
113
+ ) )
103
114
} )
104
115
105
116
return configRefs
0 commit comments