Skip to content
This repository was archived by the owner on May 15, 2025. It is now read-only.

Commit 18810cc

Browse files
feat(vscode-web): add support for settings (#195)
Currently saves to `~/.vscode-server/data/Machine/settings.json` as `~/.vscode-server/data/User/settings.json` will not work because VS Code web stores user settings in the browser.
1 parent 98a428a commit 18810cc

File tree

3 files changed

+34
-2
lines changed

3 files changed

+34
-2
lines changed

vscode-web/README.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,3 +48,20 @@ module "vscode-web" {
4848
accept_license = true
4949
}
5050
```
51+
52+
### Pre-configure Settings
53+
54+
Configure VS Code's [settings.json](https://code.visualstudio.com/docs/getstarted/settings#_settingsjson) file:
55+
56+
```tf
57+
module "vscode-web" {
58+
source = "registry.coder.com/modules/vscode-web/coder"
59+
version = "1.0.8"
60+
agent_id = coder_agent.example.id
61+
extensions = ["dracula-theme.theme-dracula"]
62+
settings = {
63+
"workbench.colorTheme" = "Dracula"
64+
}
65+
accept_license = true
66+
}
67+
```

vscode-web/main.tf

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,12 @@ variable "order" {
9191
default = null
9292
}
9393

94+
variable "settings" {
95+
type = map(string)
96+
description = "A map of settings to apply to VS Code web."
97+
default = {}
98+
}
99+
94100
resource "coder_script" "vscode-web" {
95101
agent_id = var.agent_id
96102
display_name = "VS Code Web"
@@ -101,6 +107,8 @@ resource "coder_script" "vscode-web" {
101107
INSTALL_PREFIX : var.install_prefix,
102108
EXTENSIONS : join(",", var.extensions),
103109
TELEMETRY_LEVEL : var.telemetry_level,
110+
// This is necessary otherwise the quotes are stripped!
111+
SETTINGS : replace(jsonencode(var.settings), "\"", "\\\""),
104112
})
105113
run_on_start = true
106114
}

vscode-web/run.sh

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ case "$ARCH" in
1919
;;
2020
esac
2121

22-
HASH=$(curl https://update.code.visualstudio.com/api/commits/stable/server-linux-$ARCH-web | cut -d '"' -f 2)
23-
output=$(curl -sL https://vscode.download.prss.microsoft.com/dbazure/download/stable/$HASH/vscode-server-linux-$ARCH-web.tar.gz | tar -xz -C ${INSTALL_PREFIX} --strip-components 1)
22+
HASH=$(curl -fsSL https://update.code.visualstudio.com/api/commits/stable/server-linux-$ARCH-web | cut -d '"' -f 2)
23+
output=$(curl -fsSL https://vscode.download.prss.microsoft.com/dbazure/download/stable/$HASH/vscode-server-linux-$ARCH-web.tar.gz | tar -xz -C ${INSTALL_PREFIX} --strip-components 1)
2424

2525
if [ $? -ne 0 ]; then
2626
echo "Failed to install Microsoft Visual Studio Code Server: $output"
@@ -44,6 +44,13 @@ for extension in "$${EXTENSIONLIST[@]}"; do
4444
fi
4545
done
4646

47+
# Check if the settings file exists...
48+
if [ ! -f ~/.vscode-server/data/Machine/settings.json ]; then
49+
echo "⚙️ Creating settings file..."
50+
mkdir -p ~/.vscode-server/data/Machine
51+
echo "${SETTINGS}" > ~/.vscode-server/data/Machine/settings.json
52+
fi
53+
4754
echo "👷 Running ${INSTALL_PREFIX}/bin/code-server serve-local --port ${PORT} --accept-server-license-terms serve-local --without-connection-token --telemetry-level ${TELEMETRY_LEVEL} in the background..."
4855
echo "Check logs at ${LOG_PATH}!"
4956
"${INSTALL_PREFIX}/bin/code-server" serve-local --port "${PORT}" --accept-server-license-terms serve-local --without-connection-token --telemetry-level "${TELEMETRY_LEVEL}" > "${LOG_PATH}" 2>&1 &

0 commit comments

Comments
 (0)