Skip to content

feat(vscode-web): add support for settings #195

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Mar 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions vscode-web/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,20 @@ module "vscode-web" {
accept_license = true
}
```

### Pre-configure Settings

Configure VS Code's [settings.json](https://code.visualstudio.com/docs/getstarted/settings#_settingsjson) file:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we add a warning that user settings cannot be customized because they are stored in the browser, so only machine settings will work? We could also recommend code-server if they absolutely need to have user settings, or recommend using settings sync.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@code-asher - maybe for another PR, but i think it would be useful to list out know issues and benefits the differentiate to the options.

ie:
code-server:

  • is more functionally complete
  • has less issues
  • does not support the microsoft marketplace
  • does not support some of the microsoft extensions like copilt, liveshare
  • does not require wildcard urls
  • etc..

vscode-web:

  • has issues with port forwarding
  • settings issues
  • requires wildcard / subdomain = true.
  • does not support self-hosted extensions
  • supports the microsoft extensions
  • etc..

Copy link
Member

@code-asher code-asher Mar 18, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed! This is a good list. code-server has a list of differences from Codespaces (https://github.com/coder/code-server/blob/main/docs/FAQ.md#whats-the-difference-between-code-server-and-github-codespaces) but not the self-hosted version, so we should probably add something there as well (this list is also a little out of date). Some of the differences there apply to the self-hosted version as well though.


```tf
module "vscode-web" {
source = "registry.coder.com/modules/vscode-web/coder"
version = "1.0.8"
agent_id = coder_agent.example.id
extensions = ["dracula-theme.theme-dracula"]
settings = {
"workbench.colorTheme" = "Dracula"
}
accept_license = true
}
```
8 changes: 8 additions & 0 deletions vscode-web/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,12 @@ variable "order" {
default = null
}

variable "settings" {
type = map(string)
description = "A map of settings to apply to VS Code web."
default = {}
}

resource "coder_script" "vscode-web" {
agent_id = var.agent_id
display_name = "VS Code Web"
Expand All @@ -101,6 +107,8 @@ resource "coder_script" "vscode-web" {
INSTALL_PREFIX : var.install_prefix,
EXTENSIONS : join(",", var.extensions),
TELEMETRY_LEVEL : var.telemetry_level,
// This is necessary otherwise the quotes are stripped!
SETTINGS : replace(jsonencode(var.settings), "\"", "\\\""),
})
run_on_start = true
}
Expand Down
11 changes: 9 additions & 2 deletions vscode-web/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ case "$ARCH" in
;;
esac

HASH=$(curl https://update.code.visualstudio.com/api/commits/stable/server-linux-$ARCH-web | cut -d '"' -f 2)
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)
HASH=$(curl -fsSL https://update.code.visualstudio.com/api/commits/stable/server-linux-$ARCH-web | cut -d '"' -f 2)
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)

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

# 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

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..."
echo "Check logs at ${LOG_PATH}!"
"${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 &