diff options
Diffstat (limited to 'packages/cli/src/utils/settingsUtils.ts')
| -rw-r--r-- | packages/cli/src/utils/settingsUtils.ts | 34 |
1 files changed, 25 insertions, 9 deletions
diff --git a/packages/cli/src/utils/settingsUtils.ts b/packages/cli/src/utils/settingsUtils.ts index f4363400..6b5a55c1 100644 --- a/packages/cli/src/utils/settingsUtils.ts +++ b/packages/cli/src/utils/settingsUtils.ts @@ -91,7 +91,10 @@ export function getRestartRequiredSettings(): string[] { /** * Recursively gets a value from a nested object using a key path array. */ -function getNestedValue(obj: Record<string, unknown>, path: string[]): unknown { +export function getNestedValue( + obj: Record<string, unknown>, + path: string[], +): unknown { const [first, ...rest] = path; if (!first || !(first in obj)) { return undefined; @@ -333,6 +336,20 @@ export function setPendingSettingValue( } /** + * Generic setter: Set a setting value (boolean, number, string, etc.) in the pending settings + */ +export function setPendingSettingValueAny( + key: string, + value: unknown, + pendingSettings: Settings, +): Settings { + const path = key.split('.'); + const newSettings = structuredClone(pendingSettings); + setNestedValue(newSettings, path, value); + return newSettings; +} + +/** * Check if any modified settings require a restart */ export function hasRestartRequiredSettings( @@ -382,11 +399,9 @@ export function saveModifiedSettings( // We need to set the whole parent object. const [parentKey] = path; if (parentKey) { - // Ensure value is a boolean for setPendingSettingValue - const booleanValue = typeof value === 'boolean' ? value : false; - const newParentValue = setPendingSettingValue( + const newParentValue = setPendingSettingValueAny( settingKey, - booleanValue, + value, loadedSettings.forScope(scope).settings, )[parentKey as keyof Settings]; @@ -431,11 +446,12 @@ export function getDisplayValue( const isChangedFromDefault = typeof defaultValue === 'boolean' ? value !== defaultValue : value === true; const isInModifiedSettings = modifiedSettings.has(key); - const hasPendingChanges = - pendingSettings && settingExistsInScope(key, pendingSettings); - // Add * indicator when value differs from default, is in modified settings, or has pending changes - if (isChangedFromDefault || isInModifiedSettings || hasPendingChanges) { + // Mark as modified if setting exists in current scope OR is in modified settings + if (settingExistsInScope(key, settings) || isInModifiedSettings) { + return `${valueString}*`; // * indicates setting is set in current scope + } + if (isChangedFromDefault || isInModifiedSettings) { return `${valueString}*`; // * indicates changed from default value } |
