Open History to see the last commit
1import * as Schema from "effect/Schema";
2import { TrimmedNonEmptyString } from "./baseSchemas.ts";
3
4export const EditorLaunchStyle = Schema.Literals(["direct-path", "goto", "line-column"]);
5export type EditorLaunchStyle = typeof EditorLaunchStyle.Type;
6
7type EditorDefinition = {
8 readonly id: string;
9 readonly label: string;
10 readonly commands: readonly [string, ...string[]] | null;
11 readonly baseArgs?: readonly string[];
12 readonly launchStyle: EditorLaunchStyle;
13};
14
15export const EDITORS = [
16 { id: "cursor", label: "Cursor", commands: ["cursor"], launchStyle: "goto" },
17 { id: "trae", label: "Trae", commands: ["trae"], launchStyle: "goto" },
18 { id: "kiro", label: "Kiro", commands: ["kiro"], baseArgs: ["ide"], launchStyle: "goto" },
19 { id: "vscode", label: "VS Code", commands: ["code"], launchStyle: "goto" },
20 {
21 id: "vscode-insiders",
22 label: "VS Code Insiders",
23 commands: ["code-insiders"],
24 launchStyle: "goto",
25 },
26 { id: "vscodium", label: "VSCodium", commands: ["codium"], launchStyle: "goto" },
27 { id: "zed", label: "Zed", commands: ["zed", "zeditor"], launchStyle: "direct-path" },
28 { id: "antigravity", label: "Antigravity", commands: ["agy"], launchStyle: "goto" },
29 { id: "idea", label: "IntelliJ IDEA", commands: ["idea"], launchStyle: "line-column" },
30 { id: "aqua", label: "Aqua", commands: ["aqua"], launchStyle: "line-column" },
31 { id: "clion", label: "CLion", commands: ["clion"], launchStyle: "line-column" },
32 { id: "datagrip", label: "DataGrip", commands: ["datagrip"], launchStyle: "line-column" },
33 { id: "dataspell", label: "DataSpell", commands: ["dataspell"], launchStyle: "line-column" },
34 { id: "goland", label: "GoLand", commands: ["goland"], launchStyle: "line-column" },
35 { id: "phpstorm", label: "PhpStorm", commands: ["phpstorm"], launchStyle: "line-column" },
36 { id: "pycharm", label: "PyCharm", commands: ["pycharm"], launchStyle: "line-column" },
37 { id: "rider", label: "Rider", commands: ["rider"], launchStyle: "line-column" },
38 { id: "rubymine", label: "RubyMine", commands: ["rubymine"], launchStyle: "line-column" },
39 { id: "rustrover", label: "RustRover", commands: ["rustrover"], launchStyle: "line-column" },
40 { id: "webstorm", label: "WebStorm", commands: ["webstorm"], launchStyle: "line-column" },
41 { id: "file-manager", label: "File Manager", commands: null, launchStyle: "direct-path" },
42] as const satisfies ReadonlyArray<EditorDefinition>;
43
44export const EditorId = Schema.Literals(EDITORS.map((e) => e.id));
45export type EditorId = typeof EditorId.Type;
46
47export const LaunchEditorInput = Schema.Struct({
48 cwd: TrimmedNonEmptyString,
49 editor: EditorId,
50});
51export type LaunchEditorInput = typeof LaunchEditorInput.Type;
52
53export class ExternalLauncherUnknownEditorError extends Schema.TaggedErrorClass<ExternalLauncherUnknownEditorError>()(
54 "ExternalLauncherUnknownEditorError",
55 {
56 editor: Schema.String,
57 },
58) {
59 override get message(): string {
60 return `Unknown editor: ${this.editor}`;
61 }
62}
63
64export class ExternalLauncherUnsupportedEditorError extends Schema.TaggedErrorClass<ExternalLauncherUnsupportedEditorError>()(
65 "ExternalLauncherUnsupportedEditorError",
66 {
67 editor: EditorId,
68 },
69) {
70 override get message(): string {
71 return `Unsupported editor: ${this.editor}`;
72 }
73}
74
75export class ExternalLauncherCommandNotFoundError extends Schema.TaggedErrorClass<ExternalLauncherCommandNotFoundError>()(
76 "ExternalLauncherCommandNotFoundError",
77 {
78 editor: EditorId,
79 command: Schema.String,
80 },
81) {
82 override get message(): string {
83 return `Editor command not found: ${this.command}`;
84 }
85}
86
87const ExternalLauncherSpawnFields = {
88 command: Schema.String,
89 args: Schema.Array(Schema.String),
90 cause: Schema.Defect(),
91};
92
93export class ExternalLauncherBrowserSpawnError extends Schema.TaggedErrorClass<ExternalLauncherBrowserSpawnError>()(
94 "ExternalLauncherBrowserSpawnError",
95 {
96 ...ExternalLauncherSpawnFields,
97 target: Schema.String,
98 },
99) {
100 override get message(): string {
101 return `Failed to launch browser target '${this.target}' with '${[this.command, ...this.args].join(" ")}'`;
102 }
103}
104
105export class ExternalLauncherEditorSpawnError extends Schema.TaggedErrorClass<ExternalLauncherEditorSpawnError>()(
106 "ExternalLauncherEditorSpawnError",
107 {
108 ...ExternalLauncherSpawnFields,
109 editor: EditorId,
110 target: Schema.String,
111 },
112) {
113 override get message(): string {
114 return `Failed to launch '${this.target}' in ${this.editor} with '${[this.command, ...this.args].join(" ")}'`;
115 }
116}
117
118export const ExternalLauncherError = Schema.Union([
119 ExternalLauncherUnknownEditorError,
120 ExternalLauncherUnsupportedEditorError,
121 ExternalLauncherCommandNotFoundError,
122 ExternalLauncherBrowserSpawnError,
123 ExternalLauncherEditorSpawnError,
124]);
125export type ExternalLauncherError = typeof ExternalLauncherError.Type;
126
127export const isExternalLauncherError = Schema.is(ExternalLauncherError);