Apply code review fixes

This commit is contained in:
Henrik Hørlück Berg 2023-09-15 14:38:49 +02:00
parent d6a9ad66a7
commit 5407d0b785
No known key found for this signature in database
2 changed files with 7 additions and 17 deletions

View File

@ -160,12 +160,6 @@ impl CompletionReceiver {
true
}
/// Swap our completions with a new list.
pub fn swap(&mut self, lst: &mut Vec<Completion>) {
// XXX: This completly breaks our completions.len() <= self.limit invariant
std::mem::swap(&mut self.completions, lst);
}
/// Clear the list of completions. This retains the storage inside completions_ which can be
/// useful to prevent allocations.
pub fn clear(&mut self) {

View File

@ -69,13 +69,9 @@ fn resolve_description<'f>(
) -> WString {
if let Some(complete_sep_loc) = completion.find_char(PROG_COMPLETE_SEP) {
// This completion has an embedded description, do not use the generic description.
assert!(
completion.len() > complete_sep_loc,
"resolve_description lacks a length assumption"
);
let (comp, description) = completion.split_at(complete_sep_loc + 1);
*completion = comp;
return description.to_owned();
let description = completion[complete_sep_loc + 1..].to_owned();
*completion = &completion[..complete_sep_loc];
return description;
}
if let Some(f) = description_func {
@ -143,7 +139,7 @@ fn wildcard_complete_internal(
// If we're not allowing fuzzy match, then we require a prefix match.
let needs_prefix_match = !params.expand_flags.contains(ExpandFlags::FUZZY_MATCH);
if needs_prefix_match && m.is_exact_or_prefix() {
if needs_prefix_match && !m.is_exact_or_prefix() {
return WildcardResult::NoMatch;
}
@ -464,11 +460,11 @@ fn wildcard_test_flags_then_complete(
// Append a / if this is a directory. Note this requirement may be the only reason we have to
// call stat() in some cases.
let x = |_: &wstr| match desc.as_ref() {
let desc_func = |_: &wstr| match desc.as_ref() {
Some(d) => d.to_owned(),
None => WString::new(),
};
let desc_func: Option<&dyn Fn(&wstr) -> WString> = Some(&x);
let desc_func: Option<&dyn Fn(&wstr) -> WString> = Some(&desc_func);
if is_directory {
return wildcard_complete(
&(filename.to_owned() + L!("/")),
@ -874,7 +870,7 @@ mod expander {
break;
};
if need_dir && entry.is_dir() {
if need_dir && !entry.is_dir() {
continue;
}