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:
@@ -1360,6 +1360,7 @@ enum InlayHintRefreshReason {
|
||||
RefreshRequested,
|
||||
ExcerptsRemoved(Vec<ExcerptId>),
|
||||
}
|
||||
|
||||
impl InlayHintRefreshReason {
|
||||
fn description(&self) -> &'static str {
|
||||
match self {
|
||||
@@ -3029,6 +3030,12 @@ impl Editor {
|
||||
}
|
||||
|
||||
let reason_description = reason.description();
|
||||
let ignore_debounce = matches!(
|
||||
reason,
|
||||
InlayHintRefreshReason::SettingsChange(_)
|
||||
| InlayHintRefreshReason::Toggle(_)
|
||||
| InlayHintRefreshReason::ExcerptsRemoved(_)
|
||||
);
|
||||
let (invalidate_cache, required_languages) = match reason {
|
||||
InlayHintRefreshReason::Toggle(enabled) => {
|
||||
self.inlay_hint_cache.enabled = enabled;
|
||||
@@ -3091,6 +3098,7 @@ impl Editor {
|
||||
reason_description,
|
||||
self.excerpts_for_inlay_hints_query(required_languages.as_ref(), cx),
|
||||
invalidate_cache,
|
||||
ignore_debounce,
|
||||
cx,
|
||||
) {
|
||||
self.splice_inlay_hints(to_remove, to_insert, cx);
|
||||
|
||||
Reference in New Issue
Block a user