From 1077f2771e6bfbcf9ed16dc0d18386dfbd4d4425 Mon Sep 17 00:00:00 2001 From: Anthony Eid <56899983+Anthony-Eid@users.noreply.github.com> Date: Wed, 14 May 2025 11:51:13 +0200 Subject: [PATCH] debugger: Fix launch picker program arg not using relative paths (#30680) Release Notes: - N/A --- crates/debugger_ui/src/new_session_modal.rs | 79 +++++++++++++-------- 1 file changed, 50 insertions(+), 29 deletions(-) diff --git a/crates/debugger_ui/src/new_session_modal.rs b/crates/debugger_ui/src/new_session_modal.rs index 974964d32303c69bf38ed14a637c19a715a8faac..796abe10ee143b4c3a1fe03f2a5a2742c76f8f83 100644 --- a/crates/debugger_ui/src/new_session_modal.rs +++ b/crates/debugger_ui/src/new_session_modal.rs @@ -131,6 +131,8 @@ impl NewSessionModal { this.custom_mode.update(cx, |custom, cx| { custom.load(active_cwd, window, cx); }); + + this.debugger = None; } this.launch_picker.update(cx, |picker, cx| { @@ -802,36 +804,10 @@ impl CustomMode { command }; - let program = if let Some(program) = program.strip_prefix('~') { - format!( - "$ZED_WORKTREE_ROOT{}{}", - std::path::MAIN_SEPARATOR, - &program - ) - } else if !program.starts_with(std::path::MAIN_SEPARATOR) { - format!( - "$ZED_WORKTREE_ROOT{}{}", - std::path::MAIN_SEPARATOR, - &program - ) - } else { - program - }; - - let path = if path.starts_with('~') && !path.is_empty() { - format!( - "$ZED_WORKTREE_ROOT{}{}", - std::path::MAIN_SEPARATOR, - &path[1..] - ) - } else if !path.starts_with(std::path::MAIN_SEPARATOR) && !path.is_empty() { - format!("$ZED_WORKTREE_ROOT{}{}", std::path::MAIN_SEPARATOR, &path) - } else { - path - }; - let args = args.collect::>(); + let (program, path) = resolve_paths(program, path); + task::LaunchRequest { program, cwd: path.is_empty().not().then(|| PathBuf::from(path)), @@ -1117,7 +1093,7 @@ impl PickerDelegate for DebugScenarioDelegate { .get(self.selected_index()) .and_then(|match_candidate| self.candidates.get(match_candidate.candidate_id).cloned()); - let Some((_, debug_scenario)) = debug_scenario else { + let Some((_, mut debug_scenario)) = debug_scenario else { return; }; @@ -1132,6 +1108,19 @@ impl PickerDelegate for DebugScenarioDelegate { }) .unwrap_or_default(); + if let Some(launch_config) = + debug_scenario + .request + .as_mut() + .and_then(|request| match request { + DebugRequest::Launch(launch) => Some(launch), + _ => None, + }) + { + let (program, _) = resolve_paths(launch_config.program.clone(), String::new()); + launch_config.program = program; + } + self.debug_panel .update(cx, |panel, cx| { panel.start_session(debug_scenario, task_context, None, worktree_id, window, cx); @@ -1184,3 +1173,35 @@ impl PickerDelegate for DebugScenarioDelegate { ) } } + +fn resolve_paths(program: String, path: String) -> (String, String) { + let program = if let Some(program) = program.strip_prefix('~') { + format!( + "$ZED_WORKTREE_ROOT{}{}", + std::path::MAIN_SEPARATOR, + &program + ) + } else if !program.starts_with(std::path::MAIN_SEPARATOR) { + format!( + "$ZED_WORKTREE_ROOT{}{}", + std::path::MAIN_SEPARATOR, + &program + ) + } else { + program + }; + + let path = if path.starts_with('~') && !path.is_empty() { + format!( + "$ZED_WORKTREE_ROOT{}{}", + std::path::MAIN_SEPARATOR, + &path[1..] + ) + } else if !path.starts_with(std::path::MAIN_SEPARATOR) && !path.is_empty() { + format!("$ZED_WORKTREE_ROOT{}{}", std::path::MAIN_SEPARATOR, &path) + } else { + path + }; + + (program, path) +}