on master help sign in
Apply suggestions from code review
d5d1a9bBlaž Hrastnik
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
135 },
135 },
136 move |cx, thread, _action| callback_fn(cx.editor, thread),
136 move |cx, thread, _action| callback_fn(cx.editor, thread),
137 move |editor, thread| {
137 move |editor, thread| {
138− let frame = editor
139− .debugger
140− .as_ref()
141− .and_then(|debugger| debugger.stack_frames.get(&thread.id))
138+ let frames = editor.debugger.as_ref()?.stack_frames.get(&thread.id)?;
142− .and_then(|bt| bt.get(0));
139+ let frame = frames.get(0)?;
143−
140+ let path = frame.source.as_ref()?.path.clone()?;
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((
141+ let pos = Some((
153− frame.line.saturating_sub(1),
142+ frame.line.saturating_sub(1),
154− frame.end_line.unwrap_or(frame.line).saturating_sub(1),
143+ frame.end_line.unwrap_or(frame.line).saturating_sub(1),
155− )),
144+ ));
156− )
145+ Some((path, pos))
157− })
158− } else {
159− None
160− }
161 },
146 },
162 );
147 );
163 cx.push_layer(Box::new(picker))
148 cx.push_layer(Box::new(picker))
@@ -204,13 +189,10 @@ pub fn dap_start_impl(
204) -> Result<(), anyhow::Error> {
189) -> Result<(), anyhow::Error> {
205 let doc = doc!(cx.editor);
190 let doc = doc!(cx.editor);
206
191
207− let config = match doc
192+ let config = doc
208 .language_config()
193 .language_config()
209 .and_then(|config| config.debugger.as_ref())
194 .and_then(|config| config.debugger.as_ref())
210− {
211− Some(c) => c,
212− None => bail!("No debug adapter available for language"),
195+ .ok_or(anyhow!("No debug adapter available for language"))?;
213− };
214
196
215 let result = match socket {
197 let result = match socket {
216 Some(socket) => block_on(Client::tcp(socket, 0)),
198 Some(socket) => block_on(Client::tcp(socket, 0)),
@@ -239,11 +221,8 @@ pub fn dap_start_impl(
239 let template = match name {
221 let template = match name {
240 Some(name) => config.templates.iter().find(|t| t.name == name),
222 Some(name) => config.templates.iter().find(|t| t.name == name),
241 None => config.templates.get(0),
223 None => config.templates.get(0),
242− };
224+ }
243− let template = match template {
244− Some(template) => template,
245− None => bail!("No debug config with given name"),
225+ .ok_or(anyhow!("No debug config with given name"))?;
246− };
247
226
248 let mut args: HashMap<&str, Value> = HashMap::new();
227 let mut args: HashMap<&str, Value> = HashMap::new();
249
228