Omit empty hovers (#9967)

Closes https://github.com/zed-industries/zed/issues/9962

Release Notes:

- N/A
This commit is contained in:
Kirill Bulatov 2024-03-29 20:59:01 +01:00 committed by GitHub
parent e252f90e30
commit 5d531037c4
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 87 additions and 1 deletions

View file

@ -5193,6 +5193,17 @@ impl Project {
position: PointUtf16,
cx: &mut ModelContext<Self>,
) -> Task<Vec<Hover>> {
fn remove_empty_hover_blocks(mut hover: Hover) -> Option<Hover> {
hover
.contents
.retain(|hover_block| !hover_block.text.trim().is_empty());
if hover.contents.is_empty() {
None
} else {
Some(hover)
}
}
if self.is_local() {
let snapshot = buffer.read(cx).snapshot();
let offset = position.to_offset(&snapshot);
@ -5225,7 +5236,11 @@ impl Project {
cx.spawn(|_, _| async move {
let mut hovers = Vec::with_capacity(hover_responses.len());
while let Some(hover_response) = hover_responses.next().await {
if let Some(hover) = hover_response.log_err().flatten() {
if let Some(hover) = hover_response
.log_err()
.flatten()
.and_then(remove_empty_hover_blocks)
{
hovers.push(hover);
}
}
@ -5243,6 +5258,7 @@ impl Project {
.await
.log_err()
.flatten()
.and_then(remove_empty_hover_blocks)
.map(|hover| vec![hover])
.unwrap_or_default()
})