From 69889eeb3810421f554038d06416dad7a617aa94 Mon Sep 17 00:00:00 2001 From: Miguel Solorio Date: Tue, 3 Sep 2024 23:27:33 -0700 Subject: [PATCH] Extension keeps creating the symbols.hidesExplorerArrows key in settings (Fixes #232) --- src/lib/change-listener.js | 16 ++++++++++++++-- src/lib/config.js | 26 ++++++++++++++++++++------ 2 files changed, 34 insertions(+), 8 deletions(-) diff --git a/src/lib/change-listener.js b/src/lib/change-listener.js index 6c1849ab..ba7a0a45 100644 --- a/src/lib/change-listener.js +++ b/src/lib/change-listener.js @@ -7,12 +7,24 @@ function monitorConfigChanges() { const workspaceState = getWorkspaceConfiguration(); const updatedKeys = {}; + let hasChanges = false; for (const currentKey in currentState) { - updatedKeys[currentKey] = workspaceState[currentKey]; + if (currentKey in workspaceState) { + if (JSON.stringify(workspaceState[currentKey]) !== JSON.stringify(currentState[currentKey])) { + updatedKeys[currentKey] = workspaceState[currentKey]; + hasChanges = true; + } + } else if (currentState[currentKey] !== undefined) { + // The setting was removed, so we need to update it to undefined + updatedKeys[currentKey] = undefined; + hasChanges = true; + } } - updateConfig(updatedKeys); + if (hasChanges) { + updateConfig(updatedKeys); + } } module.exports = { diff --git a/src/lib/config.js b/src/lib/config.js index 5a02e4ba..00f0dafd 100644 --- a/src/lib/config.js +++ b/src/lib/config.js @@ -25,7 +25,12 @@ function getWorkspaceConfiguration() { const valueGroup = vscode.workspace.getConfiguration("symbols").inspect(PKG_PROP_MAP[key]); - config[PKG_PROP_MAP[key]] = valueGroup.workspaceValue || valueGroup.globalValue || defaultState[PKG_PROP_MAP[key]]; + if (valueGroup.workspaceValue !== undefined) { + config[PKG_PROP_MAP[key]] = valueGroup.workspaceValue; + } else if (valueGroup.globalValue !== undefined) { + config[PKG_PROP_MAP[key]] = valueGroup.globalValue; + } + // We no longer fall back to defaultState } return config; @@ -56,11 +61,20 @@ function updateConfig(config) { const themeJSON = getSoureFile(); for (const key in config) { - log.info(`symbols.${key} changed, updating to ${config[key]}`); - const updateHandler = updateThemeJSONHandlers[key]; - if (updateHandler) { - vscode.workspace.getConfiguration("symbols").update(key, config[key], true); - updateHandler(themeJSON, config[key]); + if (config[key] === undefined) { + log.info(`symbols.${key} removed, updating theme`); + vscode.workspace.getConfiguration("symbols").update(key, undefined, true); + // Remove the key from themeJSON if it exists + if (key in themeJSON) { + delete themeJSON[key]; + } + } else { + log.info(`symbols.${key} changed, updating to ${config[key]}`); + const updateHandler = updateThemeJSONHandlers[key]; + if (updateHandler) { + vscode.workspace.getConfiguration("symbols").update(key, config[key], true); + updateHandler(themeJSON, config[key]); + } } }