Show more possible matches in code context completion (#27199)

Closes #24794

We now don't filter matches provided by the fuzzy matcher, as it already
performs most of the filtering for us. Instead, the custom logic we
previously used for filtering is now used to partition, where before
discarded matches will be appended at end of list.

Before - Filtering out matches with higher fuzzy score
<img width="400" alt="image"
src="https://github.com/user-attachments/assets/7f9d66a2-0921-499c-af8a-f1e530da50b1"
/>

After - Changing filter to partition instead, and appending remaining
items at the end
<img width="400" alt="image"
src="https://github.com/user-attachments/assets/45848f70-ed51-4935-976c-6c16c5b5777b"
/>


Release Notes:

- Improved LSP auto complete to show more possible matches.

---------

Co-authored-by: Peter Tripp <petertripp@gmail.com>
This commit is contained in:
Smit Barmase 2025-03-20 23:46:20 +05:30 committed by GitHub
parent 7931b1d345
commit 7b80cd865d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 9 additions and 4 deletions

View file

@ -665,10 +665,11 @@ impl CompletionsMenu {
.collect()
};
// Remove all candidates where the query's start does not match the start of any word in the candidate
let mut additional_matches = Vec::new();
// Deprioritize all candidates where the query's start does not match the start of any word in the candidate
if let Some(query) = query {
if let Some(query_start) = query.chars().next() {
matches.retain(|string_match| {
let (primary, secondary) = matches.into_iter().partition(|string_match| {
split_words(&string_match.string).any(|word| {
// Check that the first codepoint of the word as lowercase matches the first
// codepoint of the query as lowercase
@ -678,6 +679,8 @@ impl CompletionsMenu {
.all(|(word_cp, query_cp)| word_cp == query_cp)
})
});
matches = primary;
additional_matches = secondary;
}
}
@ -740,6 +743,8 @@ impl CompletionsMenu {
}
drop(completions);
matches.extend(additional_matches);
*self.entries.borrow_mut() = matches;
self.selected_item = 0;
// This keeps the display consistent when y_flipped.