on master help sign in
Apply suggestions from code review

Co-authored-by: Gokul Soumya <gokulps15@gmail.com>

commitd5d1a9b1ae3bb7e02c86d0785e74f90358a048c6 authorBlaž Hrastnik <blaz@mxxn.io> dateMon 6 Dec 2021, 09:32 (5 years ago) parent5545f8e
1 file changed+12−33
helix-term/src/commands/dap.rs+12−33
helix-term/src/commands/dap.rs+12−33
@@ -135,29 +135,14 @@ fn thread_picker(cx: &mut Context, callback_fn: impl Fn(&mut Editor, &dap::Threa
135135 },
136136 move |cx, thread, _action| callback_fn(cx.editor, thread),
137137 move |editor, thread| {
138− let frame = editor
139− .debugger
140− .as_ref()
141− .and_then(|debugger| debugger.stack_frames.get(&thread.id))
142− .and_then(|bt| bt.get(0));
143−
144− if let Some(frame) = frame {
145− frame
146− .source
147− .as_ref()
148− .and_then(|source| source.path.clone())
149− .map(|path| {
150− (
151− path,
152− Some((
153− frame.line.saturating_sub(1),
154− frame.end_line.unwrap_or(frame.line).saturating_sub(1),
155− )),
156− )
157− })
158− } else {
159− None
160− }
138+ let frames = editor.debugger.as_ref()?.stack_frames.get(&thread.id)?;
139+ let frame = frames.get(0)?;
140+ let path = frame.source.as_ref()?.path.clone()?;
141+ let pos = Some((
142+ frame.line.saturating_sub(1),
143+ frame.end_line.unwrap_or(frame.line).saturating_sub(1),
144+ ));
145+ Some((path, pos))
161146 },
162147 );
163148 cx.push_layer(Box::new(picker))
@@ -204,13 +189,10 @@ pub fn dap_start_impl(
204189) -> Result<(), anyhow::Error> {
205190 let doc = doc!(cx.editor);
206191
207− let config = match doc
192+ let config = doc
208193 .language_config()
209194 .and_then(|config| config.debugger.as_ref())
210− {
211− Some(c) => c,
212− None => bail!("No debug adapter available for language"),
213− };
195+ .ok_or(anyhow!("No debug adapter available for language"))?;
214196
215197 let result = match socket {
216198 Some(socket) => block_on(Client::tcp(socket, 0)),
@@ -239,11 +221,8 @@ pub fn dap_start_impl(
239221 let template = match name {
240222 Some(name) => config.templates.iter().find(|t| t.name == name),
241223 None => config.templates.get(0),
242− };
243− let template = match template {
244− Some(template) => template,
245− None => bail!("No debug config with given name"),
246− };
224+ }
225+ .ok_or(anyhow!("No debug config with given name"))?;
247226
248227 let mut args: HashMap<&str, Value> = HashMap::new();
249228