Skip to content

Commit 5750468

Browse files
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 <[email protected]>
1 parent 9ed5084 commit 5750468

File tree

1 file changed

+21
-4
lines changed
  • registry/coder/modules/vscode-web

1 file changed

+21
-4
lines changed

registry/coder/modules/vscode-web/run.sh

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,27 @@ run_vscode_web() {
2828
"$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 &
2929
}
3030

31-
# Check if the settings file exists...
32-
if [ ! -f ~/.vscode-server/data/Machine/settings.json ]; then
33-
echo "⚙️ Creating settings file..."
34-
mkdir -p ~/.vscode-server/data/Machine
31+
# Merge settings with any existing settings file
32+
echo "⚙️ Configuring VS Code settings..."
33+
mkdir -p ~/.vscode-server/data/Machine
34+
35+
SETTINGS_FILE="~/.vscode-server/data/Machine/settings.json"
36+
if [ -f ~/.vscode-server/data/Machine/settings.json ]; then
37+
# Merge with existing settings using jq if available
38+
if command -v jq > /dev/null 2>&1; then
39+
echo "📝 Merging with existing settings..."
40+
# Create a temporary file with the new settings
41+
echo "${SETTINGS}" > /tmp/new_settings.json
42+
# Merge existing settings with new settings (new settings take precedence)
43+
jq -s '.[0] * .[1]' ~/.vscode-server/data/Machine/settings.json /tmp/new_settings.json > /tmp/merged_settings.json
44+
mv /tmp/merged_settings.json ~/.vscode-server/data/Machine/settings.json
45+
rm -f /tmp/new_settings.json
46+
else
47+
echo "⚠️ jq not available, overwriting existing settings..."
48+
echo "${SETTINGS}" > ~/.vscode-server/data/Machine/settings.json
49+
fi
50+
else
51+
echo "📝 Creating new settings file..."
3552
echo "${SETTINGS}" > ~/.vscode-server/data/Machine/settings.json
3653
fi
3754

0 commit comments

Comments
 (0)