From 5750468a5763e750aa65fda701a888b0deaba2e0 Mon Sep 17 00:00:00 2001 From: "blink-so[bot]" <211532188+blink-so[bot]@users.noreply.github.com> Date: Wed, 23 Jul 2025 03:46:12 +0000 Subject: [PATCH] fix: improve VSCode-web settings merge with existing configurations Enhance the settings handling in the VSCode-web module to properly merge user-defined settings with any existing settings file using jq when available. This ensures that settings from both the Terraform module and Coder's git authentication system are preserved. Related to coder/coder#19007 Co-authored-by: matifali <10648092+matifali@users.noreply.github.com> --- registry/coder/modules/vscode-web/run.sh | 25 ++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/registry/coder/modules/vscode-web/run.sh b/registry/coder/modules/vscode-web/run.sh index 9346b4bdb..3e8999416 100644 --- a/registry/coder/modules/vscode-web/run.sh +++ b/registry/coder/modules/vscode-web/run.sh @@ -28,10 +28,27 @@ run_vscode_web() { "$VSCODE_WEB" serve-local "$EXTENSION_ARG" "$SERVER_BASE_PATH_ARG" "$DISABLE_TRUST_ARG" --port "${PORT}" --host 127.0.0.1 --accept-server-license-terms --without-connection-token --telemetry-level "${TELEMETRY_LEVEL}" > "${LOG_PATH}" 2>&1 & } -# Check if the settings file exists... -if [ ! -f ~/.vscode-server/data/Machine/settings.json ]; then - echo "⚙️ Creating settings file..." - mkdir -p ~/.vscode-server/data/Machine +# Merge settings with any existing settings file +echo "⚙️ Configuring VS Code settings..." +mkdir -p ~/.vscode-server/data/Machine + +SETTINGS_FILE="~/.vscode-server/data/Machine/settings.json" +if [ -f ~/.vscode-server/data/Machine/settings.json ]; then + # Merge with existing settings using jq if available + if command -v jq > /dev/null 2>&1; then + echo "📝 Merging with existing settings..." + # Create a temporary file with the new settings + echo "${SETTINGS}" > /tmp/new_settings.json + # Merge existing settings with new settings (new settings take precedence) + jq -s '.[0] * .[1]' ~/.vscode-server/data/Machine/settings.json /tmp/new_settings.json > /tmp/merged_settings.json + mv /tmp/merged_settings.json ~/.vscode-server/data/Machine/settings.json + rm -f /tmp/new_settings.json + else + echo "⚠️ jq not available, overwriting existing settings..." + echo "${SETTINGS}" > ~/.vscode-server/data/Machine/settings.json + fi +else + echo "📝 Creating new settings file..." echo "${SETTINGS}" > ~/.vscode-server/data/Machine/settings.json fi