Skip to content

Commit 013a2cf

Browse files
AdemBenAbdallahcodex
authored andcommitted
Support Zed alias command detection
- Resolve editor launches against multiple command aliases - Include zeditor as a fallback for Zed and update availability checks - Refresh MSW worker version Co-authored-by: codex <[email protected]>
1 parent 340dbbb commit 013a2cf

3 files changed

Lines changed: 92 additions & 14 deletions

File tree

‎apps/server/src/open.test.ts‎

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ it.layer(NodeServices.layer)("resolveEditorLaunch", (it) => {
1616
const antigravityLaunch = yield* resolveEditorLaunch(
1717
{ cwd: "/tmp/workspace", editor: "antigravity" },
1818
"darwin",
19+
{ PATH: "" },
1920
);
2021
assert.deepEqual(antigravityLaunch, {
2122
command: "agy",
@@ -25,6 +26,7 @@ it.layer(NodeServices.layer)("resolveEditorLaunch", (it) => {
2526
const cursorLaunch = yield* resolveEditorLaunch(
2627
{ cwd: "/tmp/workspace", editor: "cursor" },
2728
"darwin",
29+
{ PATH: "" },
2830
);
2931
assert.deepEqual(cursorLaunch, {
3032
command: "cursor",
@@ -43,6 +45,7 @@ it.layer(NodeServices.layer)("resolveEditorLaunch", (it) => {
4345
const vscodeLaunch = yield* resolveEditorLaunch(
4446
{ cwd: "/tmp/workspace", editor: "vscode" },
4547
"darwin",
48+
{ PATH: "" },
4649
);
4750
assert.deepEqual(vscodeLaunch, {
4851
command: "code",
@@ -70,6 +73,7 @@ it.layer(NodeServices.layer)("resolveEditorLaunch", (it) => {
7073
const zedLaunch = yield* resolveEditorLaunch(
7174
{ cwd: "/tmp/workspace", editor: "zed" },
7275
"darwin",
76+
{ PATH: "" },
7377
);
7478
assert.deepEqual(zedLaunch, {
7579
command: "zed",
@@ -92,6 +96,7 @@ it.layer(NodeServices.layer)("resolveEditorLaunch", (it) => {
9296
const lineOnly = yield* resolveEditorLaunch(
9397
{ cwd: "/tmp/workspace/AGENTS.md:48", editor: "cursor" },
9498
"darwin",
99+
{ PATH: "" },
95100
);
96101
assert.deepEqual(lineOnly, {
97102
command: "cursor",
@@ -101,6 +106,7 @@ it.layer(NodeServices.layer)("resolveEditorLaunch", (it) => {
101106
const lineAndColumn = yield* resolveEditorLaunch(
102107
{ cwd: "/tmp/workspace/src/open.ts:71:5", editor: "cursor" },
103108
"darwin",
109+
{ PATH: "" },
104110
);
105111
assert.deepEqual(lineAndColumn, {
106112
command: "cursor",
@@ -119,6 +125,7 @@ it.layer(NodeServices.layer)("resolveEditorLaunch", (it) => {
119125
const vscodeLineAndColumn = yield* resolveEditorLaunch(
120126
{ cwd: "/tmp/workspace/src/open.ts:71:5", editor: "vscode" },
121127
"darwin",
128+
{ PATH: "" },
122129
);
123130
assert.deepEqual(vscodeLineAndColumn, {
124131
command: "code",
@@ -146,6 +153,7 @@ it.layer(NodeServices.layer)("resolveEditorLaunch", (it) => {
146153
const zedLineAndColumn = yield* resolveEditorLaunch(
147154
{ cwd: "/tmp/workspace/src/open.ts:71:5", editor: "zed" },
148155
"darwin",
156+
{ PATH: "" },
149157
);
150158
assert.deepEqual(zedLineAndColumn, {
151159
command: "zed",
@@ -181,11 +189,43 @@ it.layer(NodeServices.layer)("resolveEditorLaunch", (it) => {
181189
}),
182190
);
183191

192+
it.effect("falls back to zeditor when zed is not installed", () =>
193+
Effect.gen(function* () {
194+
const fs = yield* FileSystem.FileSystem;
195+
const path = yield* Path.Path;
196+
const dir = yield* fs.makeTempDirectoryScoped({ prefix: "t3-open-test-" });
197+
yield* fs.writeFileString(path.join(dir, "zeditor"), "#!/bin/sh\nexit 0\n");
198+
yield* fs.chmod(path.join(dir, "zeditor"), 0o755);
199+
200+
const result = yield* resolveEditorLaunch({ cwd: "/tmp/workspace", editor: "zed" }, "linux", {
201+
PATH: dir,
202+
});
203+
204+
assert.deepEqual(result, {
205+
command: "zeditor",
206+
args: ["/tmp/workspace"],
207+
});
208+
}),
209+
);
210+
211+
it.effect("falls back to the primary command when no alias is installed", () =>
212+
Effect.gen(function* () {
213+
const result = yield* resolveEditorLaunch({ cwd: "/tmp/workspace", editor: "zed" }, "linux", {
214+
PATH: "",
215+
});
216+
assert.deepEqual(result, {
217+
command: "zed",
218+
args: ["/tmp/workspace"],
219+
});
220+
}),
221+
);
222+
184223
it.effect("maps file-manager editor to OS open commands", () =>
185224
Effect.gen(function* () {
186225
const launch1 = yield* resolveEditorLaunch(
187226
{ cwd: "/tmp/workspace", editor: "file-manager" },
188227
"darwin",
228+
{ PATH: "" },
189229
);
190230
assert.deepEqual(launch1, {
191231
command: "open",
@@ -195,6 +235,7 @@ it.layer(NodeServices.layer)("resolveEditorLaunch", (it) => {
195235
const launch2 = yield* resolveEditorLaunch(
196236
{ cwd: "C:\\workspace", editor: "file-manager" },
197237
"win32",
238+
{ PATH: "" },
198239
);
199240
assert.deepEqual(launch2, {
200241
command: "explorer",
@@ -204,6 +245,7 @@ it.layer(NodeServices.layer)("resolveEditorLaunch", (it) => {
204245
const launch3 = yield* resolveEditorLaunch(
205246
{ cwd: "/tmp/workspace", editor: "file-manager" },
206247
"linux",
248+
{ PATH: "" },
207249
);
208250
assert.deepEqual(launch3, {
209251
command: "xdg-open",
@@ -321,4 +363,22 @@ it.layer(NodeServices.layer)("resolveAvailableEditors", (it) => {
321363
assert.deepEqual(editors, ["trae", "vscode-insiders", "vscodium", "file-manager"]);
322364
}),
323365
);
366+
367+
it.effect("includes zed when only the zeditor command is installed", () =>
368+
Effect.gen(function* () {
369+
const fs = yield* FileSystem.FileSystem;
370+
const path = yield* Path.Path;
371+
const dir = yield* fs.makeTempDirectoryScoped({ prefix: "t3-editors-" });
372+
373+
yield* fs.writeFileString(path.join(dir, "zeditor"), "#!/bin/sh\nexit 0\n");
374+
yield* fs.writeFileString(path.join(dir, "xdg-open"), "#!/bin/sh\nexit 0\n");
375+
yield* fs.chmod(path.join(dir, "zeditor"), 0o755);
376+
yield* fs.chmod(path.join(dir, "xdg-open"), 0o755);
377+
378+
const editors = resolveAvailableEditors("linux", {
379+
PATH: dir,
380+
});
381+
assert.deepEqual(editors, ["zed", "file-manager"]);
382+
}),
383+
);
324384
});

‎apps/server/src/open.ts‎

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,18 @@ function resolveCommandEditorArgs(
7575
}
7676
}
7777

78+
function resolveAvailableCommand(
79+
commands: ReadonlyArray<string>,
80+
options: CommandAvailabilityOptions = {},
81+
): string | null {
82+
for (const command of commands) {
83+
if (isCommandAvailable(command, options)) {
84+
return command;
85+
}
86+
}
87+
return null;
88+
}
89+
7890
function fileManagerCommandForPlatform(platform: NodeJS.Platform): string {
7991
switch (platform) {
8092
case "darwin":
@@ -198,8 +210,11 @@ export function resolveAvailableEditors(
198210
const available: EditorId[] = [];
199211

200212
for (const editor of EDITORS) {
201-
const command = editor.command ?? fileManagerCommandForPlatform(platform);
202-
if (isCommandAvailable(command, { platform, env })) {
213+
const command =
214+
editor.commands === null
215+
? fileManagerCommandForPlatform(platform)
216+
: resolveAvailableCommand(editor.commands, { platform, env });
217+
if (command !== null) {
203218
available.push(editor.id);
204219
}
205220
}
@@ -236,6 +251,7 @@ export class Open extends ServiceMap.Service<Open, OpenShape>()("t3/open") {}
236251
export const resolveEditorLaunch = Effect.fn("resolveEditorLaunch")(function* (
237252
input: OpenInEditorInput,
238253
platform: NodeJS.Platform = process.platform,
254+
env: NodeJS.ProcessEnv = process.env,
239255
): Effect.fn.Return<EditorLaunch, OpenError> {
240256
yield* Effect.annotateCurrentSpan({
241257
"open.editor": input.editor,
@@ -247,9 +263,11 @@ export const resolveEditorLaunch = Effect.fn("resolveEditorLaunch")(function* (
247263
return yield* new OpenError({ message: `Unknown editor: ${input.editor}` });
248264
}
249265

250-
if (editorDef.command) {
266+
if (editorDef.commands) {
267+
const command =
268+
resolveAvailableCommand(editorDef.commands, { platform, env }) ?? editorDef.commands[0];
251269
return {
252-
command: editorDef.command,
270+
command,
253271
args: resolveCommandEditorArgs(editorDef, input.cwd),
254272
};
255273
}

‎packages/contracts/src/editor.ts‎

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,25 +7,25 @@ export type EditorLaunchStyle = typeof EditorLaunchStyle.Type;
77
type EditorDefinition = {
88
readonly id: string;
99
readonly label: string;
10-
readonly command: string | null;
10+
readonly commands: readonly [string, ...string[]] | null;
1111
readonly launchStyle: EditorLaunchStyle;
1212
};
1313

1414
export const EDITORS = [
15-
{ id: "cursor", label: "Cursor", command: "cursor", launchStyle: "goto" },
16-
{ id: "trae", label: "Trae", command: "trae", launchStyle: "goto" },
17-
{ id: "vscode", label: "VS Code", command: "code", launchStyle: "goto" },
15+
{ id: "cursor", label: "Cursor", commands: ["cursor"], launchStyle: "goto" },
16+
{ id: "trae", label: "Trae", commands: ["trae"], launchStyle: "goto" },
17+
{ id: "vscode", label: "VS Code", commands: ["code"], launchStyle: "goto" },
1818
{
1919
id: "vscode-insiders",
2020
label: "VS Code Insiders",
21-
command: "code-insiders",
21+
commands: ["code-insiders"],
2222
launchStyle: "goto",
2323
},
24-
{ id: "vscodium", label: "VSCodium", command: "codium", launchStyle: "goto" },
25-
{ id: "zed", label: "Zed", command: "zed", launchStyle: "direct-path" },
26-
{ id: "antigravity", label: "Antigravity", command: "agy", launchStyle: "goto" },
27-
{ id: "idea", label: "IntelliJ IDEA", command: "idea", launchStyle: "line-column" },
28-
{ id: "file-manager", label: "File Manager", command: null, launchStyle: "direct-path" },
24+
{ id: "vscodium", label: "VSCodium", commands: ["codium"], launchStyle: "goto" },
25+
{ id: "zed", label: "Zed", commands: ["zed", "zeditor"], launchStyle: "direct-path" },
26+
{ id: "antigravity", label: "Antigravity", commands: ["agy"], launchStyle: "goto" },
27+
{ id: "idea", label: "IntelliJ IDEA", commands: ["idea"], launchStyle: "line-column" },
28+
{ id: "file-manager", label: "File Manager", commands: null, launchStyle: "direct-path" },
2929
] as const satisfies ReadonlyArray<EditorDefinition>;
3030

3131
export const EditorId = Schema.Literals(EDITORS.map((e) => e.id));

0 commit comments

Comments
 (0)