Don't generate invalid ranges for C code (#13183)

Fixes: #13128

Release Notes:

- Fixed a panic when editing C code
([#13128](https://github.com/zed-industries/zed/issues/13128)).
This commit is contained in:
Conrad Irwin 2024-06-17 21:13:42 -06:00 committed by GitHub
parent 7003b0f211
commit 0af6e442a7
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -197,8 +197,16 @@ impl super::LspAdapter for CLspAdapter {
let detail = completion.detail.as_ref().unwrap();
let text = format!("{} {}", detail, label);
let runs = language.highlight_text(&Rope::from(text.as_str()), 0..text.len());
let filter_start = detail.len() + 1;
let filter_end =
if let Some(end) = text.rfind('(').filter(|end| *end > filter_start) {
end
} else {
text.len()
};
return Some(CodeLabel {
filter_range: detail.len() + 1..text.rfind('(').unwrap_or(text.len()),
filter_range: filter_start..filter_end,
text,
runs,
});