/**
 * Recursively sets a value in a nested object using a key path array.
 * This is a direct copy of the private function from settingsUtils to avoid import issues.
 */
function setNestedValue(obj, path, value) {
    const [first, ...rest] = path;
    if (!first) {
        return obj;
    }
    if (rest.length === 0) {
        obj[first] = value;
        return obj;
    }
    if (!obj[first] || typeof obj[first] !== 'object') {
        obj[first] = {};
    }
    setNestedValue(obj[first], rest, value);
    return obj;
}
/**
 * Saves a single setting to the appropriate scope
 * This utility correctly handles nested settings by updating only the specific key
 * within the existing object structure.
 */
export function saveSingleSetting(settingKey, value, loadedSettings, scope) {
    const pathParts = settingKey.split('.');
    if (pathParts.length === 1) {
        // It's a top-level setting, the original logic is fine.
        const topLevelKey = pathParts[0];
        loadedSettings.setValue(scope, topLevelKey, value);
        return;
    }
    // It's a nested setting like 'fileFiltering.respectGitIgnore'
    // We need to get the current full object for the parent key, update the nested value within it,
    // and then save the entire parent object back.
    const parentKey = pathParts[0];
    const currentParentObject = loadedSettings.forScope(scope).settings[parentKey];
    // Create a deep copy of the parent object to modify
    const newParentObject = JSON.parse(JSON.stringify(currentParentObject || {}));
    // Use the copied setNestedValue helper to update the specific nested key
    setNestedValue(newParentObject, pathParts.slice(1), value);
    // Save the updated parent object back to the settings file
    loadedSettings.setValue(scope, parentKey, newParentObject);
}
//# sourceMappingURL=singleSettingSaver.js.map