on master help sign in
clippy: Factor out a Completion type.
commit698e4ddea46e9c94d537c8e4a6c69e7dc9ee1947 authorBlaž Hrastnik <blaz@mxxn.io> dateMon 22 Mar 2021, 13:16 (6 years ago) parentcbcacb1
2 files changed+8−5
helix-term/src/ui/mod.rs+3−2 helix-term/src/ui/prompt.rs+5−3
helix-term/src/ui/mod.rs+3−2
@@ -137,9 +137,10 @@ pub fn buffer_picker(views: &[View], current: usize) -> Picker<(Option<PathBuf>,
137137}
138138
139139pub mod completers {
140− use std::{borrow::Cow, ops::RangeFrom};
140+ use crate::ui::prompt::Completion;
141+ use std::borrow::Cow;
141142 // TODO: we could return an iter/lazy thing so it can fetch as many as it needs.
142− pub fn filename(input: &str) -> Vec<(RangeFrom<usize>, Cow<'static, str>)> {
143+ pub fn filename(input: &str) -> Vec<Completion> {
143144 // Rust's filename handling is really annoying.
144145
145146 use ignore::WalkBuilder;
helix-term/src/ui/prompt.rs+5−3
@@ -4,13 +4,15 @@ use helix_core::Position;
44use helix_view::{Editor, Theme};
55use std::{borrow::Cow, ops::RangeFrom};
66
7+pub type Completion = (RangeFrom<usize>, Cow<'static, str>);
8+
79pub struct Prompt {
810 prompt: String,
911 pub line: String,
1012 cursor: usize,
11− completion: Vec<(RangeFrom<usize>, Cow<'static, str>)>,
13+ completion: Vec<Completion>,
1214 completion_selection_index: Option<usize>,
13− completion_fn: Box<dyn FnMut(&str) -> Vec<(RangeFrom<usize>, Cow<'static, str>)>>,
15+ completion_fn: Box<dyn FnMut(&str) -> Vec<Completion>>,
1416 callback_fn: Box<dyn FnMut(&mut Editor, &str, PromptEvent)>,
1517}
1618
@@ -27,7 +29,7 @@ pub enum PromptEvent {
2729impl Prompt {
2830 pub fn new(
2931 prompt: String,
30− mut completion_fn: impl FnMut(&str) -> Vec<(RangeFrom<usize>, Cow<'static, str>)> + 'static,
32+ mut completion_fn: impl FnMut(&str) -> Vec<Completion> + 'static,
3133 callback_fn: impl FnMut(&mut Editor, &str, PromptEvent) + 'static,
3234 ) -> Prompt {
3335 Prompt {