From 5407d0b7859c27bbc72c80ef26bc579be09df953 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20H=C3=B8rl=C3=BCck=20Berg?= <36937807+henrikhorluck@users.noreply.github.com> Date: Fri, 15 Sep 2023 14:38:49 +0200 Subject: [PATCH] Apply code review fixes --- fish-rust/src/complete.rs | 6 ------ fish-rust/src/wildcard.rs | 18 +++++++----------- 2 files changed, 7 insertions(+), 17 deletions(-) diff --git a/fish-rust/src/complete.rs b/fish-rust/src/complete.rs index 789450602..8d9b846d3 100644 --- a/fish-rust/src/complete.rs +++ b/fish-rust/src/complete.rs @@ -160,12 +160,6 @@ impl CompletionReceiver { true } - /// Swap our completions with a new list. - pub fn swap(&mut self, lst: &mut Vec) { - // 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) { diff --git a/fish-rust/src/wildcard.rs b/fish-rust/src/wildcard.rs index b233bb26a..49bf94e02 100644 --- a/fish-rust/src/wildcard.rs +++ b/fish-rust/src/wildcard.rs @@ -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; }