Skip to content

Commit

Permalink
resolve new complex type clippy lints
Browse files Browse the repository at this point in the history
  • Loading branch information
pascalkuthe committed Jan 21, 2023
1 parent c2ad4d4 commit d632ec5
Show file tree
Hide file tree
Showing 8 changed files with 27 additions and 14 deletions.
4 changes: 3 additions & 1 deletion helix-term/src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,13 +69,15 @@ use grep_searcher::{sinks, BinaryDetection, SearcherBuilder};
use ignore::{DirEntry, WalkBuilder, WalkState};
use tokio_stream::wrappers::UnboundedReceiverStream;

pub type KeyCallback = Box<dyn FnOnce(&mut Context, KeyEvent)>;

pub struct Context<'a> {
pub register: Option<char>,
pub count: Option<NonZeroUsize>,
pub editor: &'a mut Editor,

pub callback: Option<crate::compositor::Callback>,
pub on_next_key_callback: Option<Box<dyn FnOnce(&mut Context, KeyEvent)>>,
pub on_next_key_callback: Option<KeyCallback>,
pub jobs: &'a mut Jobs,
}

Expand Down
1 change: 1 addition & 0 deletions helix-term/src/compositor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use helix_view::graphics::{CursorKind, Rect};
use tui::buffer::Buffer as Surface;

pub type Callback = Box<dyn FnOnce(&mut Compositor, &mut Context)>;
pub type SyncCallback = Box<dyn FnOnce(&mut Compositor, &mut Context) + Sync>;

// Cursive-inspired
pub enum EventResult {
Expand Down
7 changes: 5 additions & 2 deletions helix-term/src/job.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,12 @@ use crate::compositor::Compositor;
use futures_util::future::{BoxFuture, Future, FutureExt};
use futures_util::stream::{FuturesUnordered, StreamExt};

pub type EditorCompositorCallback = Box<dyn FnOnce(&mut Editor, &mut Compositor) + Send>;
pub type EditorCallback = Box<dyn FnOnce(&mut Editor) + Send>;

pub enum Callback {
EditorCompositor(Box<dyn FnOnce(&mut Editor, &mut Compositor) + Send>),
Editor(Box<dyn FnOnce(&mut Editor) + Send>),
EditorCompositor(EditorCompositorCallback),
Editor(EditorCallback),
}

pub type JobFuture = BoxFuture<'static, anyhow::Result<Option<Callback>>>;
Expand Down
2 changes: 0 additions & 2 deletions helix-term/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#![allow(clippy::type_complexity)]

#[macro_use]
extern crate helix_view;

Expand Down
4 changes: 2 additions & 2 deletions helix-term/src/ui/editor.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::{
commands,
commands::{self, KeyCallback},
compositor::{Component, Context, Event, EventResult},
job::{self, Callback},
key,
Expand Down Expand Up @@ -34,7 +34,7 @@ use super::statusline;

pub struct EditorView {
pub keymaps: Keymaps,
on_next_key: Option<Box<dyn FnOnce(&mut commands::Context, KeyEvent)>>,
on_next_key: Option<KeyCallback>,
pseudo_pending: Vec<KeyEvent>,
last_insert: (commands::MappableCommand, Vec<InsertEvent>),
pub(crate) completion: Option<Completion>,
Expand Down
4 changes: 3 additions & 1 deletion helix-term/src/ui/menu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ impl Item for PathBuf {
}
}

pub type MenuCallback<T> = Box<dyn Fn(&mut Editor, Option<&T>, MenuEvent)>;

pub struct Menu<T: Item> {
options: Vec<T>,
editor_data: T::Data,
Expand All @@ -55,7 +57,7 @@ pub struct Menu<T: Item> {

widths: Vec<Constraint>,

callback_fn: Box<dyn Fn(&mut Editor, Option<&T>, MenuEvent)>,
callback_fn: MenuCallback<T>,

scroll: usize,
size: (u16, u16),
Expand Down
8 changes: 6 additions & 2 deletions helix-term/src/ui/picker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ impl From<DocumentId> for PathOrId {
}
}

type FileCallback<T> = Box<dyn Fn(&Editor, &T) -> Option<FileLocation>>;

/// File path and range of lines (used to align and highlight lines)
pub type FileLocation = (PathOrId, Option<(usize, usize)>);

Expand All @@ -71,7 +73,7 @@ pub struct FilePicker<T: Item> {
preview_cache: HashMap<PathBuf, CachedPreview>,
read_buffer: Vec<u8>,
/// Given an item in the picker, return the file path and line number to display.
file_fn: Box<dyn Fn(&Editor, &T) -> Option<FileLocation>>,
file_fn: FileCallback<T>,
}

pub enum CachedPreview {
Expand Down Expand Up @@ -371,6 +373,8 @@ impl Ord for PickerMatch {
}
}

type PickerCallback<T> = Box<dyn Fn(&mut Context, &T, Action)>;

pub struct Picker<T: Item> {
options: Vec<T>,
editor_data: T::Data,
Expand All @@ -392,7 +396,7 @@ pub struct Picker<T: Item> {
/// Constraints for tabular formatting
widths: Vec<Constraint>,

callback_fn: Box<dyn Fn(&mut Context, &T, Action)>,
callback_fn: PickerCallback<T>,
}

impl<T: Item> Picker<T> {
Expand Down
11 changes: 7 additions & 4 deletions helix-term/src/ui/prompt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,11 @@ use helix_view::{
Editor,
};

pub type Completion = (RangeFrom<usize>, Cow<'static, str>);
type PromptCharHandler = Box<dyn Fn(&mut Prompt, char, &Context)>;
pub type Completion = (RangeFrom<usize>, Cow<'static, str>);
type CompletionFn = Box<dyn FnMut(&Editor, &str) -> Vec<Completion>>;
type CallbackFn = Box<dyn FnMut(&mut Context, &str, PromptEvent)>;
pub type DocFn = Box<dyn Fn(&str) -> Option<Cow<str>>>;

pub struct Prompt {
prompt: Cow<'static, str>,
Expand All @@ -25,9 +28,9 @@ pub struct Prompt {
selection: Option<usize>,
history_register: Option<char>,
history_pos: Option<usize>,
completion_fn: Box<dyn FnMut(&Editor, &str) -> Vec<Completion>>,
callback_fn: Box<dyn FnMut(&mut Context, &str, PromptEvent)>,
pub doc_fn: Box<dyn Fn(&str) -> Option<Cow<str>>>,
completion_fn: CompletionFn,
callback_fn: CallbackFn,
pub doc_fn: DocFn,
next_char_handler: Option<PromptCharHandler>,
}

Expand Down

0 comments on commit d632ec5

Please sign in to comment.