diff --git a/registry/coder/modules/zed/README.md b/registry/coder/modules/zed/README.md index 9ebf82c2a..989df54d9 100644 --- a/registry/coder/modules/zed/README.md +++ b/registry/coder/modules/zed/README.md @@ -19,7 +19,7 @@ Zed is a high-performance, multiplayer code editor from the creators of Atom and module "zed" { count = data.coder_workspace.me.start_count source = "registry.coder.com/coder/zed/coder" - version = "1.0.1" + version = "1.1.0" agent_id = coder_agent.example.id } ``` @@ -32,7 +32,7 @@ module "zed" { module "zed" { count = data.coder_workspace.me.start_count source = "registry.coder.com/coder/zed/coder" - version = "1.0.1" + version = "1.1.0" agent_id = coder_agent.example.id folder = "/home/coder/project" } @@ -44,7 +44,7 @@ module "zed" { module "zed" { count = data.coder_workspace.me.start_count source = "registry.coder.com/coder/zed/coder" - version = "1.0.1" + version = "1.1.0" agent_id = coder_agent.example.id display_name = "Zed Editor" order = 1 @@ -57,8 +57,36 @@ module "zed" { module "zed" { count = data.coder_workspace.me.start_count source = "registry.coder.com/coder/zed/coder" - version = "1.0.1" + version = "1.1.0" agent_id = coder_agent.example.id agent_name = coder_agent.example.name } ``` + +### Configure Zed settings including MCP servers + +Zed stores settings at `~/.config/zed/settings.json` by default. If `XDG_CONFIG_HOME` is set on Linux, settings will be at `$XDG_CONFIG_HOME/zed/settings.json`. + +You can declaratively set/merge settings with the `settings` input. Provide a JSON string (e.g., via `jsonencode(...)`). For example, to configure MCP servers: + +```tf +module "zed" { + count = data.coder_workspace.me.start_count + source = "registry.coder.com/coder/zed/coder" + version = "1.1.0" + agent_id = coder_agent.example.id + + settings = jsonencode({ + context_servers = { + your-mcp-server = { + source = "custom" + command = "some-command" + args = ["arg-1", "arg-2"] + env = {} + } + } + }) +} +``` + +See Zed’s settings files documentation: https://zed.dev/docs/configuring-zed#settings-files diff --git a/registry/coder/modules/zed/main.tf b/registry/coder/modules/zed/main.tf index 2f6376a44..94ec69a6a 100644 --- a/registry/coder/modules/zed/main.tf +++ b/registry/coder/modules/zed/main.tf @@ -50,7 +50,14 @@ variable "display_name" { default = "Zed" } +variable "settings" { + type = string + description = "JSON encoded settings.json" + default = "" +} + data "coder_workspace" "me" {} + data "coder_workspace_owner" "me" {} locals { @@ -60,6 +67,30 @@ locals { hostname = var.agent_name != "" ? "${local.agent_name}.${local.workspace_name}.${local.owner_name}.coder" : "${local.workspace_name}.coder" } +resource "coder_script" "zed_settings" { + agent_id = var.agent_id + display_name = "Configure Zed settings" + icon = "/icon/zed.svg" + run_on_start = true + script = <<-EOT + set -eu + SETTINGS_JSON='${replace(var.settings, "\"", "\\\"")}' + if [ -z "$${SETTINGS_JSON}" ] || [ "$${SETTINGS_JSON}" = "{}" ]; then + exit 0 + fi + CONFIG_HOME="$${XDG_CONFIG_HOME:-$HOME/.config}" + ZED_DIR="$${CONFIG_HOME}/zed" + mkdir -p "$${ZED_DIR}" + SETTINGS_FILE="$${ZED_DIR}/settings.json" + if command -v jq >/dev/null 2>&1 && [ -s "$${SETTINGS_FILE}" ]; then + tmpfile="$(mktemp)" + jq -s '.[0] * .[1]' "$${SETTINGS_FILE}" <(printf '%s\n' "$${SETTINGS_JSON}") > "$${tmpfile}" && mv "$${tmpfile}" "$${SETTINGS_FILE}" + else + printf '%s\n' "$${SETTINGS_JSON}" > "$${SETTINGS_FILE}" + fi + EOT +} + resource "coder_app" "zed" { agent_id = var.agent_id display_name = var.display_name