Skip to content

Commit eb27843

Browse files
Add Zed IDE module (#179)
Co-authored-by: blink-so[bot] <211532188+blink-so[bot]@users.noreply.github.com> Co-authored-by: matifali <10648092+matifali@users.noreply.github.com>
1 parent e95d90d commit eb27843

File tree

4 files changed

+226
-0
lines changed

4 files changed

+226
-0
lines changed

.icons/zed.svg

Lines changed: 3 additions & 0 deletions
Loading

registry/coder/modules/zed/README.md

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
---
2+
display_name: Zed
3+
description: Add a one-click button to launch Zed
4+
icon: ../../../../.icons/zed.svg
5+
maintainer_github: coder
6+
verified: true
7+
tags: [ide, zed, editor]
8+
---
9+
10+
# Zed
11+
12+
Add a button to open any workspace with a single click in Zed.
13+
14+
Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
15+
16+
> [!IMPORTANT]
17+
> Zed needs you to either have Coder CLI installed with `coder config-ssh` run or [Coder Desktop](https://coder.com/docs/user-guides/desktop)
18+
19+
```tf
20+
module "zed" {
21+
count = data.coder_workspace.me.start_count
22+
source = "registry.coder.com/coder/zed/coder"
23+
version = "1.0.0"
24+
agent_id = coder_agent.example.id
25+
}
26+
```
27+
28+
## Examples
29+
30+
### Open in a specific directory
31+
32+
```tf
33+
module "zed" {
34+
count = data.coder_workspace.me.start_count
35+
source = "registry.coder.com/coder/zed/coder"
36+
version = "1.0.0"
37+
agent_id = coder_agent.example.id
38+
folder = "/home/coder/project"
39+
}
40+
```
41+
42+
### Custom display name and order
43+
44+
```tf
45+
module "zed" {
46+
count = data.coder_workspace.me.start_count
47+
source = "registry.coder.com/coder/zed/coder"
48+
version = "1.0.0"
49+
agent_id = coder_agent.example.id
50+
display_name = "Zed Editor"
51+
order = 1
52+
}
53+
```
54+
55+
### With custom agent name
56+
57+
```tf
58+
module "zed" {
59+
count = data.coder_workspace.me.start_count
60+
source = "registry.coder.com/coder/zed/coder"
61+
version = "1.0.0"
62+
agent_id = coder_agent.example.id
63+
agent_name = coder_agent.example.name
64+
}
65+
```
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
import { describe, expect, it } from "bun:test";
2+
import {
3+
runTerraformApply,
4+
runTerraformInit,
5+
testRequiredVariables,
6+
} from "~test";
7+
8+
describe("zed", async () => {
9+
await runTerraformInit(import.meta.dir);
10+
11+
testRequiredVariables(import.meta.dir, {
12+
agent_id: "foo",
13+
});
14+
15+
it("default output", async () => {
16+
const state = await runTerraformApply(import.meta.dir, {
17+
agent_id: "foo",
18+
});
19+
expect(state.outputs.zed_url.value).toBe(
20+
"zed://ssh/default.coder",
21+
);
22+
23+
const coder_app = state.resources.find(
24+
(res) => res.type === "coder_app" && res.name === "zed",
25+
);
26+
27+
expect(coder_app).not.toBeNull();
28+
expect(coder_app?.instances.length).toBe(1);
29+
expect(coder_app?.instances[0].attributes.order).toBeNull();
30+
});
31+
32+
it("adds folder", async () => {
33+
const state = await runTerraformApply(import.meta.dir, {
34+
agent_id: "foo",
35+
folder: "/foo/bar",
36+
});
37+
expect(state.outputs.zed_url.value).toBe(
38+
"zed://ssh/default.coder/foo/bar",
39+
);
40+
});
41+
42+
it("expect order to be set", async () => {
43+
const state = await runTerraformApply(import.meta.dir, {
44+
agent_id: "foo",
45+
order: "22",
46+
});
47+
48+
const coder_app = state.resources.find(
49+
(res) => res.type === "coder_app" && res.name === "zed",
50+
);
51+
52+
expect(coder_app).not.toBeNull();
53+
expect(coder_app?.instances.length).toBe(1);
54+
expect(coder_app?.instances[0].attributes.order).toBe(22);
55+
});
56+
57+
it("expect display_name to be set", async () => {
58+
const state = await runTerraformApply(import.meta.dir, {
59+
agent_id: "foo",
60+
display_name: "Custom Zed",
61+
});
62+
63+
const coder_app = state.resources.find(
64+
(res) => res.type === "coder_app" && res.name === "zed",
65+
);
66+
67+
expect(coder_app).not.toBeNull();
68+
expect(coder_app?.instances.length).toBe(1);
69+
expect(coder_app?.instances[0].attributes.display_name).toBe("Custom Zed");
70+
});
71+
72+
it("adds agent_name to hostname", async () => {
73+
const state = await runTerraformApply(import.meta.dir, {
74+
agent_id: "foo",
75+
agent_name: "myagent",
76+
});
77+
expect(state.outputs.zed_url.value).toBe(
78+
"zed://ssh/myagent.default.default.coder",
79+
);
80+
});
81+
});

registry/coder/modules/zed/main.tf

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
terraform {
2+
required_version = ">= 1.0"
3+
4+
required_providers {
5+
coder = {
6+
source = "coder/coder"
7+
version = ">= 2.5"
8+
}
9+
}
10+
}
11+
12+
variable "agent_id" {
13+
type = string
14+
description = "The ID of a Coder agent"
15+
}
16+
17+
variable "agent_name" {
18+
type = string
19+
description = "The name of the agent"
20+
default = ""
21+
}
22+
23+
variable "folder" {
24+
type = string
25+
description = "The folder to open in Zed"
26+
default = ""
27+
}
28+
29+
variable "order" {
30+
type = number
31+
description = "The order determines the position of app in the UI presentation. The lowest order is shown first and apps with equal order are sorted by name (ascending order)"
32+
default = null
33+
}
34+
35+
variable "group" {
36+
type = string
37+
description = "The name of a group that this app belongs to"
38+
default = null
39+
}
40+
41+
variable "slug" {
42+
type = string
43+
description = "The slug of the app"
44+
default = "zed"
45+
}
46+
47+
variable "display_name" {
48+
type = string
49+
description = "The display name of the app"
50+
default = "Zed"
51+
}
52+
53+
data "coder_workspace" "me" {}
54+
data "coder_workspace_owner" "me" {}
55+
56+
locals {
57+
workspace_name = lower(data.coder_workspace.me.name)
58+
owner_name = lower(data.coder_workspace_owner.me.name)
59+
agent_name = lower(var.agent_name)
60+
hostname = var.agent_name != "" ? "${local.agent_name}.${local.workspace_name}.${local.owner_name}.coder" : "${local.workspace_name}.coder"
61+
}
62+
63+
resource "coder_app" "zed" {
64+
agent_id = var.agent_id
65+
display_name = var.display_name
66+
slug = var.slug
67+
icon = "/icon/zed.svg"
68+
external = true
69+
order = var.order
70+
group = var.group
71+
url = "zed://ssh/${local.hostname}${var.folder}"
72+
}
73+
74+
output "zed_url" {
75+
value = coder_app.zed.url
76+
description = "Zed URL"
77+
}

0 commit comments

Comments
 (0)