Skip to content

Commit 6acded5

Browse files
CytoShaharDevelopmentCatsmatifali
authored
added positron desktop ide module based on vs code desktop (#528)
Co-authored-by: DevCats <[email protected]> Co-authored-by: Atif Ali <[email protected]>
1 parent f3c24af commit 6acded5

File tree

6 files changed

+224
-0
lines changed

6 files changed

+224
-0
lines changed

.icons/positron.svg

Lines changed: 12 additions & 0 deletions
Loading
43.8 KB
Loading

registry/cytoshahar/README.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
---
2+
display_name: "CytoShahar"
3+
bio: "Data engineer by day, maker by night"
4+
avatar: "./.images/avatar.jpeg"
5+
github: "https://github.com/CytoShahar"
6+
linkedin: "https://www.linkedin.com/in/shaharzrihen" # Optional
7+
status: "community"
8+
---
9+
10+
# Shahar Zrihen
11+
12+
Data engineer by day, maker by night
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
---
2+
display_name: Positron Desktop
3+
description: Add a one-click button to launch Positron Desktop
4+
icon: ../../../../.icons/positron.svg
5+
verified: true
6+
tags: [ide, positron]
7+
---
8+
9+
# Positron Desktop
10+
11+
Add a button to open any workspace with a single click.
12+
13+
Uses the [Coder Remote VS Code Extension](https://github.com/coder/vscode-coder).
14+
15+
```tf
16+
module "positron" {
17+
count = data.coder_workspace.me.start_count
18+
source = "registry.coder.com/cytoshahar/positron/coder"
19+
version = "1.0.0"
20+
agent_id = coder_agent.example.id
21+
}
22+
```
23+
24+
## Examples
25+
26+
### Open in a specific directory
27+
28+
```tf
29+
module "positron" {
30+
count = data.coder_workspace.me.start_count
31+
source = "registry.coder.com/cytoshahar/positron/coder"
32+
version = "1.0.0"
33+
agent_id = coder_agent.example.id
34+
folder = "/home/coder/project"
35+
}
36+
```
37+
38+
Based on the [Coder VS Code Desktop Module](https://github.com/coder/registry/tree/main/registry/coder/modules/vscode-desktop)
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
import { describe, expect, it } from "bun:test";
2+
import {
3+
runTerraformApply,
4+
runTerraformInit,
5+
testRequiredVariables,
6+
} from "~test";
7+
8+
describe("positron-desktop", 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.positron_url.value).toBe(
20+
"positron://coder.coder-remote/open?owner=default&workspace=default&url=https://mydeployment.coder.com&token=$SESSION_TOKEN",
21+
);
22+
23+
const coder_app = state.resources.find(
24+
(res) => res.type === "coder_app" && res.name === "positron",
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.positron_url.value).toBe(
38+
"positron://coder.coder-remote/open?owner=default&workspace=default&folder=/foo/bar&url=https://mydeployment.coder.com&token=$SESSION_TOKEN",
39+
);
40+
});
41+
42+
it("adds folder and open_recent", async () => {
43+
const state = await runTerraformApply(import.meta.dir, {
44+
agent_id: "foo",
45+
folder: "/foo/bar",
46+
open_recent: "true",
47+
});
48+
expect(state.outputs.positron_url.value).toBe(
49+
"positron://coder.coder-remote/open?owner=default&workspace=default&folder=/foo/bar&openRecent&url=https://mydeployment.coder.com&token=$SESSION_TOKEN",
50+
);
51+
});
52+
53+
it("adds folder but not open_recent", async () => {
54+
const state = await runTerraformApply(import.meta.dir, {
55+
agent_id: "foo",
56+
folder: "/foo/bar",
57+
openRecent: "false",
58+
});
59+
expect(state.outputs.positron_url.value).toBe(
60+
"positron://coder.coder-remote/open?owner=default&workspace=default&folder=/foo/bar&url=https://mydeployment.coder.com&token=$SESSION_TOKEN",
61+
);
62+
});
63+
64+
it("adds open_recent", async () => {
65+
const state = await runTerraformApply(import.meta.dir, {
66+
agent_id: "foo",
67+
open_recent: "true",
68+
});
69+
expect(state.outputs.positron_url.value).toBe(
70+
"positron://coder.coder-remote/open?owner=default&workspace=default&openRecent&url=https://mydeployment.coder.com&token=$SESSION_TOKEN",
71+
);
72+
});
73+
74+
it("expect order to be set", async () => {
75+
const state = await runTerraformApply(import.meta.dir, {
76+
agent_id: "foo",
77+
order: "22",
78+
});
79+
80+
const coder_app = state.resources.find(
81+
(res) => res.type === "coder_app" && res.name === "positron",
82+
);
83+
84+
expect(coder_app).not.toBeNull();
85+
expect(coder_app?.instances.length).toBe(1);
86+
expect(coder_app?.instances[0].attributes.order).toBe(22);
87+
});
88+
});
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
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+
locals {
13+
icon_url = "/icon/positron.svg"
14+
}
15+
16+
variable "agent_id" {
17+
type = string
18+
description = "The ID of a Coder agent."
19+
}
20+
21+
variable "folder" {
22+
type = string
23+
description = "The folder to open in Positron."
24+
default = ""
25+
}
26+
27+
variable "open_recent" {
28+
type = bool
29+
description = "Open the most recent workspace or folder. Falls back to the folder if there is no recent workspace or folder to open."
30+
default = false
31+
}
32+
33+
variable "order" {
34+
type = number
35+
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)."
36+
default = null
37+
}
38+
39+
variable "group" {
40+
type = string
41+
description = "The name of a group that this app belongs to."
42+
default = null
43+
}
44+
45+
data "coder_workspace" "me" {}
46+
data "coder_workspace_owner" "me" {}
47+
48+
resource "coder_app" "positron" {
49+
agent_id = var.agent_id
50+
external = true
51+
icon = local.icon_url
52+
slug = "positron"
53+
display_name = "Positron Desktop"
54+
order = var.order
55+
group = var.group
56+
57+
url = join("", [
58+
"positron://coder.coder-remote/open",
59+
"?owner=",
60+
data.coder_workspace_owner.me.name,
61+
"&workspace=",
62+
data.coder_workspace.me.name,
63+
var.folder != "" ? join("", ["&folder=", var.folder]) : "",
64+
var.open_recent ? "&openRecent" : "",
65+
"&url=",
66+
data.coder_workspace.me.access_url,
67+
"&token=$SESSION_TOKEN",
68+
])
69+
}
70+
71+
output "positron_url" {
72+
value = coder_app.positron.url
73+
description = "Positron Desktop URL."
74+
}

0 commit comments

Comments
 (0)