Debounce refresh of inlay hints on buffer edits (#8282)
I think this makes it less chaotic to edit text when the inlay hints are
on.
It's for cases where you're editing to the right side of an inlay hint.
Example:
```rust
for name in names.iter().map(|item| item.len()) {
println!("{:?}", name);
}
```
We display a `usize` inlay hint right next to `name`.
But as soon as you remove that `.` in `names.iter` your cursor jumps
around because the inlay hint has been removed.
With this change we now have a 700ms debounce before we update the inlay
hints.
VS Code seems to have an even longer debounce, I think somewhere around
~1s.
Release Notes:
- Added debouncing to make it easier to edit text when inlay hints are
enabled and to save rendering of inlay hints when scrolling. Both
debounce durations can be configured with `{"inlay_hints":
{"edit_debounce_ms": 700}}` (default) and `{"inlay_hints":
{"scroll_debounce_ms": 50}}`. Set a value to `0` to turn off the
debouncing.
### Before
https://github.com/zed-industries/zed/assets/1185253/3afbe548-dcfb-45a3-ab9f-cce14c04a148
### After
https://github.com/zed-industries/zed/assets/1185253/7ea90e42-bca6-4f6c-995e-83324669ab43
---------
Co-authored-by: Kirill <kirill@zed.dev>
This commit is contained in:
@@ -327,12 +327,34 @@ pub struct InlayHintSettings {
|
||||
/// Default: true
|
||||
#[serde(default = "default_true")]
|
||||
pub show_other_hints: bool,
|
||||
/// Whether or not to debounce inlay hints updates after buffer edits.
|
||||
///
|
||||
/// Set to 0 to disable debouncing.
|
||||
///
|
||||
/// Default: 700
|
||||
#[serde(default = "edit_debounce_ms")]
|
||||
pub edit_debounce_ms: u64,
|
||||
/// Whether or not to debounce inlay hints updates after buffer scrolls.
|
||||
///
|
||||
/// Set to 0 to disable debouncing.
|
||||
///
|
||||
/// Default: 50
|
||||
#[serde(default = "scroll_debounce_ms")]
|
||||
pub scroll_debounce_ms: u64,
|
||||
}
|
||||
|
||||
fn default_true() -> bool {
|
||||
true
|
||||
}
|
||||
|
||||
fn edit_debounce_ms() -> u64 {
|
||||
700
|
||||
}
|
||||
|
||||
fn scroll_debounce_ms() -> u64 {
|
||||
50
|
||||
}
|
||||
|
||||
impl InlayHintSettings {
|
||||
/// Returns the kinds of inlay hints that are enabled based on the settings.
|
||||
pub fn enabled_inlay_hint_kinds(&self) -> HashSet<Option<InlayHintKind>> {
|
||||
|
||||
Reference in New Issue
Block a user