Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ability to display backgrounds for inlay hints #18010

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions assets/settings/default.json
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,10 @@
"show_parameter_hints": true,
// Corresponds to null/None LSP hint type value.
"show_other_hints": true,
// Whether to show a background for inlay hints.
//
// If set to `true`, the background will use the `hint.background` color from the current theme.
"show_background": false,
// Time to wait after editing the buffer, before requesting the hints,
// set to 0 to disable debouncing.
"edit_debounce_ms": 700,
Expand Down
6 changes: 2 additions & 4 deletions crates/assistant/src/prompt_library.rs
Original file line number Diff line number Diff line change
Expand Up @@ -921,10 +921,8 @@ impl PromptLibrary {
scrollbar_width: Pixels::ZERO,
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:
editor::make_inlay_hints_style(cx),
suggestions_style: HighlightStyle {
color: Some(cx.theme().status().predictive),
..HighlightStyle::default()
Expand Down
4 changes: 4 additions & 0 deletions crates/collab/src/tests/editor_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1524,6 +1524,7 @@ async fn test_mutual_editor_inlay_hint_cache_update(
show_type_hints: true,
show_parameter_hints: false,
show_other_hints: true,
show_background: false,
})
});
});
Expand All @@ -1538,6 +1539,7 @@ async fn test_mutual_editor_inlay_hint_cache_update(
show_type_hints: true,
show_parameter_hints: false,
show_other_hints: true,
show_background: false,
})
});
});
Expand Down Expand Up @@ -1786,6 +1788,7 @@ async fn test_inlay_hint_refresh_is_forwarded(
show_type_hints: false,
show_parameter_hints: false,
show_other_hints: false,
show_background: false,
})
});
});
Expand All @@ -1800,6 +1803,7 @@ async fn test_inlay_hint_refresh_is_forwarded(
show_type_hints: true,
show_parameter_hints: true,
show_other_hints: true,
show_background: false,
})
});
});
Expand Down
21 changes: 15 additions & 6 deletions crates/editor/src/editor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -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()
Expand Down
1 change: 1 addition & 0 deletions crates/editor/src/hover_links.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1205,6 +1205,7 @@ mod tests {
show_type_hints: true,
show_parameter_hints: true,
show_other_hints: true,
show_background: false,
})
});

Expand Down
1 change: 1 addition & 0 deletions crates/editor/src/hover_popover.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1337,6 +1337,7 @@ mod tests {
show_type_hints: true,
show_parameter_hints: true,
show_other_hints: true,
show_background: false,
})
});

Expand Down
15 changes: 15 additions & 0 deletions crates/editor/src/inlay_hint_cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
})
});

Expand Down Expand Up @@ -1428,6 +1429,7 @@ pub mod tests {
show_type_hints: true,
show_parameter_hints: true,
show_other_hints: true,
show_background: false,
})
});

Expand Down Expand Up @@ -1547,6 +1549,7 @@ pub mod tests {
show_type_hints: true,
show_parameter_hints: true,
show_other_hints: true,
show_background: false,
})
});

Expand Down Expand Up @@ -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,
})
});

Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -2122,6 +2129,7 @@ pub mod tests {
show_type_hints: true,
show_parameter_hints: true,
show_other_hints: true,
show_background: false,
})
});

Expand Down Expand Up @@ -2256,6 +2264,7 @@ pub mod tests {
show_type_hints: true,
show_parameter_hints: true,
show_other_hints: true,
show_background: false,
})
});

Expand Down Expand Up @@ -2551,6 +2560,7 @@ pub mod tests {
show_type_hints: true,
show_parameter_hints: true,
show_other_hints: true,
show_background: false,
})
});

Expand Down Expand Up @@ -2902,6 +2912,7 @@ pub mod tests {
show_type_hints: false,
show_parameter_hints: false,
show_other_hints: false,
show_background: false,
})
});

Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -3131,6 +3143,7 @@ pub mod tests {
show_type_hints: true,
show_parameter_hints: true,
show_other_hints: true,
show_background: false,
})
});

Expand Down Expand Up @@ -3225,6 +3238,7 @@ pub mod tests {
show_type_hints: true,
show_parameter_hints: true,
show_other_hints: true,
show_background: false,
})
});

Expand Down Expand Up @@ -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();
Expand Down
8 changes: 8 additions & 0 deletions crates/language/src/language_settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -741,6 +741,14 @@ pub struct InlayHintSettings {
/// Default: true
#[serde(default = "default_true")]
pub show_other_hints: bool,
/// Whether to show a background for inlay hints.
///
/// If set to `true`, the background will use the `hint.background` color
/// from the current theme.
///
/// Default: false
#[serde(default)]
pub show_background: bool,
/// Whether or not to debounce inlay hints updates after buffer edits.
///
/// Set to 0 to disable debouncing.
Expand Down
1 change: 1 addition & 0 deletions docs/src/configuring-zed.md
Original file line number Diff line number Diff line change
Expand Up @@ -982,6 +982,7 @@ To interpret all `.c` files as C++, files called `MyLockFile` as TOML and files
"show_type_hints": true,
"show_parameter_hints": true,
"show_other_hints": true,
"show_background": false,
"edit_debounce_ms": 700,
"scroll_debounce_ms": 50
}
Expand Down
Loading