Apply suggestions from code review

Co-authored-by: Gokul Soumya <gokulps15@gmail.com>
pull/574/head
Blaž Hrastnik 3 years ago committed by GitHub
parent 5545f8ebb5
commit d5d1a9b1ae
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -135,29 +135,14 @@ fn thread_picker(cx: &mut Context, callback_fn: impl Fn(&mut Editor, &dap::Threa
}, },
move |cx, thread, _action| callback_fn(cx.editor, thread), move |cx, thread, _action| callback_fn(cx.editor, thread),
move |editor, thread| { move |editor, thread| {
let frame = editor let frames = editor.debugger.as_ref()?.stack_frames.get(&thread.id)?;
.debugger let frame = frames.get(0)?;
.as_ref() let path = frame.source.as_ref()?.path.clone()?;
.and_then(|debugger| debugger.stack_frames.get(&thread.id)) let pos = Some((
.and_then(|bt| bt.get(0)); frame.line.saturating_sub(1),
frame.end_line.unwrap_or(frame.line).saturating_sub(1),
if let Some(frame) = frame { ));
frame Some((path, pos))
.source
.as_ref()
.and_then(|source| source.path.clone())
.map(|path| {
(
path,
Some((
frame.line.saturating_sub(1),
frame.end_line.unwrap_or(frame.line).saturating_sub(1),
)),
)
})
} else {
None
}
}, },
); );
cx.push_layer(Box::new(picker)) cx.push_layer(Box::new(picker))
@ -204,13 +189,10 @@ pub fn dap_start_impl(
) -> Result<(), anyhow::Error> { ) -> Result<(), anyhow::Error> {
let doc = doc!(cx.editor); let doc = doc!(cx.editor);
let config = match doc let config = doc
.language_config() .language_config()
.and_then(|config| config.debugger.as_ref()) .and_then(|config| config.debugger.as_ref())
{ .ok_or(anyhow!("No debug adapter available for language"))?;
Some(c) => c,
None => bail!("No debug adapter available for language"),
};
let result = match socket { let result = match socket {
Some(socket) => block_on(Client::tcp(socket, 0)), Some(socket) => block_on(Client::tcp(socket, 0)),
@ -239,11 +221,8 @@ pub fn dap_start_impl(
let template = match name { let template = match name {
Some(name) => config.templates.iter().find(|t| t.name == name), Some(name) => config.templates.iter().find(|t| t.name == name),
None => config.templates.get(0), None => config.templates.get(0),
}; }
let template = match template { .ok_or(anyhow!("No debug config with given name"))?;
Some(template) => template,
None => bail!("No debug config with given name"),
};
let mut args: HashMap<&str, Value> = HashMap::new(); let mut args: HashMap<&str, Value> = HashMap::new();

Loading…
Cancel
Save