@@ -69,7 +69,7 @@ class InMemoryConfiguration implements WorkspaceConfiguration {
6969class DefaultConfiguration implements WorkspaceConfiguration {
7070 private readonly values : Record < string , unknown > = { } ;
7171
72- public constructor ( configurations : Record < string , { default : unknown } > ) {
72+ public constructor ( configurations : PackageConfiguration ) {
7373 for ( const [ section , config ] of Object . entries ( configurations ) ) {
7474 setIn ( this . values , section , config . default ) ;
7575 }
@@ -138,29 +138,44 @@ class ChainedInMemoryConfiguration {
138138 }
139139}
140140
141+ type PackageConfiguration = Record <
142+ string ,
143+ {
144+ default : unknown ;
145+ }
146+ > ;
147+
141148// Public configuration keys are the ones defined in the package.json.
142149// These keys are documented in the settings page. Other keys are
143150// internal and not documented.
144- const packageConfiguration : Record <
145- string ,
146- {
147- default : any | undefined ;
148- }
149- > = ( function initConfigurationKeys ( ) {
150- // Note we are using synchronous file reads here. This is fine because
151- // we are in tests.
152- const pkg = JSON . parse (
153- readFileSync ( join ( __dirname , "../../package.json" ) , "utf-8" ) ,
154- ) ;
155- return {
156- ...pkg . contributes . configuration . properties ,
157- // `debug.saveBeforeStart` is a core VS Code setting, but we depend on its value in these tests.
158- // We'll set it here to the value that we expect.
159- "debug.saveBeforeStart" : {
160- default : "nonUntitledEditorsInActiveGroup" ,
161- } ,
162- } ;
163- } ) ( ) ;
151+ const packageConfiguration : PackageConfiguration =
152+ ( function initConfigurationKeys ( ) {
153+ // Note we are using synchronous file reads here. This is fine because
154+ // we are in tests.
155+ const pkg = JSON . parse (
156+ readFileSync ( join ( __dirname , "../../package.json" ) , "utf-8" ) ,
157+ ) ;
158+
159+ const properties : PackageConfiguration = {
160+ // `debug.saveBeforeStart` is a core VS Code setting, but we depend on its value in these tests.
161+ // We'll set it here to the value that we expect.
162+ "debug.saveBeforeStart" : {
163+ default : "nonUntitledEditorsInActiveGroup" ,
164+ } ,
165+ } ;
166+ if ( ! Array . isArray ( pkg . contributes . configuration ) ) {
167+ throw new Error ( "Expected package.json configuration to be an array" ) ;
168+ }
169+ for ( const configuration of pkg . contributes . configuration ) {
170+ if ( configuration . properties ) {
171+ for ( const [ key , value ] of Object . entries ( configuration . properties ) ) {
172+ properties [ key ] = value as any ;
173+ }
174+ }
175+ }
176+
177+ return properties ;
178+ } ) ( ) ;
164179
165180export let vscodeGetConfigurationMock : jest . SpiedFunction <
166181 typeof workspace . getConfiguration
0 commit comments