on master help sign in
dap: Simplify launch & start
6586808Blaž Hrastnik
helix-term/src/commands/dap.rs+11−26
@@ -165,19 +165,10 @@ pub fn dap_start_impl(
165 socket: Option<std::net::SocketAddr>,
165 socket: Option<std::net::SocketAddr>,
166 params: Option<Vec<&str>>,
166 params: Option<Vec<&str>>,
167) {
167) {
168− let (_, doc) = current!(editor);
168+ let doc = doc!(editor);
169
169
170− let path = match doc.path() {
170+ let config = match doc
171− Some(path) => path,
172− None => {
173− editor.set_error("Can't start debug: document has no path".to_string());
174− return;
175− }
176− };
177−
178− let language_config = editor.syn_loader.language_config_for_file_name(path);
179− let config = match language_config
171+ .language_config()
180− .as_deref()
181 .and_then(|config| config.debugger.as_ref())
172 .and_then(|config| config.debugger.as_ref())
182 {
173 {
183 Some(c) => c,
174 Some(c) => c,
@@ -283,7 +274,8 @@ pub fn dap_start_impl(
283 }
274 }
284 };
275 };
285 if let Err(e) = result {
276 if let Err(e) = result {
286− editor.set_error(format!("Failed {} target: {}", start_config.request, e));
277+ let msg = format!("Failed {} target: {}", start_config.request, e);
278+ editor.set_error(msg);
287 return;
279 return;
288 }
280 }
289
281
@@ -300,19 +292,10 @@ pub fn dap_launch(cx: &mut Context) {
300 return;
292 return;
301 }
293 }
302
294
303− let (_, doc) = current!(cx.editor);
295+ let doc = doc!(cx.editor);
304− let path = match doc.path() {
305− Some(path) => path,
306− None => {
307− cx.editor
308− .set_error("Can't start debug: document has no path".to_string());
309− return;
310− }
311− };
312
296
313− let language_config = cx.editor.syn_loader.language_config_for_file_name(path);
314− let config = match language_config
297+ let config = match doc
315− .as_deref()
298+ .language_config()
316 .and_then(|config| config.debugger.as_ref())
299 .and_then(|config| config.debugger.as_ref())
317 {
300 {
318 Some(c) => c,
301 Some(c) => c,
@@ -324,9 +307,11 @@ pub fn dap_launch(cx: &mut Context) {
324 }
307 }
325 };
308 };
326
309
310+ let templates = config.templates.clone();
311+
327 cx.push_layer(Box::new(Picker::new(
312 cx.push_layer(Box::new(Picker::new(
328 true,
313 true,
329− config.templates.clone(),
314+ templates,
330 |template| template.name.as_str().into(),
315 |template| template.name.as_str().into(),
331 |cx, template, _action| {
316 |cx, template, _action| {
332 let completions = template.completion.clone();
317 let completions = template.completion.clone();