Skip to content

feat(vscode-web): add workspace file support #347

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

Draft
wants to merge 7 commits into
base: main
Choose a base branch
from
Draft
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
23 changes: 18 additions & 5 deletions registry/coder/modules/vscode-web/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -30,21 +30,34 @@ 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"
accept_license = true
}
```

### 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.4.0"
agent_id = coder_agent.example.id
workspace = "/home/coder/project.code-workspace"
accept_license = true
}
```

### Install Extensions

```tf
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
Expand All @@ -59,7 +72,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 = {
Expand All @@ -77,7 +90,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.4.0"
agent_id = coder_agent.example.id
commit_id = "e54c774e0add60467559eb0d1e229c6452cf8447"
accept_license = true
Expand Down
14 changes: 13 additions & 1 deletion registry/coder/modules/vscode-web/main.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,17 @@ describe("vscode-web", async () => {
expect(t).toThrow("Offline mode does not allow extensions to be installed");
});

it("folder and workspace can not be used together", () => {
const t = async () => {
await runTerraformApply(import.meta.dir, {
agent_id: "foo",
accept_license: "true",
folder: "/home/coder",
workspace: "/home/coder/project.code-workspace",
});
};
expect(t).toThrow("Cannot specify both 'folder' and 'workspace'. Please use only one.");
});

// More tests depend on shebang refactors
});
});
26 changes: 22 additions & 4 deletions registry/coder/modules/vscode-web/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,13 @@ variable "slug" {

variable "folder" {
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 = ""
}

Expand Down Expand Up @@ -178,6 +184,8 @@ resource "coder_script" "vscode-web" {
DISABLE_TRUST : var.disable_trust,
EXTENSIONS_DIR : var.extensions_dir,
FOLDER : var.folder,
WORKSPACE : var.workspace,
WORKSPACE_ARG : coalesce(var.workspace, var.folder),
AUTO_INSTALL_EXTENSIONS : var.auto_install_extensions,
SERVER_BASE_PATH : local.server_base_path,
COMMIT_ID : var.commit_id,
Expand All @@ -186,6 +194,11 @@ resource "coder_script" "vscode-web" {
run_on_start = true

lifecycle {
precondition {
condition = !(var.folder != "" && var.workspace != "")
error_message = "Cannot specify both 'folder' and 'workspace'. Please use only one."
}

precondition {
condition = !var.offline || length(var.extensions) == 0
error_message = "Offline mode does not allow extensions to be installed"
Expand Down Expand Up @@ -218,6 +231,11 @@ 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"
}

# 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"
}
4 changes: 2 additions & 2 deletions registry/coder/modules/vscode-web/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ if [ "${DISABLE_TRUST}" = true ]; then
fi

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}!"
"$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...
Expand Down
Binary file added terraform.zip
Binary file not shown.