Skip to content

Commit d9b223a

Browse files
matifaliblink-so[bot]DevelopmentCats
authored
feat(zed): settings input and MCP servers example (#317)
This PR adds an optional `settings` input to the Zed module and updates the README with an example for configuring MCP servers. Changes: - Add `settings` variable to modules/zed/main.tf - Add `coder_script` to write/merge `~/.config/zed/settings.json` (respects `$XDG_CONFIG_HOME` and merges with existing settings if `jq` is available) - Update README with a `settings` example configuring MCP context servers and clarify default settings path Test plan: - Syntax-only: `bun test --filter zed` fails in CI without Terraform; this change only adds inputs and a startup script. No behavior change to existing outputs. Co-authored-by: Atif Ali <[email protected]> --------- Co-authored-by: blink-so[bot] <211532188+blink-so[bot]@users.noreply.github.com> Co-authored-by: DevCats <[email protected]>
1 parent 1749f9c commit d9b223a

File tree

2 files changed

+63
-4
lines changed

2 files changed

+63
-4
lines changed

registry/coder/modules/zed/README.md

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ Zed is a high-performance, multiplayer code editor from the creators of Atom and
1919
module "zed" {
2020
count = data.coder_workspace.me.start_count
2121
source = "registry.coder.com/coder/zed/coder"
22-
version = "1.0.1"
22+
version = "1.1.0"
2323
agent_id = coder_agent.example.id
2424
}
2525
```
@@ -32,7 +32,7 @@ module "zed" {
3232
module "zed" {
3333
count = data.coder_workspace.me.start_count
3434
source = "registry.coder.com/coder/zed/coder"
35-
version = "1.0.1"
35+
version = "1.1.0"
3636
agent_id = coder_agent.example.id
3737
folder = "/home/coder/project"
3838
}
@@ -44,7 +44,7 @@ module "zed" {
4444
module "zed" {
4545
count = data.coder_workspace.me.start_count
4646
source = "registry.coder.com/coder/zed/coder"
47-
version = "1.0.1"
47+
version = "1.1.0"
4848
agent_id = coder_agent.example.id
4949
display_name = "Zed Editor"
5050
order = 1
@@ -57,8 +57,36 @@ module "zed" {
5757
module "zed" {
5858
count = data.coder_workspace.me.start_count
5959
source = "registry.coder.com/coder/zed/coder"
60-
version = "1.0.1"
60+
version = "1.1.0"
6161
agent_id = coder_agent.example.id
6262
agent_name = coder_agent.example.name
6363
}
6464
```
65+
66+
### Configure Zed settings including MCP servers
67+
68+
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`.
69+
70+
You can declaratively set/merge settings with the `settings` input. Provide a JSON string (e.g., via `jsonencode(...)`). For example, to configure MCP servers:
71+
72+
```tf
73+
module "zed" {
74+
count = data.coder_workspace.me.start_count
75+
source = "registry.coder.com/coder/zed/coder"
76+
version = "1.1.0"
77+
agent_id = coder_agent.example.id
78+
79+
settings = jsonencode({
80+
context_servers = {
81+
your-mcp-server = {
82+
source = "custom"
83+
command = "some-command"
84+
args = ["arg-1", "arg-2"]
85+
env = {}
86+
}
87+
}
88+
})
89+
}
90+
```
91+
92+
See Zed’s settings files documentation: https://zed.dev/docs/configuring-zed#settings-files

registry/coder/modules/zed/main.tf

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,14 @@ variable "display_name" {
5050
default = "Zed"
5151
}
5252

53+
variable "settings" {
54+
type = string
55+
description = "JSON encoded settings.json"
56+
default = ""
57+
}
58+
5359
data "coder_workspace" "me" {}
60+
5461
data "coder_workspace_owner" "me" {}
5562

5663
locals {
@@ -60,6 +67,30 @@ locals {
6067
hostname = var.agent_name != "" ? "${local.agent_name}.${local.workspace_name}.${local.owner_name}.coder" : "${local.workspace_name}.coder"
6168
}
6269

70+
resource "coder_script" "zed_settings" {
71+
agent_id = var.agent_id
72+
display_name = "Configure Zed settings"
73+
icon = "/icon/zed.svg"
74+
run_on_start = true
75+
script = <<-EOT
76+
set -eu
77+
SETTINGS_JSON='${replace(var.settings, "\"", "\\\"")}'
78+
if [ -z "$${SETTINGS_JSON}" ] || [ "$${SETTINGS_JSON}" = "{}" ]; then
79+
exit 0
80+
fi
81+
CONFIG_HOME="$${XDG_CONFIG_HOME:-$HOME/.config}"
82+
ZED_DIR="$${CONFIG_HOME}/zed"
83+
mkdir -p "$${ZED_DIR}"
84+
SETTINGS_FILE="$${ZED_DIR}/settings.json"
85+
if command -v jq >/dev/null 2>&1 && [ -s "$${SETTINGS_FILE}" ]; then
86+
tmpfile="$(mktemp)"
87+
jq -s '.[0] * .[1]' "$${SETTINGS_FILE}" <(printf '%s\n' "$${SETTINGS_JSON}") > "$${tmpfile}" && mv "$${tmpfile}" "$${SETTINGS_FILE}"
88+
else
89+
printf '%s\n' "$${SETTINGS_JSON}" > "$${SETTINGS_FILE}"
90+
fi
91+
EOT
92+
}
93+
6394
resource "coder_app" "zed" {
6495
agent_id = var.agent_id
6596
display_name = var.display_name

0 commit comments

Comments
 (0)