feat(vscode-web): add workspace file support

- Add 'workspace' variable to open .code-workspace files
- Add mutual exclusion validation between 'folder' and 'workspace'
- Update run.sh to handle workspace files as arguments to code-server
- Update README with workspace file example
- Bump version to 1.3.2

Fixes workspace file refresh issue by using proper VS Code web URL parameters.
This commit is contained in:
blink-so[bot] 2025-08-20 23:06:12 +00:00
parent 29e5307121
commit e737aa2a38
3 changed files with 45 additions and 8 deletions

View File

@ -14,7 +14,7 @@ Automatically install [Visual Studio Code Server](https://code.visualstudio.com/
module "vscode-web" { module "vscode-web" {
count = data.coder_workspace.me.start_count count = data.coder_workspace.me.start_count
source = "registry.coder.com/coder/vscode-web/coder" source = "registry.coder.com/coder/vscode-web/coder"
version = "1.3.1" version = "1.3.2"
agent_id = coder_agent.example.id agent_id = coder_agent.example.id
accept_license = true accept_license = true
} }
@ -38,6 +38,19 @@ module "vscode-web" {
} }
``` ```
### Open a VS Code workspace file
```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/project.code-workspace"
accept_license = true
}
```
### Install Extensions ### Install Extensions
```tf ```tf
@ -82,4 +95,3 @@ module "vscode-web" {
commit_id = "e54c774e0add60467559eb0d1e229c6452cf8447" commit_id = "e54c774e0add60467559eb0d1e229c6452cf8447"
accept_license = true accept_license = true
} }
```

View File

@ -34,7 +34,13 @@ variable "slug" {
variable "folder" { variable "folder" {
type = string type = string
description = "The folder to open in vscode-web." description = "The folder to open in vscode-web. Cannot be used with 'workspace'."
default = ""
}
variable "workspace" {
type = string
description = "Path to a .code-workspace file to open on startup. Cannot be used with 'folder'."
default = "" default = ""
} }
@ -178,6 +184,7 @@ resource "coder_script" "vscode-web" {
DISABLE_TRUST : var.disable_trust, DISABLE_TRUST : var.disable_trust,
EXTENSIONS_DIR : var.extensions_dir, EXTENSIONS_DIR : var.extensions_dir,
FOLDER : var.folder, FOLDER : var.folder,
WORKSPACE : var.workspace,
AUTO_INSTALL_EXTENSIONS : var.auto_install_extensions, AUTO_INSTALL_EXTENSIONS : var.auto_install_extensions,
SERVER_BASE_PATH : local.server_base_path, SERVER_BASE_PATH : local.server_base_path,
COMMIT_ID : var.commit_id, COMMIT_ID : var.commit_id,
@ -186,6 +193,11 @@ resource "coder_script" "vscode-web" {
run_on_start = true run_on_start = true
lifecycle { lifecycle {
precondition {
condition = !(var.folder != "" && var.workspace != "")
error_message = "Cannot specify both 'folder' and 'workspace'. Please use only one."
}
precondition { precondition {
condition = !var.offline || length(var.extensions) == 0 condition = !var.offline || length(var.extensions) == 0
error_message = "Offline mode does not allow extensions to be installed" error_message = "Offline mode does not allow extensions to be installed"
@ -218,6 +230,11 @@ resource "coder_app" "vscode-web" {
locals { locals {
server_base_path = var.subdomain ? "" : format("/@%s/%s/apps/%s/", data.coder_workspace_owner.me.name, data.coder_workspace.me.name, var.slug) 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" # Mutually exclusive: workspace takes precedence over folder
} query_param = var.workspace != "" ? "workspace=${urlencode(var.workspace)}" : (var.folder != "" ? "folder=${urlencode(var.folder)}" : "")
url = local.query_param != "" ? "http://localhost:${var.port}${local.server_base_path}?${local.query_param}" : "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"
}

View File

@ -22,10 +22,18 @@ if [ "${DISABLE_TRUST}" = true ]; then
DISABLE_TRUST_ARG="--disable-workspace-trust" DISABLE_TRUST_ARG="--disable-workspace-trust"
fi fi
# Set workspace or folder argument
WORKSPACE_ARG=""
if [ -n "${WORKSPACE}" ]; then
WORKSPACE_ARG="${WORKSPACE}"
elif [ -n "${FOLDER}" ]; then
WORKSPACE_ARG="${FOLDER}"
fi
run_vscode_web() { run_vscode_web() {
echo "👷 Running $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} in the background..." echo "👷 Running $VSCODE_WEB serve-local with workspace: ${WORKSPACE_ARG}"
echo "Check logs at ${LOG_PATH}!" echo "Check logs at ${LOG_PATH}!"
"$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 & "$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}" "${WORKSPACE_ARG}" > "${LOG_PATH}" 2>&1 &
} }
# Check if the settings file exists... # Check if the settings file exists...