MCPcopy Create free account
hub / github.com/esengine/esengine / open_with_editor

Function open_with_editor

packages/editor-app/src-tauri/src/commands/system.rs:287–349  ·  view source on GitHub ↗
(
    project_path: String,
    editor_command: String,
    file_path: Option<String>,
)

Source from the content-addressed store, hash-verified

285/// @param file_path - Optional file to open (will be opened in the editor) | 可选的要打开的文件
286#[tauri::command]
287pub fn open_with_editor(
288 project_path: String,
289 editor_command: String,
290 file_path: Option<String>,
291) -> Result<(), String> {
292 use std::path::Path;
293
294 // Normalize paths
295 let normalized_project = project_path.replace('/', "\\");
296 let normalized_file = file_path.map(|f| f.replace('/', "\\"));
297
298 // Verify project path exists
299 let project = Path::new(&normalized_project);
300 if !project.exists() {
301 return Err(format!("Project path does not exist: {}", normalized_project));
302 }
303
304 // 解析编辑器命令到实际路径
305 // Resolve editor command to actual path
306 let resolved_command = resolve_editor_command(&editor_command);
307
308 println!(
309 "[open_with_editor] editor: {} -> {}, project: {}, file: {:?}",
310 editor_command, resolved_command, normalized_project, normalized_file
311 );
312
313 let mut cmd = Command::new(&resolved_command);
314
315 // VSCode/Cursor CLI 正确用法:
316 // 1. 使用 --folder-uri 或直接传文件夹路径会打开新窗口
317 // 2. 使用 --add 可以将文件夹添加到当前工作区
318 // 3. 使用 --goto file:line:column 可以打开文件并定位
319 //
320 // VSCode/Cursor CLI correct usage:
321 // 1. Use --folder-uri or pass folder path directly to open new window
322 // 2. Use --add to add folder to current workspace
323 // 3. Use --goto file:line:column to open file and navigate
324 //
325 // 正确命令格式: code <folder> <file>
326 // 这会打开文件夹并同时打开文件
327 // Correct command format: code <folder> <file>
328 // This opens the folder and also opens the file
329
330 // Add project folder first
331 // 先添加项目文件夹
332 cmd.arg(&normalized_project);
333
334 // If a specific file is provided, add it directly (not with -g)
335 // VSCode will open the folder AND the file
336 // 如果提供了文件,直接添加(不使用 -g)
337 // VSCode 会同时打开文件夹和文件
338 if let Some(ref file) = normalized_file {
339 let file_path_obj = Path::new(file);
340 if file_path_obj.exists() {
341 cmd.arg(file);
342 }
343 }
344

Callers

nothing calls this directly

Calls 4

resolve_editor_commandFunction · 0.85
existsMethod · 0.65
mapMethod · 0.45
spawnMethod · 0.45

Tested by

no test coverage detected