MCPcopy Create free account
hub / github.com/anus-dev/ANUS / saveModifiedSettings

Function saveModifiedSettings

packages/cli/src/utils/settingsUtils.ts:357–402  ·  view source on GitHub ↗
(
  modifiedSettings: Set<string>,
  pendingSettings: Settings,
  loadedSettings: LoadedSettings,
  scope: SettingScope,
)

Source from the content-addressed store, hash-verified

355 * Save modified settings to the appropriate scope
356 */
357export 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

Callers 2

generateSettingsItemsFunction · 0.85
SettingsDialogFunction · 0.85

Calls 6

getNestedValueFunction · 0.85
settingExistsInScopeFunction · 0.85
getDefaultValueFunction · 0.85
setPendingSettingValueFunction · 0.85
forScopeMethod · 0.80
setValueMethod · 0.45

Tested by

no test coverage detected