aboutsummaryrefslogtreecommitdiff
path: root/helix-term/src/commands/dap.rs
diff options
context:
space:
mode:
authorMichael Davis2023-06-18 17:23:15 +0000
committerMichael Davis2023-06-18 17:28:16 +0000
commit545acfda8884c890b78e586c86e4f7c5f9a15477 (patch)
treea2ff7204be3cda93bd558aedc0022b2b99e6e707 /helix-term/src/commands/dap.rs
parentfc111213b5b5a3130399cda8a1964fa89acf153a (diff)
Make file preview callback optional
When Picker and FilePicker are merged, not all Pickers will be able to show a preview. Co-authored-by: Gokul Soumya <gokulps15@gmail.com>
Diffstat (limited to 'helix-term/src/commands/dap.rs')
-rw-r--r--helix-term/src/commands/dap.rs92
1 files changed, 43 insertions, 49 deletions
diff --git a/helix-term/src/commands/dap.rs b/helix-term/src/commands/dap.rs
index 84794bed..2684e946 100644
--- a/helix-term/src/commands/dap.rs
+++ b/helix-term/src/commands/dap.rs
@@ -73,21 +73,19 @@ fn thread_picker(
let debugger = debugger!(editor);
let thread_states = debugger.thread_states.clone();
- let picker = FilePicker::new(
- threads,
- thread_states,
- move |cx, thread, _action| callback_fn(cx.editor, thread),
- move |editor, thread| {
- 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.into(), pos))
- },
- );
+ let picker = FilePicker::new(threads, thread_states, move |cx, thread, _action| {
+ callback_fn(cx.editor, thread)
+ })
+ .with_preview(move |editor, thread| {
+ 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.into(), pos))
+ });
compositor.push(Box::new(picker));
},
);
@@ -728,39 +726,35 @@ pub fn dap_switch_stack_frame(cx: &mut Context) {
let frames = debugger.stack_frames[&thread_id].clone();
- let picker = FilePicker::new(
- frames,
- (),
- move |cx, frame, _action| {
- let debugger = debugger!(cx.editor);
- // TODO: this should be simpler to find
- let pos = debugger.stack_frames[&thread_id]
- .iter()
- .position(|f| f.id == frame.id);
- debugger.active_frame = pos;
-
- let frame = debugger.stack_frames[&thread_id]
- .get(pos.unwrap_or(0))
- .cloned();
- if let Some(frame) = &frame {
- jump_to_stack_frame(cx.editor, frame);
- }
- },
- move |_editor, frame| {
- frame
- .source
- .as_ref()
- .and_then(|source| source.path.clone())
- .map(|path| {
- (
- path.into(),
- Some((
- frame.line.saturating_sub(1),
- frame.end_line.unwrap_or(frame.line).saturating_sub(1),
- )),
- )
- })
- },
- );
+ let picker = FilePicker::new(frames, (), move |cx, frame, _action| {
+ let debugger = debugger!(cx.editor);
+ // TODO: this should be simpler to find
+ let pos = debugger.stack_frames[&thread_id]
+ .iter()
+ .position(|f| f.id == frame.id);
+ debugger.active_frame = pos;
+
+ let frame = debugger.stack_frames[&thread_id]
+ .get(pos.unwrap_or(0))
+ .cloned();
+ if let Some(frame) = &frame {
+ jump_to_stack_frame(cx.editor, frame);
+ }
+ })
+ .with_preview(move |_editor, frame| {
+ frame
+ .source
+ .as_ref()
+ .and_then(|source| source.path.clone())
+ .map(|path| {
+ (
+ path.into(),
+ Some((
+ frame.line.saturating_sub(1),
+ frame.end_line.unwrap_or(frame.line).saturating_sub(1),
+ )),
+ )
+ })
+ });
cx.push_layer(Box::new(picker))
}