Removed From impl for clarity

pull/8339/head
ItsEthra 9 months ago
parent 9b055e03f0
commit 56d822f4b8

@ -62,7 +62,9 @@ use crate::{
filter_picker_entry, filter_picker_entry,
job::Callback, job::Callback,
keymap::ReverseKeymap, keymap::ReverseKeymap,
ui::{self, menu::Item, overlay::overlaid, Picker, Popup, Prompt, PromptEvent}, ui::{
self, menu::Item, overlay::overlaid, CompletionResult, Picker, Popup, Prompt, PromptEvent,
},
}; };
use crate::job::{self, Jobs}; use crate::job::{self, Jobs};
@ -2094,12 +2096,14 @@ fn searcher(cx: &mut Context, direction: Direction) {
"search:".into(), "search:".into(),
Some(reg), Some(reg),
move |_editor: &Editor, input: &str| { move |_editor: &Editor, input: &str| {
CompletionResult::new(
completions completions
.iter() .iter()
.filter(|comp| comp.starts_with(input)) .filter(|comp| comp.starts_with(input))
.map(|comp| (0.., std::borrow::Cow::Owned(comp.clone()))) .map(|comp| (0.., std::borrow::Cow::Owned(comp.clone())))
.collect::<Vec<_>>() .collect::<Vec<_>>(),
.into() false,
)
}, },
move |cx, regex, event| { move |cx, regex, event| {
if event == PromptEvent::Validate { if event == PromptEvent::Validate {
@ -2287,12 +2291,14 @@ fn global_search(cx: &mut Context) {
"global-search:".into(), "global-search:".into(),
Some(reg), Some(reg),
move |_editor: &Editor, input: &str| { move |_editor: &Editor, input: &str| {
CompletionResult::new(
completions completions
.iter() .iter()
.filter(|comp| comp.starts_with(input)) .filter(|comp| comp.starts_with(input))
.map(|comp| (0.., std::borrow::Cow::Owned(comp.clone()))) .map(|comp| (0.., std::borrow::Cow::Owned(comp.clone())))
.collect::<Vec<_>>() .collect::<Vec<_>>(),
.into() false,
)
}, },
move |cx, _, input, event| { move |cx, _, input, event| {
if event != PromptEvent::Validate { if event != PromptEvent::Validate {

@ -3134,18 +3134,17 @@ pub(super) fn command_mode(cx: &mut Context) {
let words = shellwords.words(); let words = shellwords.words();
if words.is_empty() || (words.len() == 1 && !shellwords.ends_with_whitespace()) { if words.is_empty() || (words.len() == 1 && !shellwords.ends_with_whitespace()) {
let mut result: CompletionResult = fuzzy_match( CompletionResult::new(
fuzzy_match(
input, input,
TYPABLE_COMMAND_LIST.iter().map(|command| command.name), TYPABLE_COMMAND_LIST.iter().map(|command| command.name),
false, false,
) )
.into_iter() .into_iter()
.map(|(name, _)| (0.., name.into())) .map(|(name, _)| (0.., name.into()))
.collect::<Vec<_>>() .collect(),
.into(); matches!(editor.config().command_hints, CommandHints::Always),
result.show_popup = matches!(editor.config().command_hints, CommandHints::Always); )
result
} else { } else {
// Otherwise, use the command's completer and the last shellword // Otherwise, use the command's completer and the last shellword
// as completion input. // as completion input.
@ -3161,6 +3160,7 @@ pub(super) fn command_mode(cx: &mut Context) {
.get(&words[0] as &str) .get(&words[0] as &str)
.map(|tc| tc.completer_for_argument_number(argument_number)) .map(|tc| tc.completer_for_argument_number(argument_number))
{ {
CompletionResult::new(
completer(editor, word) completer(editor, word)
.completions .completions
.into_iter() .into_iter()
@ -3172,8 +3172,9 @@ pub(super) fn command_mode(cx: &mut Context) {
let range = (range.start + offset)..; let range = (range.start + offset)..;
(range, file) (range, file)
}) })
.collect::<Vec<_>>() .collect::<Vec<_>>(),
.into() false,
)
} else { } else {
CompletionResult::default() CompletionResult::default()
}; };

@ -278,11 +278,13 @@ pub mod completers {
.unwrap_or_else(|| Cow::from(SCRATCH_BUFFER_NAME)) .unwrap_or_else(|| Cow::from(SCRATCH_BUFFER_NAME))
}); });
CompletionResult::new(
fuzzy_match(input, names, true) fuzzy_match(input, names, true)
.into_iter() .into_iter()
.map(|(name, _)| ((0..), name)) .map(|(name, _)| ((0..), name))
.collect::<Vec<Completion>>() .collect::<Vec<Completion>>(),
.into() false,
)
} }
pub fn theme(_editor: &Editor, input: &str) -> CompletionResult { pub fn theme(_editor: &Editor, input: &str) -> CompletionResult {
@ -295,11 +297,13 @@ pub mod completers {
names.sort(); names.sort();
names.dedup(); names.dedup();
CompletionResult::new(
fuzzy_match(input, names, false) fuzzy_match(input, names, false)
.into_iter() .into_iter()
.map(|(name, _)| ((0..), name.into())) .map(|(name, _)| ((0..), name.into()))
.collect::<Vec<Completion>>() .collect::<Vec<Completion>>(),
.into() false,
)
} }
/// Recursive function to get all keys from this value and add them to vec /// Recursive function to get all keys from this value and add them to vec
@ -326,11 +330,13 @@ pub mod completers {
keys keys
}); });
CompletionResult::new(
fuzzy_match(input, &*KEYS, false) fuzzy_match(input, &*KEYS, false)
.into_iter() .into_iter()
.map(|(name, _)| ((0..), name.into())) .map(|(name, _)| ((0..), name.into()))
.collect::<Vec<Completion>>() .collect::<Vec<Completion>>(),
.into() false,
)
} }
pub fn filename(editor: &Editor, input: &str) -> CompletionResult { pub fn filename(editor: &Editor, input: &str) -> CompletionResult {
@ -363,11 +369,13 @@ pub mod completers {
.map(|config| &config.language_id) .map(|config| &config.language_id)
.chain(std::iter::once(&text)); .chain(std::iter::once(&text));
CompletionResult::new(
fuzzy_match(input, language_ids, false) fuzzy_match(input, language_ids, false)
.into_iter() .into_iter()
.map(|(name, _)| ((0..), name.to_owned().into())) .map(|(name, _)| ((0..), name.to_owned().into()))
.collect::<Vec<Completion>>() .collect::<Vec<Completion>>(),
.into() false,
)
} }
pub fn lsp_workspace_command(editor: &Editor, input: &str) -> CompletionResult { pub fn lsp_workspace_command(editor: &Editor, input: &str) -> CompletionResult {
@ -378,11 +386,13 @@ pub mod completers {
return CompletionResult::default(); return CompletionResult::default();
}; };
CompletionResult::new(
fuzzy_match(input, &options.commands, false) fuzzy_match(input, &options.commands, false)
.into_iter() .into_iter()
.map(|(name, _)| ((0..), name.to_owned().into())) .map(|(name, _)| ((0..), name.to_owned().into()))
.collect::<Vec<Completion>>() .collect::<Vec<Completion>>(),
.into() false,
)
} }
pub fn directory(editor: &Editor, input: &str) -> CompletionResult { pub fn directory(editor: &Editor, input: &str) -> CompletionResult {
@ -504,17 +514,19 @@ pub mod completers {
// if empty, return a list of dirs and files in current dir // if empty, return a list of dirs and files in current dir
if let Some(file_name) = file_name { if let Some(file_name) = file_name {
let range = (input.len().saturating_sub(file_name.len()))..; let range = (input.len().saturating_sub(file_name.len()))..;
CompletionResult::new(
fuzzy_match(&file_name, files, true) fuzzy_match(&file_name, files, true)
.into_iter() .into_iter()
.map(|(name, _)| (range.clone(), name)) .map(|(name, _)| (range.clone(), name))
.collect::<Vec<Completion>>() .collect::<Vec<Completion>>(),
.into() false,
)
// TODO: complete to longest common match // TODO: complete to longest common match
} else { } else {
let mut files: Vec<_> = files.map(|file| (end.clone(), file)).collect(); let mut files: Vec<_> = files.map(|file| (end.clone(), file)).collect();
files.sort_unstable_by(|(_, path1), (_, path2)| path1.cmp(path2)); files.sort_unstable_by(|(_, path1), (_, path2)| path1.cmp(path2));
files.into() CompletionResult::new(files, false)
} }
} }
@ -526,10 +538,10 @@ pub mod completers {
.filter(|(ch, _)| !matches!(ch, '%' | '#' | '.')) .filter(|(ch, _)| !matches!(ch, '%' | '#' | '.'))
.map(|(ch, _)| ch.to_string()); .map(|(ch, _)| ch.to_string());
fuzzy_match(input, iter, false) let results = fuzzy_match(input, iter, false)
.into_iter() .into_iter()
.map(|(name, _)| ((0..), name.into())) .map(|(name, _)| ((0..), name.into()))
.collect::<Vec<Completion>>() .collect::<Vec<Completion>>();
.into() CompletionResult::new(results, false)
} }
} }

@ -29,11 +29,11 @@ pub struct CompletionResult {
pub show_popup: bool, pub show_popup: bool,
} }
impl From<Vec<Completion>> for CompletionResult { impl CompletionResult {
fn from(completions: Vec<Completion>) -> Self { pub fn new(completions: Vec<Completion>, show_popup: bool) -> Self {
Self { Self {
show_popup: true,
completions, completions,
show_popup,
} }
} }
} }

Loading…
Cancel
Save