From f912e485bec9753de55f4567558ec52c30483726 Mon Sep 17 00:00:00 2001 From: Atif Ali Date: Wed, 3 Dec 2025 11:58:56 +0000 Subject: [PATCH] fix(vscode-web): always apply settings.json configuration Previously, settings from the module were only applied if the settings.json file didn't exist. This meant that if a user had ever started vscode-web before (even with default settings), their new settings configuration would be ignored. This fix: - Always applies the module settings on startup - Uses jq to merge with existing settings when available - New module settings take precedence over existing settings - Falls back to overwriting settings if jq is not available Fixes #42 --- registry/coder/modules/vscode-web/run.sh | 28 +++++++++++++++++++----- 1 file changed, 23 insertions(+), 5 deletions(-) diff --git a/registry/coder/modules/vscode-web/run.sh b/registry/coder/modules/vscode-web/run.sh index 57bb760f9..097cf77bb 100644 --- a/registry/coder/modules/vscode-web/run.sh +++ b/registry/coder/modules/vscode-web/run.sh @@ -28,11 +28,29 @@ 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 - echo "${SETTINGS}" > ~/.vscode-server/data/Machine/settings.json +# Apply settings +SETTINGS_FILE="$HOME/.vscode-server/data/Machine/settings.json" +mkdir -p "$(dirname "$SETTINGS_FILE")" +MODULE_SETTINGS='${SETTINGS}' + +# Check if we have settings to apply +if [ -n "$MODULE_SETTINGS" ] && [ "$MODULE_SETTINGS" != "{}" ]; then + # Check if jq is available for merging settings + if command -v jq > /dev/null; then + if [ -f "$SETTINGS_FILE" ]; then + echo "⚙️ Merging settings..." + # Merge existing settings with new settings (new settings take precedence) + MERGED_SETTINGS=$(jq -s '.[0] * .[1]' "$SETTINGS_FILE" <(echo "$MODULE_SETTINGS") 2> /dev/null) || MERGED_SETTINGS="$MODULE_SETTINGS" + echo "$MERGED_SETTINGS" > "$SETTINGS_FILE" + else + echo "⚙️ Creating settings file..." + echo "$MODULE_SETTINGS" > "$SETTINGS_FILE" + fi + else + # No jq available, overwrite settings + echo "⚙️ Creating settings file..." + echo "$MODULE_SETTINGS" > "$SETTINGS_FILE" + fi fi # Check if vscode-server is already installed for offline or cached mode