From fd41309ed288ef1d348f0f0a40f43b2b95654973 Mon Sep 17 00:00:00 2001 From: xwj02155382 Date: Fri, 26 Dec 2025 16:03:05 +0800 Subject: [PATCH] refactor: share editorCommands between core and cli packages - Export editorCommands from @qwen-code/qwen-code-core - Remove duplicate editorCommands definition in useLaunchEditor - Import shared editorCommands configuration in CLI package - Reduces code duplication and ensures consistency This change makes the editor configuration a single source of truth, making it easier to maintain and add new editors in the future. --- packages/cli/src/ui/hooks/useLaunchEditor.ts | 20 +------------------- packages/core/src/utils/editor.ts | 2 +- 2 files changed, 2 insertions(+), 20 deletions(-) diff --git a/packages/cli/src/ui/hooks/useLaunchEditor.ts b/packages/cli/src/ui/hooks/useLaunchEditor.ts index d3aeb1837..f4c79e384 100644 --- a/packages/cli/src/ui/hooks/useLaunchEditor.ts +++ b/packages/cli/src/ui/hooks/useLaunchEditor.ts @@ -7,28 +7,10 @@ import { useCallback } from 'react'; import { useStdin } from 'ink'; import type { EditorType } from '@qwen-code/qwen-code-core'; +import { editorCommands } from '@qwen-code/qwen-code-core'; import { spawnSync, execSync } from 'child_process'; import { useSettings } from '../contexts/SettingsContext.js'; -/** - * Editor command configurations for different platforms. - * Each editor can have multiple possible command names, listed in order of preference. - */ -const editorCommands: Record< - EditorType, - { win32: string[]; default: string[] } -> = { - vscode: { win32: ['code.cmd'], default: ['code'] }, - vscodium: { win32: ['codium.cmd'], default: ['codium'] }, - windsurf: { win32: ['windsurf'], default: ['windsurf'] }, - cursor: { win32: ['cursor'], default: ['cursor'] }, - vim: { win32: ['vim'], default: ['vim'] }, - neovim: { win32: ['nvim'], default: ['nvim'] }, - zed: { win32: ['zed'], default: ['zed', 'zeditor'] }, - emacs: { win32: ['emacs.exe'], default: ['emacs'] }, - trae: { win32: ['trae'], default: ['trae'] }, -}; - /** * Cache for command existence checks to avoid repeated execSync calls. */ diff --git a/packages/core/src/utils/editor.ts b/packages/core/src/utils/editor.ts index b63289250..f64351ee5 100644 --- a/packages/core/src/utils/editor.ts +++ b/packages/core/src/utils/editor.ts @@ -52,7 +52,7 @@ function commandExists(cmd: string): boolean { * Editor command configurations for different platforms. * Each editor can have multiple possible command names, listed in order of preference. */ -const editorCommands: Record< +export const editorCommands: Record< EditorType, { win32: string[]; default: string[] } > = {