Atif Ali ef5a903edf
fix(zed): fix settings JSON parsing with base64 encoding (#604)
## Problem

The Zed module's settings parsing was broken. The previous
implementation used quote escaping:

```hcl
SETTINGS_JSON='${replace(var.settings, "\"", "\\\"")}'
```

This produced invalid JSON like `{\"theme\":\"dark\"}` which **jq could
not parse** because the backslash-escaped quotes are not valid JSON
syntax.

## Solution

Changed to use base64 encoding internally:

```hcl
locals {
  settings_b64 = var.settings != "" ? base64encode(var.settings) : ""
}

# In the script:
SETTINGS_B64='${local.settings_b64}'
SETTINGS_JSON="$(echo -n "${SETTINGS_B64}" | base64 -d)"
```

**User interface remains the same** - users still provide plain JSON via
`jsonencode()` or heredoc:

```hcl
module "zed" {
  source   = "..."
  agent_id = coder_agent.main.id
  settings = jsonencode({
    theme    = "dark"
    fontSize = 14
  })
}
```

## Testing

Added comprehensive tests:

**Terraform tests (5):**
- URL generation (default, folder, agent_name)
- Settings base64 encoding verification
- Empty settings edge case

**Container e2e tests (3):**
- Creates settings file with correct JSON (including special chars:
quotes, backslashes, URLs)
- Merges with existing settings via jq
- Exits early with empty settings

Also fixed existing tests to use `override_data` for proper workspace
mocking.

---------

Signed-off-by: Muhammad Atif Ali <me@matifali.dev>
Co-authored-by: DevCats <christofer@coder.com>
2025-12-17 16:17:06 -06:00
..

display_name description icon verified tags
Zed Add a one-click button to launch Zed ../../../../.icons/zed.svg true
ide
zed
editor

Zed

Add a button to open any workspace with a single click in Zed.

Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.

Important

Zed needs you to either have Coder CLI installed with coder config-ssh run or Coder Desktop

module "zed" {
  count    = data.coder_workspace.me.start_count
  source   = "registry.coder.com/coder/zed/coder"
  version  = "1.1.4"
  agent_id = coder_agent.main.id
}

Examples

Open in a specific directory

module "zed" {
  count    = data.coder_workspace.me.start_count
  source   = "registry.coder.com/coder/zed/coder"
  version  = "1.1.4"
  agent_id = coder_agent.main.id
  folder   = "/home/coder/project"
}

Custom display name and order

module "zed" {
  count        = data.coder_workspace.me.start_count
  source       = "registry.coder.com/coder/zed/coder"
  version      = "1.1.4"
  agent_id     = coder_agent.main.id
  display_name = "Zed Editor"
  order        = 1
}

With custom agent name

module "zed" {
  count      = data.coder_workspace.me.start_count
  source     = "registry.coder.com/coder/zed/coder"
  version    = "1.1.4"
  agent_id   = coder_agent.main.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:

module "zed" {
  count    = data.coder_workspace.me.start_count
  source   = "registry.coder.com/coder/zed/coder"
  version  = "1.1.4"
  agent_id = coder_agent.main.id

  settings = jsonencode({
    context_servers = {
      your-mcp-server = {
        source  = "custom"
        command = "some-command"
        args    = ["arg-1", "arg-2"]
        env     = {}
      }


    }
  })
}

See Zeds settings files documentation: https://zed.dev/docs/configuring-zed#settings-files