summaryrefslogtreecommitdiff
path: root/packages/core/src/utils
diff options
context:
space:
mode:
Diffstat (limited to 'packages/core/src/utils')
-rw-r--r--packages/core/src/utils/editor.test.ts32
-rw-r--r--packages/core/src/utils/editor.ts31
2 files changed, 53 insertions, 10 deletions
diff --git a/packages/core/src/utils/editor.test.ts b/packages/core/src/utils/editor.test.ts
index 20917c0f..e7c2f55a 100644
--- a/packages/core/src/utils/editor.test.ts
+++ b/packages/core/src/utils/editor.test.ts
@@ -35,6 +35,36 @@ describe('checkHasEditor', () => {
expect(checkHasEditor('vscode')).toBe(false);
});
+ it('should return true for windsurf if "windsurf" command exists', () => {
+ (execSync as Mock).mockReturnValue(Buffer.from('/usr/bin/windsurf'));
+ expect(checkHasEditor('windsurf')).toBe(true);
+ expect(execSync).toHaveBeenCalledWith('command -v windsurf', {
+ stdio: 'ignore',
+ });
+ });
+
+ it('should return false for windsurf if "windsurf" command does not exist', () => {
+ (execSync as Mock).mockImplementation(() => {
+ throw new Error();
+ });
+ expect(checkHasEditor('windsurf')).toBe(false);
+ });
+
+ it('should return true for cursor if "cursor" command exists', () => {
+ (execSync as Mock).mockReturnValue(Buffer.from('/usr/bin/cursor'));
+ expect(checkHasEditor('cursor')).toBe(true);
+ expect(execSync).toHaveBeenCalledWith('command -v cursor', {
+ stdio: 'ignore',
+ });
+ });
+
+ it('should return false for cursor if "cursor" command does not exist', () => {
+ (execSync as Mock).mockImplementation(() => {
+ throw new Error();
+ });
+ expect(checkHasEditor('cursor')).toBe(false);
+ });
+
it('should return true for vim if "vim" command exists', () => {
(execSync as Mock).mockReturnValue(Buffer.from('/usr/bin/vim'));
expect(checkHasEditor('vim')).toBe(true);
@@ -71,7 +101,7 @@ describe('getDiffCommand', () => {
it('should return null for an unsupported editor', () => {
// @ts-expect-error Testing unsupported editor
- const command = getDiffCommand('old.txt', 'new.txt', 'nano');
+ const command = getDiffCommand('old.txt', 'new.txt', 'foobar');
expect(command).toBeNull();
});
});
diff --git a/packages/core/src/utils/editor.ts b/packages/core/src/utils/editor.ts
index 6be5cffb..4d09e3a9 100644
--- a/packages/core/src/utils/editor.ts
+++ b/packages/core/src/utils/editor.ts
@@ -6,7 +6,7 @@
import { execSync, spawn } from 'child_process';
-type EditorType = 'vscode' | 'vim';
+export type EditorType = 'vscode' | 'windsurf' | 'cursor' | 'vim';
interface DiffCommand {
command: string;
@@ -25,15 +25,18 @@ function commandExists(cmd: string): boolean {
}
}
+const editorCommands: Record<EditorType, { win32: string; default: string }> = {
+ vscode: { win32: 'code.cmd', default: 'code' },
+ windsurf: { win32: 'windsurf', default: 'windsurf' },
+ cursor: { win32: 'cursor', default: 'cursor' },
+ vim: { win32: 'vim', default: 'vim' },
+};
+
export function checkHasEditor(editor: EditorType): boolean {
- if (editor === 'vscode') {
- return process.platform === 'win32'
- ? commandExists('code.cmd')
- : commandExists('code');
- } else if (editor === 'vim') {
- return commandExists('vim');
- }
- return false;
+ const commandConfig = editorCommands[editor];
+ const command =
+ process.platform === 'win32' ? commandConfig.win32 : commandConfig.default;
+ return commandExists(command);
}
/**
@@ -50,6 +53,16 @@ export function getDiffCommand(
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 'vim':
return {
command: 'vim',