dap: Simplify launch & start

There's no need to re-detect language config, just use the one available
on the document.
imgbot
Blaž Hrastnik 3 years ago
parent 4f2a01cc09
commit 65868081fc

@ -165,19 +165,10 @@ pub fn dap_start_impl(
socket: Option<std::net::SocketAddr>, socket: Option<std::net::SocketAddr>,
params: Option<Vec<&str>>, params: Option<Vec<&str>>,
) { ) {
let (_, doc) = current!(editor); let doc = doc!(editor);
let path = match doc.path() { let config = match doc
Some(path) => path, .language_config()
None => {
editor.set_error("Can't start debug: document has no path".to_string());
return;
}
};
let language_config = editor.syn_loader.language_config_for_file_name(path);
let config = match language_config
.as_deref()
.and_then(|config| config.debugger.as_ref()) .and_then(|config| config.debugger.as_ref())
{ {
Some(c) => c, Some(c) => c,
@ -283,7 +274,8 @@ pub fn dap_start_impl(
} }
}; };
if let Err(e) = result { if let Err(e) = result {
editor.set_error(format!("Failed {} target: {}", start_config.request, e)); let msg = format!("Failed {} target: {}", start_config.request, e);
editor.set_error(msg);
return; return;
} }
@ -300,19 +292,10 @@ pub fn dap_launch(cx: &mut Context) {
return; return;
} }
let (_, doc) = current!(cx.editor); let doc = doc!(cx.editor);
let path = match doc.path() {
Some(path) => path,
None => {
cx.editor
.set_error("Can't start debug: document has no path".to_string());
return;
}
};
let language_config = cx.editor.syn_loader.language_config_for_file_name(path); let config = match doc
let config = match language_config .language_config()
.as_deref()
.and_then(|config| config.debugger.as_ref()) .and_then(|config| config.debugger.as_ref())
{ {
Some(c) => c, Some(c) => c,
@ -324,9 +307,11 @@ pub fn dap_launch(cx: &mut Context) {
} }
}; };
let templates = config.templates.clone();
cx.push_layer(Box::new(Picker::new( cx.push_layer(Box::new(Picker::new(
true, true,
config.templates.clone(), templates,
|template| template.name.as_str().into(), |template| template.name.as_str().into(),
|cx, template, _action| { |cx, template, _action| {
let completions = template.completion.clone(); let completions = template.completion.clone();

Loading…
Cancel
Save