on master help sign in
clippy: Factor out a Completion type.
698e4ddBlaž Hrastnik
helix-term/src/ui/mod.rs+3−2
@@ -137,9 +137,10 @@ pub fn buffer_picker(views: &[View], current: usize) -> Picker<(Option<PathBuf>,
137}
137}
138
138
139pub mod completers {
139pub mod completers {
140+ use crate::ui::prompt::Completion;
140− use std::{borrow::Cow, ops::RangeFrom};
141+ use std::borrow::Cow;
141 // TODO: we could return an iter/lazy thing so it can fetch as many as it needs.
142 // 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> {
143 // Rust's filename handling is really annoying.
144 // Rust's filename handling is really annoying.
144
145
145 use ignore::WalkBuilder;
146 use ignore::WalkBuilder;
helix-term/src/ui/prompt.rs+5−3
@@ -4,13 +4,15 @@ use helix_core::Position;
4use helix_view::{Editor, Theme};
4use helix_view::{Editor, Theme};
5use std::{borrow::Cow, ops::RangeFrom};
5use std::{borrow::Cow, ops::RangeFrom};
6
6
7+pub type Completion = (RangeFrom<usize>, Cow<'static, str>);
8+
7pub struct Prompt {
9pub struct Prompt {
8 prompt: String,
10 prompt: String,
9 pub line: String,
11 pub line: String,
10 cursor: usize,
12 cursor: usize,
11− completion: Vec<(RangeFrom<usize>, Cow<'static, str>)>,
13+ completion: Vec<Completion>,
12 completion_selection_index: Option<usize>,
14 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>>,
14 callback_fn: Box<dyn FnMut(&mut Editor, &str, PromptEvent)>,
16 callback_fn: Box<dyn FnMut(&mut Editor, &str, PromptEvent)>,
15}
17}
16
18
@@ -27,7 +29,7 @@ pub enum PromptEvent {
27impl Prompt {
29impl Prompt {
28 pub fn new(
30 pub fn new(
29 prompt: String,
31 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,
31 callback_fn: impl FnMut(&mut Editor, &str, PromptEvent) + 'static,
33 callback_fn: impl FnMut(&mut Editor, &str, PromptEvent) + 'static,
32 ) -> Prompt {
34 ) -> Prompt {
33 Prompt {
35 Prompt {