on master help sign in
dap: Simplify launch & start

There's no need to re-detect language config, just use the one available on the document.

commit65868081fcc54aa4ce2ede3b95bb9800534f41f8 authorBlaž Hrastnik <blaz@mxxn.io> dateSun 7 Nov 2021, 21:26 (5 years ago) parent4f2a01c
1 file changed+11−26
helix-term/src/commands/dap.rs+11−26
helix-term/src/commands/dap.rs+11−26
@@ -165,19 +165,10 @@ pub fn dap_start_impl(
165165 socket: Option<std::net::SocketAddr>,
166166 params: Option<Vec<&str>>,
167167) {
168− let (_, doc) = current!(editor);
168+ let doc = doc!(editor);
169169
170− let path = match doc.path() {
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
180− .as_deref()
170+ let config = match doc
171+ .language_config()
181172 .and_then(|config| config.debugger.as_ref())
182173 {
183174 Some(c) => c,
@@ -283,7 +274,8 @@ pub fn dap_start_impl(
283274 }
284275 };
285276 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);
287279 return;
288280 }
289281
@@ -300,19 +292,10 @@ pub fn dap_launch(cx: &mut Context) {
300292 return;
301293 }
302294
303− let (_, doc) = current!(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− };
295+ let doc = doc!(cx.editor);
312296
313− let language_config = cx.editor.syn_loader.language_config_for_file_name(path);
314− let config = match language_config
315− .as_deref()
297+ let config = match doc
298+ .language_config()
316299 .and_then(|config| config.debugger.as_ref())
317300 {
318301 Some(c) => c,
@@ -324,9 +307,11 @@ pub fn dap_launch(cx: &mut Context) {
324307 }
325308 };
326309
310+ let templates = config.templates.clone();
311+
327312 cx.push_layer(Box::new(Picker::new(
328313 true,
329− config.templates.clone(),
314+ templates,
330315 |template| template.name.as_str().into(),
331316 |cx, template, _action| {
332317 let completions = template.completion.clone();