( modifiedSettings: Set<string>, pendingSettings: Settings, loadedSettings: LoadedSettings, scope: SettingScope, )
| 355 | * Save modified settings to the appropriate scope |
| 356 | */ |
| 357 | export function saveModifiedSettings( |
| 358 | modifiedSettings: Set<string>, |
| 359 | pendingSettings: Settings, |
| 360 | loadedSettings: LoadedSettings, |
| 361 | scope: SettingScope, |
| 362 | ): void { |
| 363 | modifiedSettings.forEach((settingKey) => { |
| 364 | const path = settingKey.split('.'); |
| 365 | const value = getNestedValue( |
| 366 | pendingSettings as Record<string, unknown>, |
| 367 | path, |
| 368 | ); |
| 369 | |
| 370 | if (value === undefined) { |
| 371 | return; |
| 372 | } |
| 373 | |
| 374 | const existsInOriginalFile = settingExistsInScope( |
| 375 | settingKey, |
| 376 | loadedSettings.forScope(scope).settings, |
| 377 | ); |
| 378 | |
| 379 | const isDefaultValue = value === getDefaultValue(settingKey); |
| 380 | |
| 381 | if (existsInOriginalFile || !isDefaultValue) { |
| 382 | // This is tricky because setValue only works on top-level keys. |
| 383 | // We need to set the whole parent object. |
| 384 | const [parentKey] = path; |
| 385 | if (parentKey) { |
| 386 | // Ensure value is a boolean for setPendingSettingValue |
| 387 | const booleanValue = typeof value === 'boolean' ? value : false; |
| 388 | const newParentValue = setPendingSettingValue( |
| 389 | settingKey, |
| 390 | booleanValue, |
| 391 | loadedSettings.forScope(scope).settings, |
| 392 | )[parentKey as keyof Settings]; |
| 393 | |
| 394 | loadedSettings.setValue( |
| 395 | scope, |
| 396 | parentKey as keyof Settings, |
| 397 | newParentValue, |
| 398 | ); |
| 399 | } |
| 400 | } |
| 401 | }); |
| 402 | } |
| 403 | |
| 404 | /** |
| 405 | * Get the display value for a setting, showing current scope value with default change indicator |
no test coverage detected