aboutsummaryrefslogtreecommitdiff
path: root/helix-term/src/commands
diff options
context:
space:
mode:
authorPascal Kuthe2023-06-19 02:18:42 +0000
committerGitHub2023-06-19 02:18:42 +0000
commit06d63d6ac1644ce57d6a90b53ea4f832e67ab2a9 (patch)
treeaf461a6c93f76be80370655c8bcc9fa2d2c0ecc5 /helix-term/src/commands
parent29638babea410d6d8397b02e6a826de0076a69c0 (diff)
parentf18acadbd0d7b15bc314fc3ede99f4546b72d76d (diff)
Merge pull request #7264 from the-mikedavis/merge-picker-and-filepicker
Merge FilePicker into Picker
Diffstat (limited to 'helix-term/src/commands')
-rw-r--r--helix-term/src/commands/dap.rs94
-rw-r--r--helix-term/src/commands/lsp.rs90
2 files changed, 85 insertions, 99 deletions
diff --git a/helix-term/src/commands/dap.rs b/helix-term/src/commands/dap.rs
index 84794bed..70a5ec21 100644
--- a/helix-term/src/commands/dap.rs
+++ b/helix-term/src/commands/dap.rs
@@ -2,7 +2,7 @@ use super::{Context, Editor};
use crate::{
compositor::{self, Compositor},
job::{Callback, Jobs},
- ui::{self, overlay::overlaid, FilePicker, Picker, Popup, Prompt, PromptEvent, Text},
+ ui::{self, overlay::overlaid, Picker, Popup, Prompt, PromptEvent, Text},
};
use dap::{StackFrame, Thread, ThreadStates};
use helix_core::syntax::{DebugArgumentValue, DebugConfigCompletion, DebugTemplate};
@@ -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 = Picker::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 = Picker::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))
}
diff --git a/helix-term/src/commands/lsp.rs b/helix-term/src/commands/lsp.rs
index 8c3fd13b..55153648 100644
--- a/helix-term/src/commands/lsp.rs
+++ b/helix-term/src/commands/lsp.rs
@@ -31,8 +31,8 @@ use crate::{
compositor::{self, Compositor},
job::Callback,
ui::{
- self, lsp::SignatureHelp, overlay::overlaid, DynamicPicker, FileLocation, FilePicker,
- Popup, PromptEvent,
+ self, lsp::SignatureHelp, overlay::overlaid, DynamicPicker, FileLocation, Picker, Popup,
+ PromptEvent,
},
};
@@ -236,48 +236,44 @@ fn jump_to_location(
align_view(doc, view, Align::Center);
}
-type SymbolPicker = FilePicker<SymbolInformationItem>;
+type SymbolPicker = Picker<SymbolInformationItem>;
fn sym_picker(symbols: Vec<SymbolInformationItem>, current_path: Option<lsp::Url>) -> SymbolPicker {
// TODO: drop current_path comparison and instead use workspace: bool flag?
- FilePicker::new(
- symbols,
- current_path.clone(),
- move |cx, item, action| {
- let (view, doc) = current!(cx.editor);
- push_jump(view, doc);
-
- if current_path.as_ref() != Some(&item.symbol.location.uri) {
- let uri = &item.symbol.location.uri;
- let path = match uri.to_file_path() {
- Ok(path) => path,
- Err(_) => {
- let err = format!("unable to convert URI to filepath: {}", uri);
- cx.editor.set_error(err);
- return;
- }
- };
- if let Err(err) = cx.editor.open(&path, action) {
- let err = format!("failed to open document: {}: {}", uri, err);
- log::error!("{}", err);
+ Picker::new(symbols, current_path.clone(), move |cx, item, action| {
+ let (view, doc) = current!(cx.editor);
+ push_jump(view, doc);
+
+ if current_path.as_ref() != Some(&item.symbol.location.uri) {
+ let uri = &item.symbol.location.uri;
+ let path = match uri.to_file_path() {
+ Ok(path) => path,
+ Err(_) => {
+ let err = format!("unable to convert URI to filepath: {}", uri);
cx.editor.set_error(err);
return;
}
+ };
+ if let Err(err) = cx.editor.open(&path, action) {
+ let err = format!("failed to open document: {}: {}", uri, err);
+ log::error!("{}", err);
+ cx.editor.set_error(err);
+ return;
}
+ }
- let (view, doc) = current!(cx.editor);
+ let (view, doc) = current!(cx.editor);
- if let Some(range) =
- lsp_range_to_range(doc.text(), item.symbol.location.range, item.offset_encoding)
- {
- // we flip the range so that the cursor sits on the start of the symbol
- // (for example start of the function).
- doc.set_selection(view.id, Selection::single(range.head, range.anchor));
- align_view(doc, view, Align::Center);
- }
- },
- move |_editor, item| Some(location_to_file_location(&item.symbol.location)),
- )
+ if let Some(range) =
+ lsp_range_to_range(doc.text(), item.symbol.location.range, item.offset_encoding)
+ {
+ // we flip the range so that the cursor sits on the start of the symbol
+ // (for example start of the function).
+ doc.set_selection(view.id, Selection::single(range.head, range.anchor));
+ align_view(doc, view, Align::Center);
+ }
+ })
+ .with_preview(move |_editor, item| Some(location_to_file_location(&item.symbol.location)))
.truncate_start(false)
}
@@ -292,7 +288,7 @@ fn diag_picker(
diagnostics: BTreeMap<lsp::Url, Vec<(lsp::Diagnostic, usize)>>,
current_path: Option<lsp::Url>,
format: DiagnosticsFormat,
-) -> FilePicker<PickerDiagnostic> {
+) -> Picker<PickerDiagnostic> {
// TODO: drop current_path comparison and instead use workspace: bool flag?
// flatten the map to a vec of (url, diag) pairs
@@ -318,7 +314,7 @@ fn diag_picker(
error: cx.editor.theme.get("error"),
};
- FilePicker::new(
+ Picker::new(
flat_diag,
(styles, format),
move |cx,
@@ -345,11 +341,11 @@ fn diag_picker(
align_view(doc, view, Align::Center);
}
},
- move |_editor, PickerDiagnostic { url, diag, .. }| {
- let location = lsp::Location::new(url.clone(), diag.range);
- Some(location_to_file_location(&location))
- },
)
+ .with_preview(move |_editor, PickerDiagnostic { url, diag, .. }| {
+ let location = lsp::Location::new(url.clone(), diag.range);
+ Some(location_to_file_location(&location))
+ })
.truncate_start(false)
}
@@ -1047,14 +1043,10 @@ fn goto_impl(
editor.set_error("No definition found.");
}
_locations => {
- let picker = FilePicker::new(
- locations,
- cwdir,
- move |cx, location, action| {
- jump_to_location(cx.editor, location, offset_encoding, action)
- },
- move |_editor, location| Some(location_to_file_location(location)),
- );
+ let picker = Picker::new(locations, cwdir, move |cx, location, action| {
+ jump_to_location(cx.editor, location, offset_encoding, action)
+ })
+ .with_preview(move |_editor, location| Some(location_to_file_location(location)));
compositor.push(Box::new(overlaid(picker)));
}
}