diff --git a/Cargo.lock b/Cargo.lock
index 1b54bdda02..51ca31bd9d 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -5714,6 +5714,17 @@ dependencies = [
"memchr",
]
+[[package]]
+name = "quick_action_bar"
+version = "0.1.0"
+dependencies = [
+ "editor",
+ "gpui",
+ "search",
+ "theme",
+ "workspace",
+]
+
[[package]]
name = "quote"
version = "1.0.32"
@@ -9922,6 +9933,7 @@ dependencies = [
"project",
"project_panel",
"project_symbols",
+ "quick_action_bar",
"rand 0.8.5",
"recent_projects",
"regex",
diff --git a/assets/icons/inlay_hint.svg b/assets/icons/inlay_hint.svg
new file mode 100644
index 0000000000..c8e6bb2d36
--- /dev/null
+++ b/assets/icons/inlay_hint.svg
@@ -0,0 +1,5 @@
+
diff --git a/crates/collab/src/tests/integration_tests.rs b/crates/collab/src/tests/integration_tests.rs
index 2224ecb838..a03e2ff16f 100644
--- a/crates/collab/src/tests/integration_tests.rs
+++ b/crates/collab/src/tests/integration_tests.rs
@@ -7867,7 +7867,7 @@ async fn test_mutual_editor_inlay_hint_cache_update(
.insert_tree(
"/a",
json!({
- "main.rs": "fn main() { a } // and some long comment to ensure inlays are not trimmed out",
+ "main.rs": "fn main() { a } // and some long comment to ensure inlay hints are not trimmed out",
"other.rs": "// Test file",
}),
)
@@ -8177,7 +8177,7 @@ async fn test_inlay_hint_refresh_is_forwarded(
.insert_tree(
"/a",
json!({
- "main.rs": "fn main() { a } // and some long comment to ensure inlays are not trimmed out",
+ "main.rs": "fn main() { a } // and some long comment to ensure inlay hints are not trimmed out",
"other.rs": "// Test file",
}),
)
diff --git a/crates/editor/src/editor.rs b/crates/editor/src/editor.rs
index 256ef2284c..904e77c9f0 100644
--- a/crates/editor/src/editor.rs
+++ b/crates/editor/src/editor.rs
@@ -302,10 +302,11 @@ actions!(
Hover,
Format,
ToggleSoftWrap,
+ ToggleInlayHints,
RevealInFinder,
CopyPath,
CopyRelativePath,
- CopyHighlightJson
+ CopyHighlightJson,
]
);
@@ -446,6 +447,7 @@ pub fn init(cx: &mut AppContext) {
cx.add_action(Editor::toggle_code_actions);
cx.add_action(Editor::open_excerpts);
cx.add_action(Editor::toggle_soft_wrap);
+ cx.add_action(Editor::toggle_inlay_hints);
cx.add_action(Editor::reveal_in_finder);
cx.add_action(Editor::copy_path);
cx.add_action(Editor::copy_relative_path);
@@ -1237,7 +1239,8 @@ enum GotoDefinitionKind {
}
#[derive(Debug, Clone)]
-enum InlayRefreshReason {
+enum InlayHintRefreshReason {
+ Toggle(bool),
SettingsChange(InlayHintSettings),
NewLinesShown,
BufferEdited(HashSet>),
@@ -1354,8 +1357,8 @@ impl Editor {
}));
}
project_subscriptions.push(cx.subscribe(project, |editor, _, event, cx| {
- if let project::Event::RefreshInlays = event {
- editor.refresh_inlays(InlayRefreshReason::RefreshRequested, cx);
+ if let project::Event::RefreshInlayHints = event {
+ editor.refresh_inlay_hints(InlayHintRefreshReason::RefreshRequested, cx);
};
}));
}
@@ -2669,13 +2672,41 @@ impl Editor {
}
}
- fn refresh_inlays(&mut self, reason: InlayRefreshReason, cx: &mut ViewContext) {
+ pub fn toggle_inlay_hints(&mut self, _: &ToggleInlayHints, cx: &mut ViewContext) {
+ self.refresh_inlay_hints(
+ InlayHintRefreshReason::Toggle(!self.inlay_hint_cache.enabled),
+ cx,
+ );
+ }
+
+ pub fn inlay_hints_enabled(&self) -> bool {
+ self.inlay_hint_cache.enabled
+ }
+
+ fn refresh_inlay_hints(&mut self, reason: InlayHintRefreshReason, cx: &mut ViewContext) {
if self.project.is_none() || self.mode != EditorMode::Full {
return;
}
let (invalidate_cache, required_languages) = match reason {
- InlayRefreshReason::SettingsChange(new_settings) => {
+ InlayHintRefreshReason::Toggle(enabled) => {
+ self.inlay_hint_cache.enabled = enabled;
+ if enabled {
+ (InvalidationStrategy::RefreshRequested, None)
+ } else {
+ self.inlay_hint_cache.clear();
+ self.splice_inlay_hints(
+ self.visible_inlay_hints(cx)
+ .iter()
+ .map(|inlay| inlay.id)
+ .collect(),
+ Vec::new(),
+ cx,
+ );
+ return;
+ }
+ }
+ InlayHintRefreshReason::SettingsChange(new_settings) => {
match self.inlay_hint_cache.update_settings(
&self.buffer,
new_settings,
@@ -2693,11 +2724,13 @@ impl Editor {
ControlFlow::Continue(()) => (InvalidationStrategy::RefreshRequested, None),
}
}
- InlayRefreshReason::NewLinesShown => (InvalidationStrategy::None, None),
- InlayRefreshReason::BufferEdited(buffer_languages) => {
+ InlayHintRefreshReason::NewLinesShown => (InvalidationStrategy::None, None),
+ InlayHintRefreshReason::BufferEdited(buffer_languages) => {
(InvalidationStrategy::BufferEdited, Some(buffer_languages))
}
- InlayRefreshReason::RefreshRequested => (InvalidationStrategy::RefreshRequested, None),
+ InlayHintRefreshReason::RefreshRequested => {
+ (InvalidationStrategy::RefreshRequested, None)
+ }
};
if let Some(InlaySplice {
@@ -2774,6 +2807,7 @@ impl Editor {
self.display_map.update(cx, |display_map, cx| {
display_map.splice_inlays(to_remove, to_insert, cx);
});
+ cx.notify();
}
fn trigger_on_type_formatting(
@@ -7696,8 +7730,8 @@ impl Editor {
.cloned()
.collect::>();
if !languages_affected.is_empty() {
- self.refresh_inlays(
- InlayRefreshReason::BufferEdited(languages_affected),
+ self.refresh_inlay_hints(
+ InlayHintRefreshReason::BufferEdited(languages_affected),
cx,
);
}
@@ -7735,8 +7769,8 @@ impl Editor {
fn settings_changed(&mut self, cx: &mut ViewContext) {
self.refresh_copilot_suggestions(true, cx);
- self.refresh_inlays(
- InlayRefreshReason::SettingsChange(inlay_hint_settings(
+ self.refresh_inlay_hints(
+ InlayHintRefreshReason::SettingsChange(inlay_hint_settings(
self.selections.newest_anchor().head(),
&self.buffer.read(cx).snapshot(cx),
cx,
diff --git a/crates/editor/src/inlay_hint_cache.rs b/crates/editor/src/inlay_hint_cache.rs
index 8be72aec46..70cccf21da 100644
--- a/crates/editor/src/inlay_hint_cache.rs
+++ b/crates/editor/src/inlay_hint_cache.rs
@@ -24,7 +24,7 @@ pub struct InlayHintCache {
hints: HashMap>>,
allowed_hint_kinds: HashSet