|
1 | 1 | use anyhow::{Result, anyhow};
|
2 | 2 | use async_trait::async_trait;
|
3 |
| -use dap::{DapLocator, DebugRequest}; |
| 3 | +use dap::{DapLocator, DebugRequest, adapters::DebugAdapterName}; |
4 | 4 | use gpui::SharedString;
|
5 | 5 | use serde_json::Value;
|
6 | 6 | use smol::{
|
@@ -41,7 +41,12 @@ impl DapLocator for CargoLocator {
|
41 | 41 | fn name(&self) -> SharedString {
|
42 | 42 | SharedString::new_static("rust-cargo-locator")
|
43 | 43 | }
|
44 |
| - fn create_scenario(&self, build_config: &TaskTemplate, adapter: &str) -> Option<DebugScenario> { |
| 44 | + fn create_scenario( |
| 45 | + &self, |
| 46 | + build_config: &TaskTemplate, |
| 47 | + resolved_label: &str, |
| 48 | + adapter: DebugAdapterName, |
| 49 | + ) -> Option<DebugScenario> { |
45 | 50 | if build_config.command != "cargo" {
|
46 | 51 | return None;
|
47 | 52 | }
|
@@ -70,9 +75,9 @@ impl DapLocator for CargoLocator {
|
70 | 75 | }
|
71 | 76 | _ => {}
|
72 | 77 | }
|
73 |
| - let label = format!("Debug `{}`", build_config.label); |
| 78 | + let label = format!("Debug `{resolved_label}`"); |
74 | 79 | Some(DebugScenario {
|
75 |
| - adapter: adapter.to_owned().into(), |
| 80 | + adapter: adapter.0, |
76 | 81 | label: SharedString::from(label),
|
77 | 82 | build: Some(BuildTaskDefinition::Template {
|
78 | 83 | task_template,
|
@@ -136,20 +141,20 @@ impl DapLocator for CargoLocator {
|
136 | 141 |
|
137 | 142 | let mut test_name = None;
|
138 | 143 | if is_test {
|
139 |
| - if let Some(package_index) = build_config |
| 144 | + test_name = build_config |
140 | 145 | .args
|
141 | 146 | .iter()
|
142 |
| - .position(|arg| arg == "-p" || arg == "--package") |
143 |
| - { |
144 |
| - test_name = build_config |
145 |
| - .args |
146 |
| - .get(package_index + 2) |
147 |
| - .filter(|name| !name.starts_with("--")) |
148 |
| - .cloned(); |
149 |
| - } |
| 147 | + .rev() |
| 148 | + .take_while(|name| "--" != name.as_str()) |
| 149 | + .find(|name| !name.starts_with("-")) |
| 150 | + .cloned(); |
150 | 151 | }
|
151 | 152 | let executable = {
|
152 |
| - if let Some(ref name) = test_name { |
| 153 | + if let Some(ref name) = test_name.as_ref().and_then(|name| { |
| 154 | + name.strip_prefix('$') |
| 155 | + .map(|name| build_config.env.get(name)) |
| 156 | + .unwrap_or(Some(name)) |
| 157 | + }) { |
153 | 158 | find_best_executable(&executables, &name).await
|
154 | 159 | } else {
|
155 | 160 | None
|
|
0 commit comments