Add "Edit in VS Code" button to the code preview

Code/text files get a VS Code action in the preview header; a backend
open_in_vscode command resolves the depot file to its local working copy
and launches `code <path>` via the shell.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
Bonchellon
2026-07-07 15:51:06 +03:00
parent e9868c5b2e
commit 72b163f592
5 changed files with 36 additions and 2 deletions

View File

@ -610,6 +610,28 @@ async fn open_in_explorer(state: State<'_, AppState>, target: String) -> Result<
Ok(())
}
/// Open a depot file's local working copy in VS Code (`code <path>`).
/// `code` is a .cmd on Windows, so it must be launched through the shell.
#[tauri::command]
async fn open_in_vscode(state: State<'_, AppState>, depot: String) -> Result<(), String> {
let conn = current(&state)?;
let local = run_json(&conn, &["where", &depot])?
.into_iter()
.next()
.and_then(|v| v.get("path").and_then(|p| p.as_str()).map(String::from))
.ok_or_else(|| "Could not resolve the file path".to_string())?;
let mut c = Command::new("cmd");
#[cfg(windows)]
{
use std::os::windows::process::CommandExt;
c.creation_flags(0x0800_0000);
}
c.arg("/C").arg(format!("code \"{local}\""));
c.spawn()
.map_err(|e| format!("VS Code not found (is `code` in PATH?): {e}"))?;
Ok(())
}
/// Open a local file with its associated application (e.g. launch Unreal for a
/// `.uproject`). Uses the shell `start` so there are no path-scope restrictions.
#[tauri::command]
@ -771,6 +793,7 @@ pub fn run() {
open_in_explorer,
find_uproject,
launch_file,
open_in_vscode,
p4_describe,
read_file,
read_depot,