editor: Utilize filter_text from language server for filter_range (#33155)

Closes #33106

Instead of directly using `filter_text` in `StringMatchCandidate`, which
yields better results for fuzzy matching but messes up with highlighting
letters in bold, as `positions` list generated by fuzzy crate are now of
`filter_text` and not `label` shown to the user.

This PR fixes it by keeping use of `filter_range` in
`StringMatchCandidate`, which is range w.r.t to `label` shown to user.
And actually generating this `filter_range` at source by using
`filter_range` if exists.

- [x] Tests

Release Notes:

- Fixed issue where incorrect letters are marked as bold in completions.
This commit is contained in:
Smit Barmase 2025-06-21 19:47:16 +05:30 committed by GitHub
parent 834cdc1271
commit 76e3136369
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
10 changed files with 206 additions and 61 deletions

View file

@ -1982,25 +1982,27 @@ impl CodeLabel {
} else {
label.clone()
};
let filter_range = item
.filter_text
.as_deref()
.and_then(|filter| text.find(filter).map(|ix| ix..ix + filter.len()))
.unwrap_or(0..label_length);
Self {
text,
runs,
filter_range: 0..label_length,
filter_range,
}
}
pub fn plain(text: String, filter_text: Option<&str>) -> Self {
let mut result = Self {
let filter_range = filter_text
.and_then(|filter| text.find(filter).map(|ix| ix..ix + filter.len()))
.unwrap_or(0..text.len());
Self {
runs: Vec::new(),
filter_range: 0..text.len(),
filter_range,
text,
};
if let Some(filter_text) = filter_text {
if let Some(ix) = result.text.find(filter_text) {
result.filter_range = ix..ix + filter_text.len();
}
}
result
}
pub fn push_str(&mut self, text: &str, highlight: Option<HighlightId>) {