Add and use CodeLabel::filter_text() (#22054)

Michael Sloan created

Release Notes:

- N/A

Change summary

crates/editor/src/code_context_menus.rs       |  7 +------
crates/language/src/language.rs               |  4 ++++
crates/project_symbols/src/project_symbols.rs | 10 ++--------
3 files changed, 7 insertions(+), 14 deletions(-)

Detailed changes

crates/editor/src/code_context_menus.rs 🔗

@@ -160,12 +160,7 @@ impl CompletionsMenu {
         let match_candidates = completions
             .iter()
             .enumerate()
-            .map(|(id, completion)| {
-                StringMatchCandidate::new(
-                    id,
-                    &completion.label.text[completion.label.filter_range.clone()],
-                )
-            })
+            .map(|(id, completion)| StringMatchCandidate::new(id, &completion.label.filter_text()))
             .collect();
 
         Self {

crates/language/src/language.rs 🔗

@@ -1678,6 +1678,10 @@ impl CodeLabel {
     pub fn text(&self) -> &str {
         self.text.as_str()
     }
+
+    pub fn filter_text(&self) -> &str {
+        &self.text[self.filter_range.clone()]
+    }
 }
 
 impl From<String> for CodeLabel {

crates/project_symbols/src/project_symbols.rs 🔗

@@ -78,10 +78,7 @@ impl ProjectSymbolsDelegate {
         ));
         let sort_key_for_match = |mat: &StringMatch| {
             let symbol = &self.symbols[mat.candidate_id];
-            (
-                Reverse(OrderedFloat(mat.score)),
-                &symbol.label.text[symbol.label.filter_range.clone()],
-            )
+            (Reverse(OrderedFloat(mat.score)), symbol.label.filter_text())
         };
 
         visible_matches.sort_unstable_by_key(sort_key_for_match);
@@ -177,10 +174,7 @@ impl PickerDelegate for ProjectSymbolsDelegate {
                         .iter()
                         .enumerate()
                         .map(|(id, symbol)| {
-                            StringMatchCandidate::new(
-                                id,
-                                &symbol.label.text[symbol.label.filter_range.clone()],
-                            )
+                            StringMatchCandidate::new(id, &symbol.label.filter_text())
                         })
                         .partition(|candidate| {
                             project