fix(vscode-web): apply settings on every workspace start

Previously, settings were only written to settings.json if the file
did not already exist. This meant that template changes to the settings
variable would never be applied to existing workspaces.

Now, Machine settings are always applied on every workspace start,
which is the expected behavior for template-controlled settings.

Fixes: https://github.com/coder/registry/issues/42
This commit is contained in:
Danny Kopping 2025-12-03 11:31:03 +02:00
parent 69e5dc5c80
commit 9aefe61d48
2 changed files with 7 additions and 7 deletions

View File

@ -53,7 +53,7 @@ module "vscode-web" {
### Pre-configure Settings
Configure VS Code's [settings.json](https://code.visualstudio.com/docs/getstarted/settings#_settings-json-file) file:
Configure VS Code's [Machine settings.json](https://code.visualstudio.com/docs/getstarted/settings#_settings-json-file) file. These settings are applied on every workspace start, ensuring template-defined settings are always enforced:
```tf
module "vscode-web" {

View File

@ -28,12 +28,12 @@ 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
fi
# Apply/overwrite template-based settings on every start
# Machine settings are always overwritten to apply template changes.
# See: https://github.com/coder/registry/issues/42
echo "⚙️ Applying VS Code settings..."
mkdir -p ~/.vscode-server/data/Machine
echo "${SETTINGS}" > ~/.vscode-server/data/Machine/settings.json
# Check if vscode-server is already installed for offline or cached mode
if [ -f "$VSCODE_WEB" ]; then