summaryrefslogtreecommitdiff
path: root/packages/core/src/utils/editor.ts
diff options
context:
space:
mode:
authorScott Densmore <[email protected]>2025-06-23 23:32:09 -0700
committerGitHub <[email protected]>2025-06-23 23:32:09 -0700
commit324715ee8bb6a7c7277692f2e08fc46f750b5181 (patch)
tree7240a85c50a3819e1837b7b1fa1abf8e153b11ab /packages/core/src/utils/editor.ts
parent9f5a625730893042982a85364aa1360263016425 (diff)
Add Zed Editor to Eidtor List (#1372)
Diffstat (limited to 'packages/core/src/utils/editor.ts')
-rw-r--r--packages/core/src/utils/editor.ts89
1 files changed, 48 insertions, 41 deletions
diff --git a/packages/core/src/utils/editor.ts b/packages/core/src/utils/editor.ts
index 15c970d0..e7a87ac1 100644
--- a/packages/core/src/utils/editor.ts
+++ b/packages/core/src/utils/editor.ts
@@ -6,10 +6,10 @@
import { execSync, spawn } from 'child_process';
-export type EditorType = 'vscode' | 'windsurf' | 'cursor' | 'vim';
+export type EditorType = 'vscode' | 'windsurf' | 'cursor' | 'vim' | 'zed';
function isValidEditorType(editor: string): editor is EditorType {
- return ['vscode', 'windsurf', 'cursor', 'vim'].includes(editor);
+ return ['vscode', 'windsurf', 'cursor', 'vim', 'zed'].includes(editor);
}
interface DiffCommand {
@@ -34,6 +34,7 @@ const editorCommands: Record<EditorType, { win32: string; default: string }> = {
windsurf: { win32: 'windsurf', default: 'windsurf' },
cursor: { win32: 'cursor', default: 'cursor' },
vim: { win32: 'vim', default: 'vim' },
+ zed: { win32: 'zed', default: 'zed' },
};
export function checkHasEditorType(editor: EditorType): boolean {
@@ -45,7 +46,7 @@ export function checkHasEditorType(editor: EditorType): boolean {
export function allowEditorTypeInSandbox(editor: EditorType): boolean {
const notUsingSandbox = !process.env.SANDBOX;
- if (['vscode', 'windsurf', 'cursor'].includes(editor)) {
+ if (['vscode', 'windsurf', 'cursor', 'zed'].includes(editor)) {
return notUsingSandbox;
}
return true;
@@ -73,22 +74,18 @@ export function getDiffCommand(
newPath: string,
editor: EditorType,
): DiffCommand | null {
+ if (!isValidEditorType(editor)) {
+ return null;
+ }
+ const commandConfig = editorCommands[editor];
+ const command =
+ process.platform === 'win32' ? commandConfig.win32 : commandConfig.default;
switch (editor) {
case 'vscode':
- return {
- command: 'code',
- args: ['--wait', '--diff', oldPath, newPath],
- };
case 'windsurf':
- return {
- command: 'windsurf',
- args: ['--wait', '--diff', oldPath, newPath],
- };
case 'cursor':
- return {
- command: 'cursor',
- args: ['--wait', '--diff', oldPath, newPath],
- };
+ case 'zed':
+ return { command, args: ['--wait', '--diff', oldPath, newPath] };
case 'vim':
return {
command: 'vim',
@@ -134,40 +131,50 @@ export async function openDiff(
): Promise<void> {
const diffCommand = getDiffCommand(oldPath, newPath, editor);
if (!diffCommand) {
- console.error('No diff tool available. Install vim or vscode.');
+ console.error('No diff tool available. Install a supported editor.');
return;
}
try {
- if (editor === 'vscode') {
- // Use spawn to avoid blocking the entire process, resolve this function when editor is closed.
- return new Promise((resolve, reject) => {
- const process = spawn(diffCommand.command, diffCommand.args, {
- stdio: 'inherit',
- });
+ switch (editor) {
+ case 'vscode':
+ case 'windsurf':
+ case 'cursor':
+ case 'zed':
+ // Use spawn for GUI-based editors to avoid blocking the entire process
+ return new Promise((resolve, reject) => {
+ const childProcess = spawn(diffCommand.command, diffCommand.args, {
+ stdio: 'inherit',
+ });
- process.on('close', (code) => {
- if (code === 0) {
- resolve();
- } else {
- reject(new Error(`VS Code exited with code ${code}`));
- }
+ childProcess.on('close', (code) => {
+ if (code === 0) {
+ resolve();
+ } else {
+ reject(new Error(`${editor} exited with code ${code}`));
+ }
+ });
+
+ childProcess.on('error', (error) => {
+ reject(error);
+ });
});
- process.on('error', (error) => {
- reject(error);
+ case 'vim': {
+ // Use execSync for terminal-based editors
+ const command =
+ process.platform === 'win32'
+ ? `${diffCommand.command} ${diffCommand.args.join(' ')}`
+ : `${diffCommand.command} ${diffCommand.args.map((arg) => `"${arg}"`).join(' ')}`;
+ execSync(command, {
+ stdio: 'inherit',
+ encoding: 'utf8',
});
- });
- } else {
- // Use execSync for terminal-based editors like vim
- const command =
- process.platform === 'win32'
- ? `${diffCommand.command} ${diffCommand.args.join(' ')}`
- : `${diffCommand.command} ${diffCommand.args.map((arg) => `"${arg}"`).join(' ')}`;
- execSync(command, {
- stdio: 'inherit',
- encoding: 'utf8',
- });
+ break;
+ }
+
+ default:
+ throw new Error(`Unsupported editor: ${editor}`);
}
} catch (error) {
console.error(error);