Add ability to display backgrounds for inlay hints (#18010)
This PR adds the ability to display backgrounds for inlay hints within
the editor.
This is controlled by the new `inlay_hints.show_background` setting.
This setting defaults to `false`.
To enable the setting, add the following to your `settings.json`:
```json
{
"inlay_hints": {
"enabled": true,
"show_background": true
}
}
```
When enabled, the inlay hint backgrounds will use the `hint.background`
color from the theme.
| Disabled | Enabled |
|
--------------------------------------------------------------------------------------------------------------------------------------------------
|
--------------------------------------------------------------------------------------------------------------------------------------------------
|
| <img width="1624" alt="Screenshot 2024-09-17 at 4 21 53 PM"
src="https://github.com/user-attachments/assets/5534d09b-1e22-4c6f-9d82-314796ed7d22">
| <img width="1624" alt="Screenshot 2024-09-17 at 4 21 43 PM"
src="https://github.com/user-attachments/assets/6ec58cde-6115-4db4-be95-97c5f2f54b2d">
|
Related issues:
- #12485
- #17392
Release Notes:
- Added an `inlay_hints.show_background` setting to allow displaying
backgrounds for inlay hints in the editor.
- This setting defaults to `false`.
- If enabled, the inlay hint backgrounds will use the `hint.background`
color from the theme.
This commit is contained in:
@@ -412,6 +412,19 @@ impl Default for EditorStyle {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn make_inlay_hints_style(cx: &WindowContext) -> HighlightStyle {
|
||||
let show_background = all_language_settings(None, cx)
|
||||
.language(None)
|
||||
.inlay_hints
|
||||
.show_background;
|
||||
|
||||
HighlightStyle {
|
||||
color: Some(cx.theme().status().hint),
|
||||
background_color: show_background.then(|| cx.theme().status().hint_background),
|
||||
..HighlightStyle::default()
|
||||
}
|
||||
}
|
||||
|
||||
type CompletionId = usize;
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
@@ -10034,9 +10047,8 @@ impl Editor {
|
||||
syntax: cx.editor_style.syntax.clone(),
|
||||
status: cx.editor_style.status.clone(),
|
||||
inlay_hints_style: HighlightStyle {
|
||||
color: Some(cx.theme().status().hint),
|
||||
font_weight: Some(FontWeight::BOLD),
|
||||
..HighlightStyle::default()
|
||||
..make_inlay_hints_style(cx)
|
||||
},
|
||||
suggestions_style: HighlightStyle {
|
||||
color: Some(cx.theme().status().predictive),
|
||||
@@ -12992,10 +13004,7 @@ impl Render for Editor {
|
||||
scrollbar_width: EditorElement::SCROLLBAR_WIDTH,
|
||||
syntax: cx.theme().syntax().clone(),
|
||||
status: cx.theme().status().clone(),
|
||||
inlay_hints_style: HighlightStyle {
|
||||
color: Some(cx.theme().status().hint),
|
||||
..HighlightStyle::default()
|
||||
},
|
||||
inlay_hints_style: make_inlay_hints_style(cx),
|
||||
suggestions_style: HighlightStyle {
|
||||
color: Some(cx.theme().status().predictive),
|
||||
..HighlightStyle::default()
|
||||
|
||||
@@ -1205,6 +1205,7 @@ mod tests {
|
||||
show_type_hints: true,
|
||||
show_parameter_hints: true,
|
||||
show_other_hints: true,
|
||||
show_background: false,
|
||||
})
|
||||
});
|
||||
|
||||
|
||||
@@ -1337,6 +1337,7 @@ mod tests {
|
||||
show_type_hints: true,
|
||||
show_parameter_hints: true,
|
||||
show_other_hints: true,
|
||||
show_background: false,
|
||||
})
|
||||
});
|
||||
|
||||
|
||||
@@ -1296,6 +1296,7 @@ pub mod tests {
|
||||
show_type_hints: allowed_hint_kinds.contains(&Some(InlayHintKind::Type)),
|
||||
show_parameter_hints: allowed_hint_kinds.contains(&Some(InlayHintKind::Parameter)),
|
||||
show_other_hints: allowed_hint_kinds.contains(&None),
|
||||
show_background: false,
|
||||
})
|
||||
});
|
||||
|
||||
@@ -1428,6 +1429,7 @@ pub mod tests {
|
||||
show_type_hints: true,
|
||||
show_parameter_hints: true,
|
||||
show_other_hints: true,
|
||||
show_background: false,
|
||||
})
|
||||
});
|
||||
|
||||
@@ -1547,6 +1549,7 @@ pub mod tests {
|
||||
show_type_hints: true,
|
||||
show_parameter_hints: true,
|
||||
show_other_hints: true,
|
||||
show_background: false,
|
||||
})
|
||||
});
|
||||
|
||||
@@ -1777,6 +1780,7 @@ pub mod tests {
|
||||
show_type_hints: allowed_hint_kinds.contains(&Some(InlayHintKind::Type)),
|
||||
show_parameter_hints: allowed_hint_kinds.contains(&Some(InlayHintKind::Parameter)),
|
||||
show_other_hints: allowed_hint_kinds.contains(&None),
|
||||
show_background: false,
|
||||
})
|
||||
});
|
||||
|
||||
@@ -1941,6 +1945,7 @@ pub mod tests {
|
||||
show_parameter_hints: new_allowed_hint_kinds
|
||||
.contains(&Some(InlayHintKind::Parameter)),
|
||||
show_other_hints: new_allowed_hint_kinds.contains(&None),
|
||||
show_background: false,
|
||||
})
|
||||
});
|
||||
cx.executor().run_until_parked();
|
||||
@@ -1987,6 +1992,7 @@ pub mod tests {
|
||||
show_parameter_hints: another_allowed_hint_kinds
|
||||
.contains(&Some(InlayHintKind::Parameter)),
|
||||
show_other_hints: another_allowed_hint_kinds.contains(&None),
|
||||
show_background: false,
|
||||
})
|
||||
});
|
||||
cx.executor().run_until_parked();
|
||||
@@ -2047,6 +2053,7 @@ pub mod tests {
|
||||
show_parameter_hints: final_allowed_hint_kinds
|
||||
.contains(&Some(InlayHintKind::Parameter)),
|
||||
show_other_hints: final_allowed_hint_kinds.contains(&None),
|
||||
show_background: false,
|
||||
})
|
||||
});
|
||||
cx.executor().run_until_parked();
|
||||
@@ -2122,6 +2129,7 @@ pub mod tests {
|
||||
show_type_hints: true,
|
||||
show_parameter_hints: true,
|
||||
show_other_hints: true,
|
||||
show_background: false,
|
||||
})
|
||||
});
|
||||
|
||||
@@ -2256,6 +2264,7 @@ pub mod tests {
|
||||
show_type_hints: true,
|
||||
show_parameter_hints: true,
|
||||
show_other_hints: true,
|
||||
show_background: false,
|
||||
})
|
||||
});
|
||||
|
||||
@@ -2551,6 +2560,7 @@ pub mod tests {
|
||||
show_type_hints: true,
|
||||
show_parameter_hints: true,
|
||||
show_other_hints: true,
|
||||
show_background: false,
|
||||
})
|
||||
});
|
||||
|
||||
@@ -2902,6 +2912,7 @@ pub mod tests {
|
||||
show_type_hints: false,
|
||||
show_parameter_hints: false,
|
||||
show_other_hints: false,
|
||||
show_background: false,
|
||||
})
|
||||
});
|
||||
|
||||
@@ -3096,6 +3107,7 @@ pub mod tests {
|
||||
show_type_hints: true,
|
||||
show_parameter_hints: true,
|
||||
show_other_hints: true,
|
||||
show_background: false,
|
||||
})
|
||||
});
|
||||
cx.executor().run_until_parked();
|
||||
@@ -3131,6 +3143,7 @@ pub mod tests {
|
||||
show_type_hints: true,
|
||||
show_parameter_hints: true,
|
||||
show_other_hints: true,
|
||||
show_background: false,
|
||||
})
|
||||
});
|
||||
|
||||
@@ -3225,6 +3238,7 @@ pub mod tests {
|
||||
show_type_hints: true,
|
||||
show_parameter_hints: true,
|
||||
show_other_hints: true,
|
||||
show_background: false,
|
||||
})
|
||||
});
|
||||
|
||||
@@ -3305,6 +3319,7 @@ pub mod tests {
|
||||
show_type_hints: true,
|
||||
show_parameter_hints: true,
|
||||
show_other_hints: true,
|
||||
show_background: false,
|
||||
})
|
||||
});
|
||||
cx.executor().run_until_parked();
|
||||
|
||||
Reference in New Issue
Block a user