diff --git a/registry/coder/modules/vscode-web/README.md b/registry/coder/modules/vscode-web/README.md index 474578577..b2e922405 100644 --- a/registry/coder/modules/vscode-web/README.md +++ b/registry/coder/modules/vscode-web/README.md @@ -14,7 +14,7 @@ Automatically install [Visual Studio Code Server](https://code.visualstudio.com/ module "vscode-web" { count = data.coder_workspace.me.start_count source = "registry.coder.com/coder/vscode-web/coder" - version = "1.3.1" + version = "1.4.0" agent_id = coder_agent.example.id accept_license = true } @@ -30,7 +30,7 @@ module "vscode-web" { module "vscode-web" { count = data.coder_workspace.me.start_count source = "registry.coder.com/coder/vscode-web/coder" - version = "1.3.1" + version = "1.4.0" agent_id = coder_agent.example.id install_prefix = "/home/coder/.vscode-web" folder = "/home/coder" @@ -44,7 +44,7 @@ module "vscode-web" { module "vscode-web" { count = data.coder_workspace.me.start_count source = "registry.coder.com/coder/vscode-web/coder" - version = "1.3.1" + version = "1.4.0" agent_id = coder_agent.example.id extensions = ["github.copilot", "ms-python.python", "ms-toolsai.jupyter"] accept_license = true @@ -59,7 +59,7 @@ Configure VS Code's [settings.json](https://code.visualstudio.com/docs/getstarte module "vscode-web" { count = data.coder_workspace.me.start_count source = "registry.coder.com/coder/vscode-web/coder" - version = "1.3.1" + version = "1.4.0" agent_id = coder_agent.example.id extensions = ["dracula-theme.theme-dracula"] settings = { @@ -77,9 +77,24 @@ By default, this module installs the latest. To pin a specific version, retrieve module "vscode-web" { count = data.coder_workspace.me.start_count source = "registry.coder.com/coder/vscode-web/coder" - version = "1.3.1" + version = "1.4.0" agent_id = coder_agent.example.id commit_id = "e54c774e0add60467559eb0d1e229c6452cf8447" accept_license = true } ``` + +### Open an existing workspace on startup + +To open an existing workspace on startup the `workspace` parameter can be used to represent a path on disk to a `code-workspace` file. +Note: Either `workspace` or `folder` can be used, but not both simultaneously. The `code-workspace` file must already be present on disk. + +```tf +module "vscode-web" { + count = data.coder_workspace.me.start_count + source = "registry.coder.com/coder/vscode-web/coder" + version = "1.4.0" + agent_id = coder_agent.example.id + workspace = "/home/coder/coder.code-workspace" +} +``` diff --git a/registry/coder/modules/vscode-web/main.tf b/registry/coder/modules/vscode-web/main.tf index c00724544..99cf7539c 100644 --- a/registry/coder/modules/vscode-web/main.tf +++ b/registry/coder/modules/vscode-web/main.tf @@ -158,6 +158,12 @@ variable "platform" { } } +variable "workspace" { + type = string + description = "Path to a .code-workspace file to open in vscode-web." + default = null +} + data "coder_workspace_owner" "me" {} data "coder_workspace" "me" {} @@ -178,6 +184,7 @@ resource "coder_script" "vscode-web" { DISABLE_TRUST : var.disable_trust, EXTENSIONS_DIR : var.extensions_dir, FOLDER : var.folder, + WORKSPACE : var.workspace, AUTO_INSTALL_EXTENSIONS : var.auto_install_extensions, SERVER_BASE_PATH : local.server_base_path, COMMIT_ID : var.commit_id, @@ -195,6 +202,11 @@ resource "coder_script" "vscode-web" { condition = !var.offline || !var.use_cached error_message = "Offline and Use Cached can not be used together" } + + precondition { + condition = (var.workspace == "" || var.folder == "") + error_message = "Set only one of `workspace` or `folder`." + } } } @@ -218,6 +230,12 @@ resource "coder_app" "vscode-web" { locals { server_base_path = var.subdomain ? "" : format("/@%s/%s/apps/%s/", data.coder_workspace_owner.me.name, data.coder_workspace.me.name, var.slug) - url = var.folder == "" ? "http://localhost:${var.port}${local.server_base_path}" : "http://localhost:${var.port}${local.server_base_path}?folder=${var.folder}" - healthcheck_url = var.subdomain ? "http://localhost:${var.port}/healthz" : "http://localhost:${var.port}${local.server_base_path}/healthz" + url = ( + var.workspace != "" ? + "http://localhost:${var.port}${local.server_base_path}?workspace=${urlencode(var.workspace)}" : + var.folder != "" ? + "http://localhost:${var.port}${local.server_base_path}?folder=${urlencode(var.folder)}" : + "http://localhost:${var.port}${local.server_base_path}" + ) + healthcheck_url = var.subdomain ? "http://localhost:${var.port}/healthz" : "http://localhost:${var.port}${local.server_base_path}/healthz" } diff --git a/registry/coder/modules/vscode-web/run.sh b/registry/coder/modules/vscode-web/run.sh index 9346b4bdb..98881d721 100644 --- a/registry/coder/modules/vscode-web/run.sh +++ b/registry/coder/modules/vscode-web/run.sh @@ -109,18 +109,27 @@ if [ "${AUTO_INSTALL_EXTENSIONS}" = true ]; then if ! command -v jq > /dev/null; then echo "jq is required to install extensions from a workspace file." else - WORKSPACE_DIR="$HOME" - if [ -n "${FOLDER}" ]; then - WORKSPACE_DIR="${FOLDER}" - fi - - if [ -f "$WORKSPACE_DIR/.vscode/extensions.json" ]; then - printf "🧩 Installing extensions from %s/.vscode/extensions.json...\n" "$WORKSPACE_DIR" - # Use sed to remove single-line comments before parsing with jq - extensions=$(sed 's|//.*||g' "$WORKSPACE_DIR"/.vscode/extensions.json | jq -r '.recommendations[]') + # Prefer WORKSPACE if set and points to a file + if [ -n "${WORKSPACE}" ] && [ -f "${WORKSPACE}" ]; then + printf "🧩 Installing extensions from %s...\n" "${WORKSPACE}" + # Strip single-line comments then parse .extensions.recommendations[] + extensions=$(sed 's|//.*||g' "${WORKSPACE}" | jq -r '(.extensions.recommendations // [])[]') for extension in $extensions; do $VSCODE_WEB "$EXTENSION_ARG" --install-extension "$extension" --force done + else + # Fallback to folder-based .vscode/extensions.json (existing behavior) + WORKSPACE_DIR="$HOME" + if [ -n "${FOLDER}" ]; then + WORKSPACE_DIR="${FOLDER}" + fi + if [ -f "$WORKSPACE_DIR/.vscode/extensions.json" ]; then + printf "🧩 Installing extensions from %s/.vscode/extensions.json...\n" "$WORKSPACE_DIR" + extensions=$(sed 's|//.*||g' "$WORKSPACE_DIR/.vscode/extensions.json" | jq -r '.recommendations[]') + for extension in $extensions; do + $VSCODE_WEB "$EXTENSION_ARG" --install-extension "$extension" --force + done + fi fi fi fi