Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: Merge Picker and FilePicker #5801

Closed
10 changes: 5 additions & 5 deletions helix-term/src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ use crate::{
filter_picker_entry,
job::Callback,
keymap::ReverseKeymap,
ui::{self, overlay::overlayed, FilePicker, Picker, Popup, Prompt, PromptEvent},
ui::{self, overlay::overlayed, Picker, Popup, Prompt, PromptEvent},
};

use crate::job::{self, Jobs};
Expand Down Expand Up @@ -2090,7 +2090,7 @@ fn global_search(cx: &mut Context) {
return;
}

let picker = FilePicker::new(
let picker = Picker::with_preview(
all_matches,
current_path,
move |cx, FileResult { path, line_num }, action| {
Expand Down Expand Up @@ -2466,7 +2466,7 @@ fn buffer_picker(cx: &mut Context) {
is_current: doc.id() == current,
};

let picker = FilePicker::new(
let picker = Picker::with_preview(
cx.editor
.documents
.values()
Expand Down Expand Up @@ -2544,7 +2544,7 @@ fn jumplist_picker(cx: &mut Context) {
}
};

let picker = FilePicker::new(
let picker = Picker::with_preview(
cx.editor
.tree
.views()
Expand Down Expand Up @@ -2616,7 +2616,7 @@ pub fn command_palette(cx: &mut Context) {
}
}));

let picker = Picker::new(commands, keymap, move |cx, command, _action| {
let picker = Picker::without_preview(commands, keymap, move |cx, command, _action| {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd still name this new() we could also make the with_preview() a builder function that takes `self‘ so you'd chain these: new(..).with_preview(..)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I think beside this, everything else looks okay.

let mut ctx = Context {
register: None,
count: std::num::NonZeroUsize::new(1),
Expand Down
8 changes: 4 additions & 4 deletions helix-term/src/commands/dap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use super::{Context, Editor};
use crate::{
compositor::{self, Compositor},
job::{Callback, Jobs},
ui::{self, overlay::overlayed, FilePicker, Picker, Popup, Prompt, PromptEvent, Text},
ui::{self, overlay::overlayed, Picker, Popup, Prompt, PromptEvent, Text},
};
use dap::{StackFrame, Thread, ThreadStates};
use helix_core::syntax::{DebugArgumentValue, DebugConfigCompletion, DebugTemplate};
Expand Down Expand Up @@ -73,7 +73,7 @@ fn thread_picker(
let debugger = debugger!(editor);

let thread_states = debugger.thread_states.clone();
let picker = FilePicker::new(
let picker = Picker::with_preview(
threads,
thread_states,
move |cx, thread, _action| callback_fn(cx.editor, thread),
Expand Down Expand Up @@ -270,7 +270,7 @@ pub fn dap_launch(cx: &mut Context) {

let templates = config.templates.clone();

cx.push_layer(Box::new(overlayed(Picker::new(
cx.push_layer(Box::new(overlayed(Picker::without_preview(
templates,
(),
|cx, template, _action| {
Expand Down Expand Up @@ -681,7 +681,7 @@ pub fn dap_switch_stack_frame(cx: &mut Context) {

let frames = debugger.stack_frames[&thread_id].clone();

let picker = FilePicker::new(
let picker = Picker::with_preview(
frames,
(),
move |cx, frame, _action| {
Expand Down
14 changes: 7 additions & 7 deletions helix-term/src/commands/lsp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ use helix_view::{document::Mode, editor::Action, theme::Style};
use crate::{
compositor::{self, Compositor},
ui::{
self, lsp::SignatureHelp, overlay::overlayed, DynamicPicker, FileLocation, FilePicker,
Popup, PromptEvent,
self, lsp::SignatureHelp, overlay::overlayed, DynamicPicker, FileLocation, Picker, Popup,
PromptEvent,
},
};

Expand Down Expand Up @@ -208,9 +208,9 @@ fn sym_picker(
symbols: Vec<lsp::SymbolInformation>,
current_path: Option<lsp::Url>,
offset_encoding: OffsetEncoding,
) -> FilePicker<lsp::SymbolInformation> {
) -> Picker<lsp::SymbolInformation> {
// TODO: drop current_path comparison and instead use workspace: bool flag?
FilePicker::new(
Picker::with_preview(
symbols,
current_path.clone(),
move |cx, symbol, action| {
Expand Down Expand Up @@ -263,7 +263,7 @@ fn diag_picker(
current_path: Option<lsp::Url>,
format: DiagnosticsFormat,
offset_encoding: OffsetEncoding,
) -> 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
Expand All @@ -285,7 +285,7 @@ fn diag_picker(
error: cx.editor.theme.get("error"),
};

FilePicker::new(
Picker::with_preview(
flat_diag,
(styles, format),
move |cx, PickerDiagnostic { url, diag }, action| {
Expand Down Expand Up @@ -886,7 +886,7 @@ fn goto_impl(
editor.set_error("No definition found.");
}
_locations => {
let picker = FilePicker::new(
let picker = Picker::with_preview(
locations,
cwdir,
move |cx, location, action| {
Expand Down
7 changes: 4 additions & 3 deletions helix-term/src/commands/typed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1161,9 +1161,10 @@ fn lsp_workspace_command(
let callback = async move {
let call: job::Callback = Callback::EditorCompositor(Box::new(
move |_editor: &mut Editor, compositor: &mut Compositor| {
let picker = ui::Picker::new(commands, (), |cx, command, _action| {
execute_lsp_command(cx.editor, command.clone());
});
let picker =
ui::Picker::without_preview(commands, (), |cx, command, _action| {
execute_lsp_command(cx.editor, command.clone());
});
compositor.push(Box::new(overlayed(picker)))
},
));
Expand Down
6 changes: 3 additions & 3 deletions helix-term/src/ui/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ pub use completion::Completion;
pub use editor::EditorView;
pub use markdown::Markdown;
pub use menu::Menu;
pub use picker::{DynamicPicker, FileLocation, FilePicker, Picker};
pub use picker::{DynamicPicker, FileLocation, Picker};
pub use popup::Popup;
pub use prompt::{Prompt, PromptEvent};
pub use spinner::{ProgressSpinners, Spinner};
Expand Down Expand Up @@ -158,7 +158,7 @@ pub fn regex_prompt(
cx.push_layer(Box::new(prompt));
}

pub fn file_picker(root: PathBuf, config: &helix_view::editor::Config) -> FilePicker<PathBuf> {
pub fn file_picker(root: PathBuf, config: &helix_view::editor::Config) -> Picker<PathBuf> {
use ignore::{types::TypesBuilder, WalkBuilder};
use std::time::Instant;

Expand Down Expand Up @@ -217,7 +217,7 @@ pub fn file_picker(root: PathBuf, config: &helix_view::editor::Config) -> FilePi

log::debug!("file_picker init {:?}", Instant::now().duration_since(now));

FilePicker::new(
Picker::with_preview(
files,
root,
move |cx, path: &PathBuf, action| {
Expand Down
Loading