Skip to content

Commit af65559

Browse files
author
yashksaini-coder
committed
feat(tools): 207 Add pre-install & workspace settings to vscode-desktop
1 parent 0a3c9b0 commit af65559

File tree

4 files changed

+404
-0
lines changed

4 files changed

+404
-0
lines changed

registry/coder/modules/vscode-desktop/README.md

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,43 @@ module "vscode" {
3535
folder = "/home/coder/project"
3636
}
3737
```
38+
39+
### Auto-install extensions and configure settings
40+
41+
```tf
42+
module "vscode" {
43+
count = data.coder_workspace.me.start_count
44+
source = "registry.coder.com/coder/vscode-desktop/coder"
45+
version = "1.1.0"
46+
agent_id = coder_agent.example.id
47+
folder = "/home/coder/project"
48+
49+
# Auto-install Python development extensions
50+
extensions = [
51+
"ms-python.python",
52+
"ms-python.pylint",
53+
"ms-toolsai.jupyter"
54+
]
55+
56+
# Configure workspace settings
57+
settings = {
58+
"editor.fontSize" = 14
59+
"editor.tabSize" = 2
60+
"python.defaultInterpreterPath" = "/usr/bin/python3"
61+
"workbench.colorTheme" = "Dark+ (default dark)"
62+
}
63+
}
64+
```
65+
66+
### Disable automatic extension installation
67+
68+
```tf
69+
module "vscode" {
70+
count = data.coder_workspace.me.start_count
71+
source = "registry.coder.com/coder/vscode-desktop/coder"
72+
version = "1.1.0"
73+
agent_id = coder_agent.example.id
74+
extensions = ["ms-python.python"]
75+
install_extensions = false # Only create recommendations, don't install
76+
}
77+
```

registry/coder/modules/vscode-desktop/main.test.ts

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,4 +86,59 @@ describe("vscode-desktop", async () => {
8686
expect(coder_app?.instances.length).toBe(1);
8787
expect(coder_app?.instances[0].attributes.order).toBe(22);
8888
});
89+
90+
it("creates setup script when extensions are provided", async () => {
91+
const state = await runTerraformApply(import.meta.dir, {
92+
agent_id: "foo",
93+
extensions: '["ms-python.python", "ms-vscode.cpptools"]',
94+
});
95+
96+
const coder_script = state.resources.find(
97+
(res) => res.type === "coder_script" && res.name === "vscode_desktop_setup",
98+
);
99+
100+
expect(coder_script).not.toBeNull();
101+
expect(coder_script?.instances.length).toBe(1);
102+
expect(coder_script?.instances[0].attributes.run_on_start).toBe(true);
103+
});
104+
105+
it("creates setup script when settings are provided", async () => {
106+
const state = await runTerraformApply(import.meta.dir, {
107+
agent_id: "foo",
108+
settings: '{"editor.fontSize": 14, "workbench.colorTheme": "Dark+ (default dark)"}',
109+
});
110+
111+
const coder_script = state.resources.find(
112+
(res) => res.type === "coder_script" && res.name === "vscode_desktop_setup",
113+
);
114+
115+
expect(coder_script).not.toBeNull();
116+
expect(coder_script?.instances.length).toBe(1);
117+
});
118+
119+
it("does not create setup script when install_extensions is false", async () => {
120+
const state = await runTerraformApply(import.meta.dir, {
121+
agent_id: "foo",
122+
extensions: '["ms-python.python"]',
123+
install_extensions: "false",
124+
});
125+
126+
const coder_script = state.resources.find(
127+
(res) => res.type === "coder_script" && res.name === "vscode_desktop_setup",
128+
);
129+
130+
expect(coder_script).toBeNull();
131+
});
132+
133+
it("does not create setup script when no extensions or settings", async () => {
134+
const state = await runTerraformApply(import.meta.dir, {
135+
agent_id: "foo",
136+
});
137+
138+
const coder_script = state.resources.find(
139+
(res) => res.type === "coder_script" && res.name === "vscode_desktop_setup",
140+
);
141+
142+
expect(coder_script).toBeNull();
143+
});
89144
});

registry/coder/modules/vscode-desktop/main.tf

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,51 @@ variable "group" {
3838
default = null
3939
}
4040

41+
variable "extensions" {
42+
type = list(string)
43+
description = "A list of VS Code extensions to install. Extensions should be specified in the format 'publisher.extension-name'."
44+
default = []
45+
46+
validation {
47+
condition = alltrue([
48+
for ext in var.extensions : can(regex("^[a-zA-Z0-9][a-zA-Z0-9\\-_]*\\.[a-zA-Z0-9][a-zA-Z0-9\\-_]*$", ext))
49+
])
50+
error_message = "Extensions must be in the format 'publisher.extension-name' (e.g., 'ms-python.python')."
51+
}
52+
}
53+
54+
variable "settings" {
55+
type = any
56+
description = "A map of VS Code settings to apply to the workspace. These settings will be written to the workspace's settings.json file."
57+
default = {}
58+
}
59+
60+
variable "install_extensions" {
61+
type = bool
62+
description = "Whether to automatically install the specified extensions when the workspace starts."
63+
default = true
64+
}
65+
4166
data "coder_workspace" "me" {}
4267
data "coder_workspace_owner" "me" {}
4368

69+
# Script to install extensions and configure settings
70+
resource "coder_script" "vscode_desktop_setup" {
71+
count = var.install_extensions && (length(var.extensions) > 0 || length(var.settings) > 0) ? 1 : 0
72+
agent_id = var.agent_id
73+
display_name = "VS Code Desktop Setup"
74+
icon = "/icon/code.svg"
75+
run_on_start = true
76+
run_on_stop = false
77+
timeout = 300
78+
79+
script = templatefile("${path.module}/setup.sh", {
80+
EXTENSIONS = jsonencode(var.extensions)
81+
SETTINGS = jsonencode(var.settings)
82+
FOLDER = var.folder
83+
})
84+
}
85+
4486
resource "coder_app" "vscode" {
4587
agent_id = var.agent_id
4688
external = true

0 commit comments

Comments
 (0)