From bc91d626873edadb9a9db4922ccfc34776303e71 Mon Sep 17 00:00:00 2001 From: Rowan Smith Date: Thu, 21 Aug 2025 05:21:28 +0000 Subject: [PATCH 1/4] added support for loading workspaces at startup --- registry/coder/modules/vscode-web/README.md | 15 ++++++++++++ registry/coder/modules/vscode-web/main.tf | 22 +++++++++++++++-- registry/coder/modules/vscode-web/run.sh | 27 ++++++++++++++------- 3 files changed, 53 insertions(+), 11 deletions(-) diff --git a/registry/coder/modules/vscode-web/README.md b/registry/coder/modules/vscode-web/README.md index 474578577..bc160af61 100644 --- a/registry/coder/modules/vscode-web/README.md +++ b/registry/coder/modules/vscode-web/README.md @@ -83,3 +83,18 @@ module "vscode-web" { 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.3.2" + agent_id = coder_agent.example.id + workspace = "/home/coder/coder.code-workspace" +} +``` \ No newline at end of file diff --git a/registry/coder/modules/vscode-web/main.tf b/registry/coder/modules/vscode-web/main.tf index c00724544..1d7ec191d 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 From fb11585be5a5418aa7f3cc0caeb183461fd0caf7 Mon Sep 17 00:00:00 2001 From: Rowan Smith Date: Thu, 21 Aug 2025 05:21:28 +0000 Subject: [PATCH 2/4] bun fmt fixes --- registry/coder/modules/vscode-web/README.md | 16 ++++++++-------- registry/coder/modules/vscode-web/main.tf | 6 +++--- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/registry/coder/modules/vscode-web/README.md b/registry/coder/modules/vscode-web/README.md index bc160af61..f0426591e 100644 --- a/registry/coder/modules/vscode-web/README.md +++ b/registry/coder/modules/vscode-web/README.md @@ -86,15 +86,15 @@ module "vscode-web" { ### 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. +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.3.2" - agent_id = coder_agent.example.id - workspace = "/home/coder/coder.code-workspace" + count = data.coder_workspace.me.start_count + source = "registry.coder.com/coder/vscode-web/coder" + version = "1.3.2" + agent_id = coder_agent.example.id + workspace = "/home/coder/coder.code-workspace" } -``` \ No newline at end of file +``` diff --git a/registry/coder/modules/vscode-web/main.tf b/registry/coder/modules/vscode-web/main.tf index 1d7ec191d..99cf7539c 100644 --- a/registry/coder/modules/vscode-web/main.tf +++ b/registry/coder/modules/vscode-web/main.tf @@ -233,9 +233,9 @@ locals { 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}" + 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" } From e99bf112493c5a32dd37a04e0af03870c54fd2ed Mon Sep 17 00:00:00 2001 From: Rowan Smith Date: Thu, 21 Aug 2025 05:44:57 +0000 Subject: [PATCH 3/4] chore: bump module versions (patch) --- registry/coder/modules/vscode-web/README.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/registry/coder/modules/vscode-web/README.md b/registry/coder/modules/vscode-web/README.md index f0426591e..015f4e066 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.3.2" 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.3.2" 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.3.2" 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.3.2" agent_id = coder_agent.example.id extensions = ["dracula-theme.theme-dracula"] settings = { @@ -77,7 +77,7 @@ 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.3.2" agent_id = coder_agent.example.id commit_id = "e54c774e0add60467559eb0d1e229c6452cf8447" accept_license = true From e4d297dcc1f8d19a46f3445991ab8e0e60bdc050 Mon Sep 17 00:00:00 2001 From: Rowan Smith Date: Thu, 21 Aug 2025 06:01:17 +0000 Subject: [PATCH 4/4] chore: bump module versions (minor) --- registry/coder/modules/vscode-web/README.md | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/registry/coder/modules/vscode-web/README.md b/registry/coder/modules/vscode-web/README.md index 015f4e066..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.2" + 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.2" + 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.2" + 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.2" + version = "1.4.0" agent_id = coder_agent.example.id extensions = ["dracula-theme.theme-dracula"] settings = { @@ -77,7 +77,7 @@ 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.2" + version = "1.4.0" agent_id = coder_agent.example.id commit_id = "e54c774e0add60467559eb0d1e229c6452cf8447" accept_license = true @@ -93,7 +93,7 @@ Note: Either `workspace` or `folder` can be used, but not both simultaneously. T module "vscode-web" { count = data.coder_workspace.me.start_count source = "registry.coder.com/coder/vscode-web/coder" - version = "1.3.2" + version = "1.4.0" agent_id = coder_agent.example.id workspace = "/home/coder/coder.code-workspace" }