mirror of
https://github.com/QwenLM/qwen-code.git
synced 2025-12-19 09:33:53 +00:00
feat: External editor settings (#882)
This commit is contained in:
@@ -8,6 +8,10 @@ import { execSync, spawn } from 'child_process';
|
||||
|
||||
export type EditorType = 'vscode' | 'windsurf' | 'cursor' | 'vim';
|
||||
|
||||
function isValidEditorType(editor: string): editor is EditorType {
|
||||
return ['vscode', 'windsurf', 'cursor', 'vim'].includes(editor);
|
||||
}
|
||||
|
||||
interface DiffCommand {
|
||||
command: string;
|
||||
args: string[];
|
||||
@@ -32,13 +36,35 @@ const editorCommands: Record<EditorType, { win32: string; default: string }> = {
|
||||
vim: { win32: 'vim', default: 'vim' },
|
||||
};
|
||||
|
||||
export function checkHasEditor(editor: EditorType): boolean {
|
||||
export function checkHasEditorType(editor: EditorType): boolean {
|
||||
const commandConfig = editorCommands[editor];
|
||||
const command =
|
||||
process.platform === 'win32' ? commandConfig.win32 : commandConfig.default;
|
||||
return commandExists(command);
|
||||
}
|
||||
|
||||
export function allowEditorTypeInSandbox(editor: EditorType): boolean {
|
||||
const notUsingSandbox = !process.env.SANDBOX;
|
||||
if (['vscode', 'windsurf', 'cursor'].includes(editor)) {
|
||||
return notUsingSandbox;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the editor is valid and can be used.
|
||||
* Returns false if preferred editor is not set / invalid / not available / not allowed in sandbox.
|
||||
*/
|
||||
export function isEditorAvailable(editor: string | undefined): boolean {
|
||||
if (editor && isValidEditorType(editor)) {
|
||||
return (
|
||||
checkHasEditorType(editor as EditorType) &&
|
||||
allowEditorTypeInSandbox(editor as EditorType)
|
||||
);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the diff command for a specific editor.
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user