aboutsummaryrefslogtreecommitdiff
path: root/helix-term/src
diff options
context:
space:
mode:
authorBlaž Hrastnik2021-12-06 00:32:11 +0000
committerGitHub2021-12-06 00:32:11 +0000
commitd5d1a9b1ae3bb7e02c86d0785e74f90358a048c6 (patch)
tree4c08d2d2248d987fa877073793ac1b4259fc6681 /helix-term/src
parent5545f8ebb5585c59981f1d09add9bd747b143ba2 (diff)
Apply suggestions from code review
Co-authored-by: Gokul Soumya <gokulps15@gmail.com>
Diffstat (limited to 'helix-term/src')
-rw-r--r--helix-term/src/commands/dap.rs45
1 files changed, 12 insertions, 33 deletions
diff --git a/helix-term/src/commands/dap.rs b/helix-term/src/commands/dap.rs
index 66c20cac..d256e5c4 100644
--- a/helix-term/src/commands/dap.rs
+++ b/helix-term/src/commands/dap.rs
@@ -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 |editor, thread| {
- let frame = editor
- .debugger
- .as_ref()
- .and_then(|debugger| debugger.stack_frames.get(&thread.id))
- .and_then(|bt| bt.get(0));
-
- if let Some(frame) = frame {
- frame
- .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
- }
+ let frames = editor.debugger.as_ref()?.stack_frames.get(&thread.id)?;
+ let frame = frames.get(0)?;
+ let path = frame.source.as_ref()?.path.clone()?;
+ let pos = Some((
+ frame.line.saturating_sub(1),
+ frame.end_line.unwrap_or(frame.line).saturating_sub(1),
+ ));
+ Some((path, pos))
},
);
cx.push_layer(Box::new(picker))
@@ -204,13 +189,10 @@ pub fn dap_start_impl(
) -> Result<(), anyhow::Error> {
let doc = doc!(cx.editor);
- let config = match doc
+ let config = doc
.language_config()
.and_then(|config| config.debugger.as_ref())
- {
- Some(c) => c,
- None => bail!("No debug adapter available for language"),
- };
+ .ok_or(anyhow!("No debug adapter available for language"))?;
let result = match socket {
Some(socket) => block_on(Client::tcp(socket, 0)),
@@ -239,11 +221,8 @@ pub fn dap_start_impl(
let template = match name {
Some(name) => config.templates.iter().find(|t| t.name == name),
None => config.templates.get(0),
- };
- let template = match template {
- Some(template) => template,
- None => bail!("No debug config with given name"),
- };
+ }
+ .ok_or(anyhow!("No debug config with given name"))?;
let mut args: HashMap<&str, Value> = HashMap::new();